There is a huge buzz about how to control servo from arduino in the net. Just to let people know what is a simplest solution. But first few details about servo and arduino. Servo comes with 3 cables with 3 different colors:
-
brown - needs to be connected to ground
-
red - needs to be connected to power supply +5V
-
orange - needs to be connected to control pin - thru this you will send commands to servo from arduino library.
So let's say that you connected everything as described above, and orange (data) cable is connected to a pin 5. Below is a simple code that rotates a servo waits 2s and rotates it to a different position.
#include
Servo servoh;
int runOnce = 1;
void setup() {
servoh.attach(5);
}
void loop() {
if(runOnce == 1){
servoh.write(10);
runOnce = 0;
}else{
servoh.write(90);
runOnce = 1;
}
delay(2000);
}
No comments:
Post a Comment