2
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ I was just experimenting with a servo few hours ago and that particular servo would jerk if it got constant high. Also don't expect to see blinking LED if you put it on control line, because PWM frequency would be too high. Period should usually be 20 ms and high time should be between 1 ms and 2 ms. You could look for differences in light intensity levels on an LED. Depending on the quality of your eyesight, you could perhaps see some differences. \$\endgroup\$ – AndrejaKo May 22 '13 at 17:24
  • \$\begingroup\$ You wouldn't see a blinking LED, but you should notice the LED dim with lower pulse widths and be brighter with longer pulse widths. Since the difference between the min/max pulse widths is small compared to the total servo period, the difference in brightness might be difficult to notice, but it will be there. \$\endgroup\$ – Kurt E. Clothier May 23 '13 at 2:40
3
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ I'm going to disagree with the servo pulse widths in your image - 1ms to 2 ms is standard with .5 to 2.5 being the absolute min/max (but this can vary with different servos)... en.wikipedia.org/wiki/File:Sinais_controle_servomotor.JPG But the other advice is good. \$\endgroup\$ – Kurt E. Clothier May 23 '13 at 2:43
  • \$\begingroup\$ I took these timings for a futuba servo (a pretty standard device). The timings will differ with different devices and that is why I state in the very first sentence - have a look at the specs for your servo. \$\endgroup\$ – JIm Dearden May 23 '13 at 9:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.