Tuesday, September 4, 2018

servo motor with arduino


     Servo Motor

A Servo Motor is a small device that has an output shaft. This shaft can be positioned to specific angular positions. As long as the coded signal exists on the input line, the servo will maintain the angular position of the shaft. If the coded signal changes, the angular position of the shaft changes. In practice, servos were used in radio-controlled airplanes to position control surfaces like the elevators and rudders. They are also used in radio-controlled cars, puppets, and of course, robots.

Hardware Required


  • 1 x  servo motor
  • 1 x Arduino uno
  • 3 x jumper wire


Wiring Diagram
The best thing about a servo motor is that it can be connected directly to an Arduino.
  • Servo red wire – 5V pin Arduino         
  • Servo brown wire – Ground pin Arduino         
  • Servo yellow wire – 9 pin Arduino


connection with ardunio-







code-



#include //Servo library Servo servo_test; //initialize a servo object for the connected servo int angle = 0; void setup() { servo_test.attach(9); // attach the signal pin of servo to pin9 of arduino } void loop() { for(angle = 0; angle < 180; angle += 1) // command to move from 0 degrees to 180 degrees { servo_test.write(angle); //command to rotate the servo to the specified angle delay(15); } delay(1000); for(angle = 180; angle>=1; angle-=5) // command to move from 180 degrees to 0 degrees { servo_test.write(angle); //command to rotate the servo to the specified angle delay(5); } delay(1000); }
Servo servo_test; //initialize a servo object for the connected servo int angle = 0; void setup() { servo_test.attach(9); // attach the signal pin of servo to pin9 of arduino} void loop() { for(angle = 0; angle < 180; angle += 1) // command to move from 0 degrees to 180 degrees { servo_test.write(angle); //command to rotate the servo to the specified angle delay(15); } delay(1000); for(angle = 180; angle>=1; angle-=5) // command to move from 180 degrees to 0 degrees { servo_test.write(angle); //command to rotate the servo to the specified angle delay(5); } delay(1000);}
Servo servo_test; //initialize a servo object for the connected servo int angle = 0; void setup() { servo_test.attach(9); // attach the signal pin of servo to pin9 of arduino} void loop() { for(angle = 0; angle < 180; angle += 1) // command to move from 0 degrees to 180 degrees { servo_test.write(angle); //command to rotate the servo to the specified angle delay(15); } delay(1000); for(angle = 180; angle>=1; angle-=5) // command to move from 180 degrees to 0 degrees { servo_test.write(angle); //command to rotate the servo to the specified angle delay(5); } delay(1000);}

Tech IOT Web Developer

No comments:

Post a Comment