Chapter 7. Controlling Servos with Arduino

In this chapter, you'll learn how to use the basic capability of Arduino to control servo motors.

Servo motors are important because you can use them to create all kinds of useful arms, legs, or even pan-and-tilt mechanisms to make really cool robots that can walk, or pick up things, or move sensors around. You'll then take this to the next level, learning how to add more functionality using a shield to control the speed and direction of a whole set of servos to build a walking hexapod robot.

The basics of a servo motor

Before you begin, you'll need some background on servo motors. Servo motors are somewhat similar to DC motors; however, there is an important difference. While DC motors are generally designed to move in a continuous way—rotating 360 degrees at a given speed—servos are generally designed to move within a limited set of angles. In other words, in the DC motor world, you generally want your motors to spin with continuous rotation speed that you control. In the servo motor world, you want your motor to move to a specific position that you control.

Controlling servos is fairly simple. The device has three wires connected to it: one for the ground connection, one for the drive voltage, and the third is a control signal that expects a pulse-width modulated (PWM) signal. The signal is a square wave that is turned on and off at a set rate, normally at around 500 Hz. The ratio of the length of the time the signal is on to the time the signal is off determines the desired angle of the servo.

Arduino can control servos using two different approaches. The first is to connect your servos directly to Arduino. You'll use this solution in the first example of this chapter. Unfortunately, if you have a lot of servo motors, they can sometimes draw more current than Arduino can provide, which is 40 mA. To solve this problem, you'll need to use a shield that can connect to an external power source. Then, your Arduino and shield can provide both voltage and current so that you can control many servos. The second example in this chapter will use this servo controller shield designed for Arduino to control 12 servos on a hexapod robot.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.73.127