Introduction

For this week’s assignment, I used a micro servo motor as an output device, connected to the Seeed Studio XIAO RP2040 microcontroller. Servo motors are commonly used for controlling position, making them ideal for robotics, mechanisms, and interactive movement.

Components Used

  • Seeed Studio XIAO RP2040
  • SG90 Micro Servo Motor
  • External 5V power supply (recommended for stable performance)
  • Breadboard and jumper wires

About Servo Motors

Servo motors rotate to specific angles based on the width of PWM signals. They have three main connections:

  • GND: Connects to ground
  • VCC: Power supply (typically 5V)
  • Signal: PWM signal from microcontroller

Wiring

I connected the SG90 servo motor to the XIAO RP2040 as follows:

  • Servo GND → GND (XIAO)
  • Servo VCC → 5V (external power recommended)
  • Servo Signal → D2 (physical pin 4 on XIAO RP2040)

Note: I used a common GND between the XIAO and the servo power supply to ensure stable signal operation.

Programming the Servo

I used the Arduino IDE to program the XIAO RP2040. The standard Servo.h library works with the RP2040 core.

Arduino Code

/* Sweep
												by BARRAGAN 
												This example code is in the public domain.
											   
												modified 8 Nov 2013
												by Scott Fitzgerald
												https://www.arduino.cc/en/Tutorial/LibraryExamples/Sweep
											   */
											   
											   #include 
											   
											   Servo myservo;  // create Servo object to control a servo
											   // twelve Servo objects can be created on most boards
											   
											   int pos = 0;    // variable to store the servo position
											   
											   void setup() {
												 myservo.attach(D2);  // attaches the servo on pin 9 to the Servo object
											   }
											   
											   void loop() {
												 for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
												   // in steps of 1 degree
												   myservo.write(pos);              // tell servo to go to position in variable 'pos'
												   delay(15);                       // waits 15 ms for the servo to reach the position
												 }
												 for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
												   myservo.write(pos);              // tell servo to go to position in variable 'pos'
												   delay(15);                       // waits 15 ms for the servo to reach the position
												 }
											   }
											   
											

Results

  • The servo motor successfully rotated from 0° to 180° and back.
  • The signal was stable, and the servo responded smoothly to the PWM output.
  • Using an external power source prevented voltage drops and jittering.

Conclusion

This week helped me understand how PWM works and how to control mechanical movement using output devices. The XIAO RP2040 performed well in generating consistent PWM signals for servo control. This knowledge can be applied in interactive prototypes, robotics, and simple actuated systems.