Assignment: Servo Motor: Actuation Assignment 2
Collaborators:
Description
Row, row, row your boat gently (or quickly, depending on your potentiometer) in a circle...
My servo motor uses half a clothespin and a rubberband to create friction and move the canoe forward (albeit in a circle). The potentiometer controls how quickly the boat moves.
Components Used
- Arduino board
- Bread board
- Wires
- Servo motor
- Potentiometer
- colored paper
- craft wire
- jewelry box
- cotton
- clothespin
- rubber band
- tape
Arduino Code
// Servo crawler with speed controlled by potentiomter
// adapted from Sweep in Arduino library by BARRAGAN <http://barraganstudio.com>
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
int potValue = 0; //value to store the input from the potentiometer
int potPin = 0; //control pin for the potentiometer
float delayValue = 0; //variable to store speed value
int minValue = 2; //minimum value for speed
void setup()
{
myservo.attach(7); // attaches the servo on pin 7 to the servo object
}
void loop()
{
for(pos = 0; pos < 120; pos += 1) // goes from 0 degrees to 130 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
potValue = analogRead(potPin); // reads potentiometer value
delayValue = (potValue/30 + minValue); //sets the delayValue to the potentiometer + min speed
delay(delayValue); // delay speed is set by pot value
}
for(pos = 120; pos>=1; pos-=1) // goes from 130 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
potValue = analogRead(potPin); // reads potentiometer value
delayValue = (potValue/30 + minValue); //sets the delayValue to the potentiometer + min speed
delay(delayValue); // delay speed is set by pot value
}
}
Photos
Canoe
Servo motor
Breadboard
Video