Activity:Servo Control Motor

About this Activity:

In this activity we will learn how to move servo to various angles with the help of the Arduino IDE. How to add Servo.write at the right position for better execution of the code. We will be moving servo to different angles like 0,45,90,135,180 degree with the delay of one second. We will learn about the concept of  movement of different parts.

Components Required:

Circuit Diagram:

Code:

// Before Uploading this code download (Servo.h) library, if not preinstalled.
// 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 45 degrees
Servo1.write(45);
delay(1000);
// Make servo go to 90 degrees
Servo1.write(90);
delay(1000);
// Make servo go to 135 degrees
Servo1.write(135);
delay(1000);
// Make servo go to 180 degrees
Servo1.write(180);
delay(1000);
} // End of the code

Steps to do the activity: