Understanding Servo Motors:
-
- Servo motors are components that can rotate their handles (usually between 0° and 180°). They are used to control the angular position of an object.
How Servo Motors Work:
-
- After connecting the VCC and GND pins to 5V and 0V, respectively, we can control the servo motor by generating a proper PWM signal on the signal pin.
- The angle of rotation is determined by the width of the PWM signal.
- The servo motor’s datasheet provides parameters such as the period of PWM, minimum and maximum widths of PWM, which are fixed in the Arduino Servo library.
Types of Servos
Positional Rotation Servo:
-
- This is the most common type of servo motor.
- It rotates 180 degrees (from 0° to 180°) and stops at specific positions.
- The feedback mechanism (usually a potentiometer) allows precise control over the shaft’s position.
- Commonly used in robotics, RC vehicles, and other applications where precise positioning is essential.
Continuous Rotation Servo:
-
- Unlike positional rotation servos, continuous rotation servos can rotate continuously in either direction.
- These servos lack a fixed stop point, making them suitable for applications like robot wheels or conveyor belts.
- Instead of controlling position, you control the speed and direction of the motor.
- Continuous rotation servos are often used for simple motion tasks.
Linear Servo:
-
- Linear servos convert rotary motion into linear motion.
- They have a linear actuator (such as a lead screw or belt) that moves back and forth.
- Linear servos find applications in sliding doors, linear actuators, and other scenarios requiring linear movement.
In this Tutorial we will use the SG90 servo motor. It is a popular choice for hobbyists and makers due to its compact size, lightweight design, and ease of use
Specifications:
-
- Torque: The SG90 has a torque of approximately 2.5 kg/cm (kilogram per centimeter). This torque rating indicates the force it can exert at a distance of 1 centimeter from the rotation axis.
- Rotation Range: The servo can rotate approximately 180 degrees (90 degrees in each direction).
- Pulse Width Modulation (PWM): The servo responds to PWM signals to control its position. A 1.5 ms pulse corresponds to the middle position (angle 0°), while a 2 ms pulse corresponds to the middle position (angle 90°). A 1 ms pulse moves it all the way to the left (angle -90°).
Pinout:
-
- The SG90 servo motor typically has three pins:
- VCC (Power): Connect this pin to a 5V power supply.
- GND (Ground): Connect this pin to the ground (0V).
- Signal (Control): Connect this pin to an Arduino or microcontroller pin to send PWM signals.
- The SG90 servo motor typically has three pins:
Components
Arduino Uno
SG90 Servo
Cables
Connection diagram
Servo library
The code!
// Include the Servo library #include <Servo.h> // Declare the Servo pin int servoPin = 3; // Create a servo object Servo Servo1; void setup() { // We need to attach the servo to the used pin number Servo1.attach(servoPin); } void loop(){ // Make servo go to 0 degrees Servo1.write(0); delay(1000); // Make servo go to 90 degrees Servo1.write(90); delay(1000); // Make servo go to 180 degrees Servo1.write(180); delay(1000); }