Lab 7: Output: Servo motors
Description
For this lab, we introduced movement to our collection of possible outputs that can be facilitated by the Arduino. Using servo motors, we can use the Arduino to make parts spin or rotate. And with some creativity, we can make our Arduino crawl.
Because a single servo motor is rather limited in its movement variety, it inspires a lot of creativity to how far it can be pushed. But before exploring how far a servo motor can go, the first part was of course learning how to use it.
Dancing Pipe Cleaner
For the in-class portion of this lab, we of course first learned how to connect and implement the servo motor. Because the motor turns very quickly and it’s hard to tell the degree with symmetrical shapes, a pipe cleaner is affixed to the horn so its direction becomes very clear.
A potentiometer can also be attached to directly turn the servo motor to the desired direction.
Crawler (or Pusher!)
The challenge of this lab was making the servo motor crawl. And this truly was a challenge! Considering the function of a leg or similar appendage, a single servo motor can only function as one “joint.” So, my goal was to make another joint!
My solution ended up being a wooden chopstick broken in two, each part joined by a nail. The smaller part was then affixed to the horn of the servo motor. I made the sides asymmetric so that there would be enough leverage for the other part to “push” off the ground. At the base is a piece of cardboard wrapped in rubber band, for more friction, enabling it to move away from the floor. Packing tape is affixed to the bottom of the crawler, a long with a cushion underneath the front edge, again for leverage for the leg. Combined, these make it glide more easily.
Lastly, a potentiometer is used to control the speed. Surprisingly, high speeds don’t necessarily make the crawler move quicker. Unsurprisingly, this is because the timing of the leg swinging is a little off. But still, with much effort on the crawler’s part, it pushes forward!
Components
- Arduino
- Breadboard
- Potentiometer
- Servo Motor
- various colorful wires
- wooden chopstick
- nail
- packing tape
- masking tape
- scrap cardboard
- rubberband
Code
// Modification of Servo Sweep
/* Servo Sweep
just makes the servo sweep back and forth repeatedly
by BARRAGAN
This example code is in the public domain.
modified 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Sweep
*/
#include <Servo.h>
int servoPin = 7; // pin for the servo motor
int potPin = A0; // pin for pot
float potVal = 0; // variable to store value of pot
float potMax = 1023; // maximum expected value for input
float speedMax = 7; // maximum speed crawler can crawl
float potSpeed = 0; // variable to store speed value derive from pot
float speed = 1; // default speed
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
Serial.begin(9600); // monitor speed
myservo.attach(servoPin); // attaches the servo on pin servoPin to the servo object
}
void loop() {
// read the pot value and convert it to the a number to use for speed
potVal = analogRead(potPin);
potSpeed = (potVal / potMax);
speed = 1 + (potSpeed * speedMax);
Serial.println(speed);
for (pos = 90; pos >= 0; pos -= speed) { // goes from 90 degrees to 0 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 0; pos <= 270; pos += speed) { // goes from 0 degrees to 270 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
This solution took a lot of trial and error. My first few attempts instead had the crawler throw its leg forward, as one might a fishing pole, in order to drag it forward. This didn’t work very well as I couldn’t encourage the servo motor to rotate quickly enough to flick the leg forward reliably.
This crawler gets frustrated easily and falls over, but placing the motor itself toward the back rather than the front prevented this from happening too often.
For another go at making a crawler, I would definitely like to try combining 2 or 3 more servo motors! It can definitely crawl better with better control over how the joints are to move rather than relying solely on basic physics!