Arduino: Basic Servo Control

This entry is part 1 of 9 in the series All About 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.

arduino

Tested Code

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

#include  // include the Servo library 
 
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); // resets position of servo motor to initial position
   delay(1000);    
   Servo_motor.write(90); // turns servo in 90 degrees from its rest position
   delay(1000);  
   Servo_motor.write(180); // turns servo in 180 degrees from its rest position 
   delay(1000);  
   }

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 >>