Starting Electronics Needs Your Help!
It is that time of the year when we need to pay for web hosting and buy new components and equipment for new tutorials. You can help by making a donation. Contribute to this website by clicking the Donate button. The total will be updated once daily. (You may need to clear your browser cache to see the updates.)
Target Amount: $2000
Amount Raised: $184
Created on: 10 September 2012
Arduino makes it so easy to connect and control a servo of the RC hobby type. Only three wires need to be connected between the Arduino board and the servo.
Servos make it possible to animate a project. Most servos will have a shaft that will rotate between 0 and 180 degrees. Servos usually come with various attachments that connect to the shaft allowing the rotational motion of the shaft to be changed to linear motion, i.e. the servo can then perform a pull and push action.
Two sketches from the examples that are built into the Arduino IDE are used in this tutorial. The first sketch "sweep" rotates the servo shaft from 0 degrees to 180 degrees and back continuously. The second sketch "knob" allows a potentiometer to be used to rotate the servo.
This video shows the two sketches in operation:
Can't see the video? View on YouTube →
An analog or digital servo can be used. Make sure that the servo is rated to operate from 5V. In this tutorial, a servo is used that is rated to operate from 4.8V to 5.5V
Connect the red wire from the servo to 5V on the Arduino and the brown wire from the servo to GND on the Arduino. The orange wire from the servo is to be connected to Arduino digital pin 9 for this tutorial.
When running the Knob sketch, a potentiometer is connected with the middle pin connected to Arduino analog pin A0. One of the outer pins of the potentiometer is connected to 5V and the other to GND.
After connecting the servo to the Arduino, load the built-in Sweep sketch to the Arduino board. The sketch can be found in the Arduino IDE under File → Examples → Servo → Sweep
With the servo and potentiometer connected to the Arduino, the Knob sketch can be loaded to the Arduino. This sketch can be found in the Arduino IDE under File → Examples → Servo → Knob