Page 91 - Programming the Photon Getting Started With the Internet of Things
P. 91

DC motors are excellent drive motors, but they are not really good for precision work
        because there is no feedback. Without using some sort of encoder device you will never
        know the exact position of a DC motor. Servo motors, or servos, are unique in that you

        can  command  them  to  rotate  to  a  particular  position  and  stay  there  until  you  tell  it
        otherwise. A good example use of a servo motor is an actuating door lock.

             When using servos, there are a couple of different types to consider, such as standard
        and continuous rotation. Standard servos operate from 0 to 180 degrees. Servo control is

        achieved by sending a pulse of a particular length. The length of the pulse determines the
        absolute position that the servo will rotate to. This is due to a small potentiometer in the
        servo that measures its position; when you remove the potentiometer, it becomes free to
        continuously rotate.

             Unlike a standard DC motor, servo motors have three pins: power (red), ground (black

        or brown), and signal (white or orange). The wires are color coded and typically in order;
        they look like the ones shown in Figure 4.11.






























        Figure 4.11 Servo motor.


             Servos have a dedicated control pin, unlike standard DC motors, that tells the servo
        which  position  to  turn  to.  The  power  and  ground  lines  of  a  servo  should  always  be
        connected to a power source. Servos are controlled using adjustable pulse widths on the
        signal line. For a standard servo sending a 1-ms 5-V pulse turns the motor to 0 degrees
        and sending a 2-ms 5-V pulse turns the motor to 180 degrees. Once a pulse has been sent

        to a servo, it then turns to that position and will remain there until instructed to move to
        another position by the sending of another pulse signal. If you want the servo to hold its
        position—that is, resist any movement, then you need to resend the same command every

        20 ms or so.

             In this experiment we are going to use a standard servo motor that operates from 0 to
        180 degrees and we will control it using a simple potentiometer. We will read the value of
        the potentiometer, and as we rotate it from one value to another the servo motor will rotate
   86   87   88   89   90   91   92   93   94   95   96