This post documents my first foray into the world of using Arduino for more than blinking LEDs! We’re finally getting into the art of making things move, and this week we focused on motors. Servomotors, to be more specific. The beauty of servos is that they can be positioned into specific angular positions; all you have to do is send the servo a signal through a variable resistor (I used a potentiometer, just to break up the FSR rut that my Stupid Pet Trick plunged me into).

I decided to actually provide some good documentation this week, so I grabbed a Panasonic LX5 from the ER and even (gasp!) a tripod. But even though I recorded some nice video, my devices revolted and refused to read any of the stuff that I shot. The best that I could do was one screenshot.

You can see in this one how the servomotor and potentiometer are connected to output and input pins (respectively). The white tip on the servomotor would move (up to 280 degrees) according to how I adjusted the potentiometer, and when I moved the potentiometer up to its highest 1023 setting, the servo started to buz and shake.

See, even when I try to set things up all nicely, the end result is still a blurry photo. Sigh.

Here’s the code (in italics) to make up for the lack of video documentation and prove that I did it:

#include <Servo.h>

 int analogValue = 0;

Servo servoMotor;

int servoPin = 2;

 void setup() {

 //pinMode(A0, INPUT); 

 Serial.begin(9600);

 servoMotor.attach(servoPin);

}

 void loop() {

  analogValue = analogRead(A0);

  Serial.println(analogValue);

    int servoAngle = map(analogValue, 0, 1023,0,179);  

  servoMotor.write(servoAngle);

  }