Skip to content

Week 10: Output Devices

Assignment:

  • Group: measure the power consumption of an output device.
  • Individual: add an output device to a microcontroller board you've designed, and program it to do something.

Group assignment

Our group work for this week is documented on the RIIDL Fab Lab group page: Week 10: Output Devices.

Measuring an output device's power: while bench-testing the DC drive motors for our machine (see Week 12), the regulated supply powering the L298N motor driver and two geared motors read 12.2 V and 0.2 A:

Bench supply reading 12.2 V and 0.2 A while powering the motor driver and DC motors

P = V × I = 12.2 V × 0.2 A ≈ 2.4 W at the moment of this reading. This showed me why motors need their own supply and a driver: the current is far more than a microcontroller pin can provide, and it rises further when the motors are loaded or stall.

Exploring the output devices in the lab

🖥️ LCD Displays (16x2 / Graphic LCD / LCD Keypad)

alt text LCD displays are output devices used to visually present information such as text, numbers, and system status. The 16x2 LCD can display 16 characters per line across two lines, making it suitable for basic user interfaces. Graphic LCDs allow more complex visuals like icons and patterns. The LCD keypad shield integrates buttons for user input along with display output. These modules communicate with microcontrollers using parallel or I2C interfaces. They are widely used in embedded systems for real-time feedback and monitoring.

🔁 Relay Modules (1-Channel / Multi-Channel)

alt text Relay modules are electrically operated switches used to control high-power devices using low-power signals. They allow microcontrollers to safely switch AC appliances like motors, lights, or pumps. Multi-channel relays can control multiple devices independently. These modules often include optocouplers for isolation and protection. When triggered, the relay physically connects or disconnects a circuit. They are essential in automation systems where electrical isolation and safety are required.

⚙️ DC Motors (Various Types)

alt text DC motors convert electrical energy into rotational mechanical motion. They are commonly used in robotics, fans, and mechanical systems. Different types shown include high-speed motors and geared motors for torque applications. The speed of a DC motor can be controlled using PWM signals. They are simple to operate but require motor drivers for proper control. These motors are widely used for movement and actuation tasks.

🔄 Servo Motors (SG90 / MG90S)

alt text Servo motors are precise rotational actuators used to control angular position. Unlike DC motors, they can move to a specific angle based on PWM signals. They are ideal for applications like robotic arms, hands, and controlled mechanisms. The SG90 is a lightweight plastic gear servo, while MG90S offers higher strength with metal gears. Servos have built-in control circuits for accurate positioning. They are essential where controlled motion is required.

🌀 Cooling Fans (DC Fans)

alt text Cooling fans are used to dissipate heat from electronic components and maintain safe operating temperatures. They work by rotating blades to create airflow across heat-generating devices. Small fans are used in compact circuits, while larger fans are used in high-power systems. They operate on DC voltage and can be controlled via PWM or simple switching. Proper cooling improves system reliability and lifespan. These are commonly used in power electronics and embedded systems.

🔢 LED Matrix Displays

alt text LED matrix displays consist of multiple LEDs arranged in rows and columns to display patterns or text. They are used for visual output such as animations, scrolling messages, and indicators. The matrix is controlled using driver ICs that manage multiplexing. These displays are efficient for compact visual communication. They are widely used in signage, clocks, and interactive projects. Their modular nature allows expansion for larger displays.

💡 LEDs (Various Types including High Power LED)

alt text LEDs (Light Emitting Diodes) are basic output devices used for indication and illumination. They emit light when current flows through them. Different colors represent different statuses in a system. High-power LEDs provide intense brightness for lighting applications. They are energy-efficient, long-lasting, and widely used in electronics. LEDs are often the first output device used in prototyping and debugging.

🔊 Buzzer Module

alt text Buzzers are audio output devices used to generate sound signals like beeps or alarms. They are commonly used for alerts, notifications, and feedback in embedded systems. Active buzzers produce sound directly when powered, while passive buzzers require signal input. They are easy to interface with microcontrollers. Buzzers consume low power and are compact. They are widely used in security systems and user interaction feedback.

🔢 7-Segment Display

