Blog > Projects > Control servo to rotate 180 degrees
Control servo to rotate 180 degrees


2017-01-07 12:25:27




Control servo to rotate 180 degrees


In this section, we will use the new method to control the servo.  We found that the use of Arduino provided by the library, some of the servo can not accurately rotate the angle we need. Through our study different steering gears were found. The reason is that different types of steering gear operating frequency is different. So we provide the following methods: The corresponding frequency can be adjusted according to different servos


- 1 * Adeept UNO R3 Board

- 1 * USB Cable

- 1 * Adeept Servo

- Several jumper wires


The servo motor has three wires: power, ground and signal. The power wire is typically red and should be connected to the 5V pin on the Arduino board. The ground wire is typically black or brown and should be connected to a ground pin on the Arduino board. Usually the signal pin is yellow orange or white and should be connected to a digital pin on the Arduino board. Note that the servo motor draws a considerable amount of power, if you need to drive more than one or two servos, you'll probably need to power them with an extra supply (i.e. not the +5V pin on your Arduino). Be sure to connect the grounds of the Arduino and external power supply together.


Step1: Build the circuit

Step2: Program   Adeept_servo_PRO.ino

File name: Adeept_servo_PRO.ino
Description:   The servo motor are rotated  from 
               0 degrees to 180 degrees and from 180 degrees to
               0 degrees.
Author: Tom
Date: 2017/01/07 
int servopin = 9;    //Define servo interface digital interface 7
int angle =0;        //Angle of rotation of the servo

void servopulse(int angle)//Define an impulse function
  int pulsewidth=(angle*11)+500;  //The angle is converted to a pulse width value of 500-2480
  digitalWrite(servopin,HIGH);    //The servo interface level to the highest
  delayMicroseconds(pulsewidth);  //The number of microseconds of the delay pulse width value
  digitalWrite(servopin,LOW);     //The servo interface level to low
  delayMicroseconds(20000-pulsewidth); //20000 can be replaced: "frequency = 1 / (20000/1000000)"

void setup()
  pinMode(servopin,OUTPUT);//Set the servo interface as the output interface

void loop()
  for(angle=0;angle<=180;angle++){ //Reference impulse function servopulse(angle); delay(20); } for(angle=180;angle>=0;angle--){
      //Reference impulse function

Step3: Compile the program and upload to Adeept UNO R3 board

Now, you should see the servo rotate from 0 to 180 degrees and then do it in the opposite direction.

Adeept Code Download Link : Adeept_servo_PRO


Last article : How to install and use Geany IDE in the Raspberry Pi or Ubuntu?
Next article : Adeept Motor Shield Introduction



  Related Products
  Related Blogs
Copyright © 2016 All Rights Reserved.