Skip to content

9. Output Devices

Types of output devices

  1. LEDs: Light Emitting Diodes, used for visual indication.

  2. LCDs: Liquid Crystal Displays, for displaying alphanumeric characters and graphics.

  3. Buzzer: An audible signaling device for generating tones or beeps.

  4. Motors: Convert electrical energy into mechanical motion, used for various applications like robotics.

  5. Relays: Electromechanical switches controlled by the microcontroller, used for switching high-power devices.

  6. Speakers: For audio output, used in applications like alarms or sound playback.

  7. Servo Motors: Precise motors used for positioning in robotics and automation.

  8. Stepper Motors: Motors that move in discrete steps, suitable for precision control in various applications.

Which Output Device to select

A servo motor typically has three pins: power (VCC), ground (GND), and control (usually labeled as signal). It is used for precise angular control, commonly in robotics, remote-controlled vehicles, and automated systems, providing accurate positioning within a defined range. For this week I am going to try out servo motor as my output device on the PCB that I have made in my pervious weeks.

Testing RP2040 on breadboard

First we connected the Seed Xiao rp2040 to the breadboard to test out the the board with our code for the servo.This ensures its functionality and allows for any necessary adjustments or troubleshooting before final implementation. Testing on a breadboard provides a controlled environment to verify compatibility, responsiveness, and accuracy, minimizing risks in the final product.

Code

#include <Servo.h>

// Define servo motor pin
#define SERVO_PIN 2

// Create a servo object
Servo myServo;

void setup() {
  // Attach the servo to pin D2
  myServo.attach(SERVO_PIN);
}

void loop() {
  // Move the servo to its minimum angle (0 degrees)
  myServo.write(0);
  delay(1000); // Wait for 1 second

  // Move the servo to its maximum angle (180 degrees)
  myServo.write(180);
  delay(1000); // Wait for 1 second
}

PCB with Servo- Its running!!

Here is the same code but running on the PCB built and designed by me in my previous weeks!

PCB with LED

I also have a LED attached to my PCB which turns on when the button on the PCB is pressed, Now I know its really basic but I guess it still counts as a output device for the week. Here it is!

Code for LED

// Pin definitions
#define LED_PIN 7
#define SWITCH_PIN 6

// Variables to store switch state and previous state
int switchState = 0;
int prevSwitchState = 0;

// Variable to store LED state
bool ledState = false;

void setup() {
  // Initialize LED pin as output
  pinMode(LED_PIN, OUTPUT);

  // Initialize switch pin as input
  pinMode(SWITCH_PIN, INPUT);
}

void loop() {
  // Read the state of the switch
  switchState = digitalRead(SWITCH_PIN);

  // Check if the switch state has changed
  if (switchState != prevSwitchState) {
    // If switch is pressed (HIGH), toggle LED state
    if (switchState == HIGH) {
      ledState = !ledState;
      digitalWrite(LED_PIN, ledState);
    }

    // Update previous switch state
    prevSwitchState = switchState;
  }
}

Code File

Servo Code

LED Code