alt text A 7-segment display is used to show numerical digits using seven individual LED segments. Each segment can be controlled to form numbers from 0 to 9. It is commonly used in digital clocks, counters, and measurement devices. These displays can be driven directly or using driver ICs. They are simple, cost-effective, and easy to read. Their straightforward design makes them ideal for numeric output applications.

⚙️ Stepper Motor

alt text alt text Stepper motors are precise motors that move in discrete steps rather than continuous rotation. This allows accurate control over position and speed. They are commonly used in CNC machines, 3D printers, and robotics. Each step corresponds to a fixed angle of rotation. They require a driver circuit to control the stepping sequence. Stepper motors are ideal for applications requiring precision and repeatability.

📀 Micro SD Card Module

alt text The micro SD card module is used for data storage and logging in embedded systems. It allows the system to save sensor data, logs, or configuration files. The module communicates with the microcontroller using SPI protocol. It supports removable storage, making data transfer easy. These modules are widely used in IoT and data acquisition systems. They are essential when persistent storage is required.

🎮 Push Button Module / Control Board

alt text Push button modules are simple interface devices used for user interaction. They allow manual input to control system functions. Each button acts as a switch that sends a signal when pressed. These modules are often debounced in software or hardware. They are used in menus, controls, and triggering events. Their simplicity makes them essential in interactive embedded systems.

alt text

Individual assignment: a servo driven from my own board

For the individual assignment I connected a servo motor to the XIAO RP2040 board I designed and milled (Week 6, Week 8) and programmed it to sweep back and forth.

My milled XIAO RP2040 board connected to an MG995 servo

I used an MG995, a larger servo than the MG90S in my gripper, for this bench test. The servo is powered from a separate metal-cased switching power supply (visible behind the breadboard in the photo), and only the signal comes from my board:

MG995 wire Connected to
Brown (GND) Power supply negative (−)
Red (VCC) Power supply positive (+5 V to +6 V)
Orange (signal) XIAO RP2040 D10
(common ground) Power supply negative (−) also wired to the XIAO's GND

The servo turns from 0° to 180° in 2° steps, pauses for a second, and returns to 0°. The close-up shows the horn turning.

How the code works

A hobby servo is controlled by a PWM signal: a pulse every 20 ms, where the pulse width (about 1–2 ms) sets the angle. The Arduino Servo library generates this pulse on D10, so myServo.write(angle) only needs the angle in degrees. Moving in 2° steps with a 30 ms delay makes the sweep smooth instead of jumping straight to the end position.

Code: mg995_sweep.ino

#include <Servo.h>

#define SERVO_PIN D10

Servo myServo;

void setup() {
  myServo.attach(SERVO_PIN);
  myServo.write(0);
  delay(1000);
}

void loop() {
  // Rotate from 0 to 180 degrees
  for (int angle = 0; angle <= 180; angle += 2) {
    myServo.write(angle);
    delay(30);
  }
  delay(1000);

  // Rotate back from 180 to 0 degrees
  for (int angle = 180; angle >= 0; angle -= 2) {
    myServo.write(angle);
    delay(30);
  }
  delay(1000);
}

Power considerations

A servo's motor draws much more current than a microcontroller pin can supply, especially when it starts moving or is held against a load. The MG995 can draw well over 1 A when it starts or stalls, far more than the XIAO's 5V pin (fed from USB) should supply, so I powered it from a separate metal-cased switching power supply at 5–6 V, within the servo's rated range. The XIAO's pin only provides the signal. The signal level is 3.3 V from the RP2040, which servos accept as a valid pulse. The supply's negative is also connected to the XIAO's GND, so the servo and the board share a common ground. Without it the servo would have no reference for the 3.3 V signal on D10.

Second test: servo and LED reacting to distance

The second test joins the input from Week 9 to two outputs. The board reads the HC-SR04, turns the servo according to how close my hand is, and lights the XIAO's red LED when the hand is closer than 15 cm. This is the same idea as my final project, where an object brought close makes the gripper close.

My board with the HC-SR04 on the breadboard, the servo on the right and the power supply behind

Part Pin Connected to
HC-SR04 VCC / GND 5V / GND
HC-SR04 TRIG XIAO D0 (GPIO26)
HC-SR04 ECHO XIAO D2 (GPIO28), through the 1 kΩ / 2 kΩ divider
Servo (MG995) Signal XIAO D4 (GPIO6)
Servo (MG995) Power the same metal-cased 5–6 V supply as above
Red user LED (on the XIAO) GPIO17, active-low

