Experiment 9 - Servo Motor
Experiment 9 - Servo Motor
Aim/Objective: The main objective of this experiment is to interface Servo motor (SG-90)
Arduino Genuino UNO and control it’s position.
Components required:
Software Hardware
Arduino UNO Board
Tinkercad Arduino UNO Cable
Arduino IDE (To be installed in Laptop) Servo Motor
Potentiometer
Jumper wires
Pre-Requisites:
Program:
#include <Servo.h>
Servo myservo;
void setup()
{
myservo.attach(9);
Serial.begin(9600);
}
void loop()
{
int pos;
Circuit/Schematic Diagram:
Results:
A servo motor is a type of motor that is designed for precise control of angular position.
It consists of a small DC motor, a set of gears, and a control circuit that provides
feedback to accurately position the motor shaft.
A servo motor works by receiving control signals in the form of pulses. The duration
of the pulse determines the desired position of the motor shaft. The control circuit inside
the servo motor compares the received pulse duration with the current position of the
motor shaft and adjusts the motor's rotation to reach the desired position.
3. How is the SG-90 servo motor connected to the Arduino Genuino UNO?
The SG-90 servo motor is connected to the Arduino Genuino UNO using three wires.
The red wire is connected to the 5V pin of the Arduino for power, the brown or black
wire is connected to the GND pin for ground, and the orange or yellow wire is
connected to a digital pin (e.g., pin 9) for control.
4. How can we control the position of the servo motor using the Arduino Genuino
UNO?
We can control the position of the servo motor using the Arduino Genuino UNO by
sending PWM (Pulse Width Modulation) signals to the control wire of the servo motor.
By varying the duration of the pulse, we can set the desired angle of the servo motor
shaft.
The SG-90 servo motor has a range of motion of approximately 180 degrees. This
means it can rotate from 0 degrees to 180 degrees, allowing for a wide range of
positioning options.
Post-Lab:
1. Control the Position of servomotor for every 5 Degrees and serial monitoring
#include <Servo.h>
Servo myservo;
void setup()
{
myservo.attach(9);
Serial.begin(9600);
}
void loop()
{
int pos;
#include <Servo.h>
Servo myservo;
void setup()
{
myservo.attach(9);
Serial.begin(9600);
}
void loop()
{
value = analogRead(potpin);
value = map(value, 0, 1023, 0, 180);
myservo.write(value);
Serial.print("The Position of the Servo motor is ");
Serial.print(value);
Serial.println(" Degrees");
delay(1000);
}