Back to Weekly Assignments

Week 10: Output Devices

Assignments

Group assignment: Measure the power consumption of an output device. Document your work on the group work page and reflect on your individual page what you learned.

Individual assignment: Add an output device to a microcontroller board you’ve designed and program it to do something.

Group Work Assignment Reflection

In the group assignment, we measured the power consumption of the SG90 servo motor under different operating conditions to understand its energy demand.

Power consumption measurement: A digital multimeter was placed in series with the servo’s power supply (5 V). The servo was programmed to sweep continuously. The multimeter showed a current draw of 0.31 A when the servo was moving and 0.02 A when idle. Using the formula P = V × I, the power consumption during motion was:

P = 5 V × 0.31 A = 1.55 W

What I learned: The power consumption of a servo depends heavily on the load and speed. Even a small servo can draw several hundred milliamps when moving, which is too much for the microcontroller’s 3.3 V regulator. Therefore, an external power supply must be used for the servo. I also learned to use a multimeter to measure current and to distinguish between idle and active power states.

Individual Assignments

Board design and fabrication (Week 8) — This assignment builds on the custom PCB I designed in Week 8. My board is built around the Seeed Studio XIAO ESP32-C3. You can find the original design files, schematic, and fabrication steps on my Week 8 assignment page.

XIAO ESP32-C3 board

SG90 servo wiring

Wiring (follow the standard servo color coding):

Servo Motor Colour Connection
Signal Orange GPIO 3 (XIAO pin D3)
VCC Red 5 V external power (positive)
GND Brown Common ground (servo GND + XIAO GND)

Note: The servo’s red wire must never be connected to the XIAO’s 3.3 V or 5 V pin. The XIAO cannot supply the required current, and this could damage the board. Always use an external 5 V supply and tie the grounds together.

Library used: ESP32Servo — this library is specifically written for ESP32-based boards and handles the low-level PWM timing correctly. Install it via the Arduino Library Manager.

Code explanation

The program makes the servo sweep smoothly from 0° to 180° and back.

ArduinoC++
#include <ESP32Servo.h>

Servo myServo;

void setup() {
  myServo.attach(5);
}

void loop() {
  myServo.write(0);
  delay(500);
  myServo.write(90);
  delay(500);
  myServo.write(180);
  delay(500);
}

How it works:

  • #include <ESP32Servo.h> brings in the necessary PWM timing functions.
  • In setup(), the servo is attached to GPIO5.
  • In loop(), the sketch writes 0°, 90°, and 180° with delays between positions.

Problems Encountered & Solutions

Problem 1: The servo motor did not move.

Solution: After checking the wiring and the code, I found the warning: library Servo claims to run on AVR. I changed the library to ESP32Servo.h and uploaded again. The servo motor moved.

Servo test setup

Serial monitor output

Servo movement

Source file (Arduino sketch): ESP32_motor.ino — XIAO ESP32-C3 + servo motor (same code as on this page).

Video

Servo sweep demo