How to set the initial position for a micro servo so that you can accurately place your servo in your project. Once you have your shaft position set, you can more easily set your final shaft travel.
You can set the position to whatever angle you wish. The code that we provide is set to 90 degrees. The code shows you where to make the change. (Download the code through the link below.)
How To Set The Servo Angle
Note that the video under the image to the left shows the servo in action.
Upload the sketch below to an Arduino Uno..
Attach the servo ground and power leads to Grnd and +5v on the Uno.
Note About Powering The Servo – The Uno can power a single servo such as the Tower Pro Micro Servo 9g without damage. But to be super careful, you may choose to power the servo by a separate 5 volt power supply. Set the separate power supply connections up on a breadboard.
Be sure to have an arm on the servo shaft so that you can see the movement when you connect the control wire to the Uno.
Insert the control wire into pin 9.
The shaft will rotate to the 90 degree position. Reset the arm on the shaft to the 90 degree position.
For your safety and convenience, the sketch is stored on Pastebin at this link. (So that you do not lose this page, this page will open in a new tab.) There you can safely review it, and if satisfied, download it.
Other Useful Servo Sketches
To use servos in slow moving switch machines, go to DIY Switch Machines
To use servos in level crossings go to Grade Crossing Circuit