Project 7
SG-90 Servo Motor Control - Arduino Uno
Precise servo motor control for robotics
Project Description
A servo motor is a precision actuator that rotates to a specific angle based on control signals. It contains a motor, gear system, and a feedback potentiometer that constantly monitors its position. With its built-in control circuitry, the servo can move to and hold any angle between 0° and 180°, making it ideal for robotics, automation, and control systems where accurate positioning is required.
Signals of varying durations are sent from the Arduino to the motor, telling it to move in precise steps. Learn more about servo motors here
Components
- Arduino Uno
- SG-90 Servo motor
- Jumper wires
Code
#include <Servo.h>
Servo myservo;
void setup() {
myservo.attach(9); // attach servo signal to pin 9
}
void loop() {
// Sweep from 0 to 180 degrees
for (int pos = 0; pos <= 180; pos += 5) {
myservo.write(pos);
delay(100); // adjust speed
}
// Sweep back from 180 to 0 degrees
for (int pos = 180; pos >= 0; pos -= 5) {
myservo.write(pos);
delay(100); // adjust speed
}
}
Taking things further
- The servo motor can be used for a steering system on a robot car
- A robotic arm can be constructed by combining several servo motors
- A window/door opener or closer can be created for a model house
- The motor can be controlled directly using a potentiometer (variable resistor) where the angle corresponds to the angle of the potentiometer
Arduino & Microcontrollers