Page 195 - Making things move_ DIY mechanisms for inventors, hobbyists, and artists
P. 195

Chapter 6    Options for Creating and Controlling Motion          173




                     void loop()
                     {
                     // read the analog input from the photocell (value between 0 and
                     // 1023)
                     analogValue = analogRead(analogPin);

                     // map the analog value from the photocell (0 - 1023) to the angle
                     // of the servo (0 - 179)
                     analogValue = map(analogValue, 0, 1023, 0, 179);
                     // write the new mapped analog value to set the position of the
                     // servo
                     // servoMotor.write(analogValue);
                     delay(15);   // waits for the servo to get there before getting
                                  // another photocell reading
                     }
                 7. Try to make the servo motor move by using your finger to block the photocell,
                     and then moving it away and letting light hit it. It should move back and forth,
                     but depending on the light in the room, you probably won’t get the full range
                     of the servo by doing this.

               Continuous Rotation Servo Control
               If you have a continuous rotation servo (that you bought or modified from a standard
               servo), you no longer have control over position. Instead, the signal you give the servo
               controls the speed.

               The maximum speed you can expect with no load is already stated for you in the data
               sheet. For example, for the Hitec HS-311 servo motor, that speed is 60° in 0.15 seconds.
               Since there are 360° in one revolution, that means a modified HS-311 servo could
               finish one full revolution in 0.15 × 6 = 0.9 seconds. Because there are 60 seconds in
               a minute, dividing 60 seconds by 0.9 seconds gives a speed of 67 rpm.

               Stepper Motor Control

               There are two main types of stepper motors: unipolar and bipolar. They have between
               four and eight wires coming from the housing, and there are no standards as to what
               the wire colors mean. You use all these wires to give power to different parts of the
               motor in a specific sequence. The specifics of the sequence determine the stepping
               behavior (forward, backward, one-half step at a time, and so on). Both unipolar and
               bipolar steppers can be controlled by the same stepping sequence, but are wired
               differently.
   190   191   192   193   194   195   196   197   198   199   200