Wednesday, July 6, 2016

Arduino and Servo Motors

With electronics, there is only one mantra to live by... baby steps. My ultimate goal is to control 2 standard servo motors with an accelerometer (details on the actual project later). I started out by wiring up 1 servo motor to a potentiometer and then writing a very short program like that described in Project 25 of Beginning Arduino by Michael McRoberts. I wired the center pin on the pot to pin A0 and the servo signal wire to pin D5. The jumper wires I got from SparkFun Electronics make this so much easier to do than the alligator clips I usually use.
Next, I disconnected the pot and replaced it with an analog protoboard adapter from Vernier Software & Technology (same wiring). Vernier sells a 3-axis accelerometer, but I just plugged in the x-axis for the first pass. The servo arm responded to the movement of the accelerometer, but I didn't have the full 180° range of motion. (Have to figure out why...)

Incidentally, I discovered something about using servo motors with the Arduino board. I knew you controlled servos with Pulse-Width-Modulation (PWM), but I didn't realize that not all digital pins on the Arduino board provided that. Only the ones with the tilde ~ next to them provide PWM. A useful tip for the day.