Arduino + servo simple setup

by

in

Using servo with arduino is pretty easy.

Here is my setup:
Arduino with servo


Servo has 3wires, vcc, gnd and control.
My servo colors were
+5V – red,
gnd – brown
control – orange.

Code for arduino (my control wire goes to pin12):

#include 
Servo myServo;

int servoPin = 12;

void setup() {
	myServo.attach(servoPin);
}

void loop() {
	myServo.write(0);
	delay(1000);
	myServo.write(180);
	delay(1000);
}

#include – we load servo library
Servo myServo; – create an servo object
With int servoPin we just make simple variable to be more readable in code (currently doesn’t make sense as there is only one pin in use, but it’s a good habit to have).
myServo.attach(servoPin); – point to servo object to use “servoPin” pin.
myServo.write() function takes degrees as parameters.
My current servo takes from 0 to 180.

And video:


Comments

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.