User:Mmuhlbock/enes100/Arduinomotorcontrol/servomotorcontrol

Servo Motors
Servo Motors can be positioned from 0-180 degrees Internal feedback circuitry & gearing takes care of the hard stuff. Easy three-wire PWM 5V interface. Servos are used for Roboticists, movie effects people, and puppeteers use them extensively any time you need controlled, repeatable motion. Can turn rotation into linear movement with clever mechanical levers. Come in all sizes from super-tiny to drive-your-car. But all have the same 3-wire interface.

Pulse width Modulation
More commonly known as PMW. This is used because computer cant use output analog signals so PWM is used to fake it. Using digital voltages and in th Arduinos case the two digital signals are 0 volts and 5 volts.
 * The way this works is you average the output voltage over a given amount of time on vs. off. Here is the equation for figuring out the final output voltage
 * output_voltage = (on_time / (on_time + off_time) ) * max_voltage
 * ex. if you put power out 75% of the time and have it off 25% of the time you will come up with an output of 3.75 volt
 * On 50% Off 50% output 2.5 volts
 * On 20% Off 80% output 1.0 volts

How to Control a Servo With PWM
PWM freq is 50 Hz (i.e. every 20 millisecs)
 * Pulse width ranges from 1 to 2 millisecs
 * 1 millisec = full anti-clockwise position
 * 2 millisec = full clockwise position

To position, send a pulse train from 1 to 2 ms
 * To hold a position, pulses must repeat
 * Takes time to rotate, so pulse too fast & it won’t move

Adjusting the Code To Do What you Want
The code that I posted has the motor go the its full range of 180 degree motion this is done in the first line of the code where I define the number of micro seconds as 2500 this sets the motor to go to 180 degree as seen in this
 * Then I change the value to 1500 in the second line of the code to read int Pulse=1500 this sets the motor to the 90 degree position
 * Video

Hardware
For this I used the most simple set up connecting using the servo motor and the arduino motor.
 * Black wire goes to GRD
 * Orange to digital pin 4
 * Red to the 5V

Pictured below