As my hand moves toward the sensor, the servo horn turns toward 0°, and it turns back as the hand moves away.

Serial output: distance, servo angle and LED state on every line

How the distance becomes an angle

The code clamps the distance between 5 cm and 40 cm and maps it linearly onto 0–90°:

angle = 90 × (distance − 5) / (40 − 5)

I checked this against the serial output above:

Distance Calculation Printed
11.7 cm 90 × 6.7 / 35 = 17.2 servo 17 deg
9.5 cm 90 × 4.5 / 35 = 11.6 servo 12 deg
7.6 cm 90 × 2.6 / 35 = 6.7 servo 7 deg

Every reading in the screenshot is below 15 cm, so every line shows LED ON. If there is no echo, the servo and LED keep their last state, so the servo doesn't jump when the sensor briefly loses the hand.

Unlike the sweep above, this code is MicroPython. It drives the servo with the RP2040's hardware PWM directly instead of a library. The PWM runs at 50 Hz (a 20 ms frame), and the pulse width goes from 500 µs at 0° to 2500 µs at 180°.

Code: distance_servo_led.py. The comments mention the MG90S because this code was written for my gripper's servo. For this bench test I used the MG995: both take the same 50 Hz signal, so the code is unchanged.

# Distance -> servo + LED on XIAO RP2040, ~15 readings/s.
# HC-SR04: TRIG -> D0 (GPIO26), ECHO -> divider -> D2 (GPIO28). MG90S signal -> D4 (GPIO6).
# >= 40 cm: servo 90 deg; <= 5 cm: servo 0 deg; linear in between. <= 15 cm: on-board LED red ON.
# No echo: everything holds its last state.
import machine, time

trig = machine.Pin(26, machine.Pin.OUT, value=0)    # D0
echo = machine.Pin(28, machine.Pin.IN)              # D2
led = machine.Pin(17, machine.Pin.OUT, value=1)     # on-board red, active-low (0 = on)

servo = machine.PWM(machine.Pin(6))                 # D4
servo.freq(50)
MIN_US, MAX_US = 500, 2500                          # MG90S 0..180 deg; tweak if 0/90 look off

NEAR_CM, FAR_CM = 5, 40                             # servo 0 deg at NEAR, 90 deg at FAR
LED_CM = 15


def servo_deg(deg):
    servo.duty_ns(int((MIN_US + (MAX_US - MIN_US) * deg / 180) * 1000))


def distance_cm():
    trig.value(1)
    time.sleep_us(10)
    trig.value(0)
    t = machine.time_pulse_us(echo, 1, 30000)       # 30 ms timeout (~5 m)
    return None if t < 0 else t * 0.0343 / 2


servo_deg(90)
while True:
    cm = distance_cm()
    if cm is None:
        print("no echo")
    else:
        c = min(max(cm, NEAR_CM), FAR_CM)
        deg = round(90 * (c - NEAR_CM) / (FAR_CM - NEAR_CM))
        servo_deg(deg)
        led.value(0 if cm <= LED_CM else 1)
        print("%.1f cm | servo %d deg | LED %s" % (cm, deg, "ON" if cm <= LED_CM else "off"))
    time.sleep_ms(66)                               # ~15 Hz

AI assistance: I used Claude (Anthropic's AI assistant) to help write this MicroPython code. I chose the pins, wired the board, ran it, and checked the printed angles against the formula above.

Capacitive touch sound system

alt text

alt text alt text alt text alt text

This project demonstrates a simple capacitive touch-based sound system using conductive copper points, a buzzer, and an Arduino Uno. Copper pads are placed at different locations on the fabric surface, acting as touch sensors. Each colored circle represents an individual touch point connected through wires to the breadboard and microcontroller pins.

When a user touches any copper point, the human body introduces a small capacitance change, which is detected by the microcontroller. Based on the touched input, the system triggers a corresponding predefined tone or melody through the buzzer. Each touch point is mapped to a unique sound, creating an interactive audio experience. The breadboard is used for quick prototyping and connections, while jumper wires link the copper pads, buzzer, and controller. This setup demonstrates the integration of interactive textiles, basic electronics, and sound generation in a simple and intuitive way.