Electronic – Raspberry Pi: driving Servo with PWM

pwmraspberry piservo

I'm experimenting with a small servo motor with the raspberry pi using PWM (pulse-width modulation). My understanding is that the servo should respond to different length of pulse. I should be seeing some motion if I output a constant square wave, right?

And if I output a constant HIGH signal the servo shouldn't do anything.

Is there a way to test for sure that the servo is working properly? I don't have an oscilloscope so I can't really confirm that my code is outputting the way it should – thinking about putting an LED and I should see a blinking light.

Best Answer

Have a look at the specs for your servo. It will expect to see a pulse every 20mS or so. The duration of the pulse will determine the angle. N.B. This 20mS timing may vary depending on the servo type used. The length of the pulse within this time will determine the position (min about 1ms, max about 2mS) enter image description here

The three connection wires are Power (+5V), Control Signal and Ground. Check the maker for specific colour code. Test the servo is working by setting up a 1.25mS pulse (0 - 5 - 0) every 20 mS. The arm should swing to the 0 degree position. Then change the pulse length to 1.75 mS and the arm should swing to 180 degrees. Putting a constant high signal on the input is not recommended.

As regards testing the output you could try a high impedance speaker (>64R) connected in series with a small capacitor (say 0.1 uF). connect one side to ground and the other to a probe (piece of wire). You should hear a low frequency hum if the output line is switching on and off.

enter image description here