Week 10: Output Devices

Group Assignment

We measured and analyzed the behavior of various output devices (LEDs, buzzers, motors) using an oscilloscope. 🔗 Group assignment link

Overview

Output devices respond to control signals by producing physical actions like movement or light. For this week, I used an SG90 servo motor controlled by the board I made in Week 8.

What is a Servo Motor?

The SG90 micro servo motor rotates from 0° to 180° and uses PWM signals for control. It’s commonly used in robotics for precise angle positioning.

SG90

PWM (Pulse Width Modulation)

PWM sends rapid ON/OFF pulses to simulate analog control. The servo uses this to interpret position:

PWM

Wiring

Servo Wire ColorFunctionConnected To
BrownGNDGND
RedVCC3.3V
OrangeSignalGPIO 6

Power Consumption

I used a multimeter to measure the current draw of the SG90:

This is important for choosing appropriate power supplies in final projects.

Code and Programming

I used the ESP32Servo library since I'm working with an ESP32-C3 board. The servo is swept back and forth smoothly with 15ms intervals:

#include <ESP32Servo.h>

Servo myservo;
int pos = 0;

void setup() {
  myservo.setPeriodHertz(50);
  myservo.attach(6, 500, 2500);
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) {
    myservo.write(pos);
    delay(15);
  }
  for (pos = 180; pos >= 0; pos -= 1) {
    myservo.write(pos);
    delay(15);
  }
}
      

Problems and Troubleshooting

While setting up the servo with my ESP32-C3 board, I ran into several issues:

After resolving these issues, the servo worked properly with my custom PCB and GPIO 6 using the ESP32Servo library.

Hero Shot

I used the custom PCB I designed and produced in Electronics Production week to control the servo using an Arduino-compatible microcontroller.

Download Files

Download this weeks files below:

📦 Download files .) (ZIP)