0 Comments

Introduction

Servos or servo motors are used in electronics applications where linear or angular displacement is a prime concern. These are widely used as precision rotation and linear actuators. In robotics application servos play a significant roll. Here we will try to control two servos simultaneously from zero to ninety degrees smoothly by using arduino uno.

We are going to use

Two micro servo motors

Arduino uno board

External 5V DC adaptor

A bread board

Some jumper wires

Pin outs of a micro servo motor

If you have a servo motor with three coloured wires having orange red and brown, then red indicates positive, brown negative and orange is used as controlling wire.

Care must be taken

We will need an external DC 5V adaptor to drive the motors because the arduino uno board can’t provide the required power to rotate two servo motors simultaneously.

Ground of external 5V supply must be connected to ground of Arduino Uno board.

It is necessary to download and install the Servo.h Library in arduino ide software.

The program for Atmega328 microcontroller

#include<Servo.h> //Include the servo library.

Servo s1; // Assign s1 as servo motor1.

Servo s2; // Assign s2 as servo motor2.

int i; // Declare the type of variable as we are going to use it in for loop.

void setup()  // Now what we write below here will be executed once.

{

Serial.begin(9600);  // This is the baud rate for serial communication. 

s1.attach(12);  // Attach orange colour wire of servo motor1 to digital pin12 of arduino uno board. You can choose the digital pins according to your wish

 s2.attach(13);  // Attach orange colour wire of servo motor2 to digital pin13 of arduino uno board. You can choose the digital pins according to your wish.

}

void loop() // Here the actual program starts.

for(i=0; i<=90; i+=1) // Here we are initializing the for loop with required conditions. It is for the movement from 0 to 90 degree.

 {   

 s1.write(i);       

 s2.write(i);

 delay(100); // Provide some meaningful delay times. I have taken 100. If you write 5000, you will notice that shaft is just shaking.

 }

delay(4000);  // This delay is necessary to notice the difference between the movement between 0 to 90 degree.

for(i=90; i>=0; i-=1)  // Here we are initializing the for loop with required conditions. It is for the movement from 90 to 0 degree.

 {

 s1.write(i); 

 s2.write(i);         

 delay(100);  //These 100 has a meaning, if you write 5000 ,you will notice shaking of shaft.

 }

delay(4000);  // This delay is necessary to notice the difference between the movement between 90 to 0 degree.

}

The arduino file

//SMOOTH CONTROLLING OF TWO SEVOMOTORS FROM 0 TO 90 DEGREES SIMULTANEOUSLY.
//Ground of external 5v supply must be connected to ground of Arduino Uno. 
//Download and install the Servo.h Library.
#include<Servo.h>
Servo s1;
Servo s2;
int i;
void setup()
{
  Serial.begin(9600);
  s1.attach(12);  //Attach orange colour wire of servo motor1 to digital pin12. 
  s2.attach(13);  //Attach orange colour wire of servo motor2 to digital pin13. 
}
void loop()
{  
 for(i=0; i<=90; i+=1)
 {    
 s1.write(i);        
 s2.write(i); 
 delay(100);//These 100 has a meaning,if you write 5000 ,you will notice nothing
 }
delay(4000);
  for(i=90; i>=0; i-=1)
  {
  s1.write(i);  
  s2.write(i);          
  delay(100);//These 100 has a meaning,if you write 5000 ,you will notice nothing
  }
  delay(4000);
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts