Arduino: Basic Servo Control

This entry is part 1 of 13 in the series Arduino

With this code, you will be able to control simple servo motor using Arduino UNO. Connect the servo motor as shown below, with your Arduino UNO dev. board and then burn the following program into it.


Tested Code

The lab tested code is given below. You can also download the text file of this code. Copy the complete code and then paste it into your Arduino Software by creating new project.

  Program of basic controlling of Servo motor through 180 degree
  Created by: Vidyasagar Academy, Akola;
  Date: 04.06.2017, Version: 1.0
  Tested ok on Arduino UNO.

#include 'Servo.h' // replace (') single quote by (<>)
Servo Servo_motor; // Create a servo object 

void setup() 
   Servo_motor.attach(0); // attach the servo to pin-0 number 

void loop()
   Servo_motor.write(0); // reset the position of servo motor to initial position
   Servo_motor.write(90); // 
   Servo_motor.write(180); // 

Note: You can change Servo_motor.write(90); given in above code, with any value you like to get different rotation angle of the servo motor.

Series NavigationArduino: Fading LED >>