Saturday 6 April 2024

Arduino and Servo motor Interfacing

Interfacing Servo motor with Arduino



Warning: It is suggested not to give power from Arduino board to servo motor if the servo motor pulls load. It can damage the Arduino board. Instead, external power supply must be given .

Code in Action: 



Code: 

#include <Servo.h> 

Servo myservo; // create servo object to control a servo 

void setup() { 
   myservo.attach(9); // pin 9 of Arduino with servo motor
}

void loop() { 
   myservo.write(0); // tell servo to go to a particular angle 
   delay(1000); 
   myservo.write(90); // move to 90 degree
   delay(500); 
   myservo.write(135); // angle 135 degree
   delay(500); 
   myservo.write(180); // angle 180 degree
   delay(1500); 

}

No comments:

Post a Comment