Description
In this assignment, we needed to build a crawler using the servo motor. The task proved to be quite tricky, especially since I was working with only one motor. My initial idea was to create some sort of stilts to mimic bipedal movements. However, after some rapid prototyping, this turned out to be difficult to do.
I came to the final solution after a few rounds of prototyping. At one point, I simply attached a wooden stick and observed the movement as I spun the servo motor back and forth. While doing this, I realized that the ends of the stick were hitting the same areas--the motor didn't move forward because there was no friction between the stick and the surface. Following this, I tried to attach a kneaded rubber eraser (typically used while drawing with charcoal or pencil) to one end. The purpose is twofold: to put more weight on one end and to create some traction with the surface. This approach seemed to work, and afterward I continued to experiment with different weight and length to optimize the crawler.
A video demo can be seen here: https://drive.google.com/file/d/0BzNIHWmnbWZ6TkYtY29HOW1PWTg/edit?usp=sharing
Components
1x 10k Ohm Resistor
1x Diode
1x Transistor
1x DC motor
1x Arduino Uno
1x Breadboard
1x Macbook Pro
1x Ouija board
1x Coin
1x Kneaded rubber eraser
Code
int servoPin = 7; // Control pin for servo motor
int potPin = 0; // select the input pin for the potentiometer
int pulseWidth = 0; // Amount to pulse the servo
long lastPulse = 0; // the time in millisecs of the last pulse
int refreshTime = 20; // the time in millisecs needed in between pulses
int val; // variable used to store data from potentiometer
int minPulse = 500; // minimum pulse width
void setup() {
pinMode(servoPin, OUTPUT); // Set servo pin as an output pin
pulseWidth = minPulse; // Set the motor position to the minimum
Serial.begin(9600); // connect to the serial port
Serial.println("servo_serial_better ready");
}
void loop() {
val = analogRead(potPin); // read the value from the sensor, between 0 - 1024
if (val > 0 && val <= 999 ) {
pulseWidth = val*2 + minPulse; // convert angle to microseconds
Serial.print("moving servo to ");
Serial.println(pulseWidth,DEC);
}
updateServo(); // update servo position
}
// called every loop().
void updateServo() {
// pulse the servo again if the refresh time (20 ms) has passed:
if (millis() - lastPulse >= refreshTime) {
digitalWrite(servoPin, HIGH); // Turn the motor on
delayMicroseconds(pulseWidth); // Length of the pulse sets the motor position
digitalWrite(servoPin, LOW); // Turn the motor off
lastPulse = millis(); // save the time of the last pulse
}
}
- Login to post comments