Assignment: Servo Motor: Actuation Assignment 2
Collaborators: janani, neha
Description
This time, Janani, Neha, and I made a crawling (walking) Wall-E and a gracefully rotating Eva. Two servo motors are used for Wall-E's legs and one motor is for rotating his head. Under Eva, there is also one motor and this supports her moving as well.
Components
Arduino
4 Servo motors
3 potentiometers
Lego blocks
Eva
Tape
Arduino Code
[Wall-E]
/*
* Three servos with two potentiometer controls
* October 21 2009
*
*/
int servoPin1 = 7; // Control pin for servo motor 1
int servoPin2 = 8; // Control pin for servo motor 2
int servoPin3 = 6; // Control pin for servo motor 3
int potPin1 = 0; // select the input pin for the potentiometer 1
int potPin2 = 2; // select the input pin for the potentiometer 2
int pulseWidth1 = 0; // Amount to pulse the servo 1
int pulseWidth2 = 0; // Amount to pulse the servo 2
int pulseWidth3 = 0; // Amount to pulse the servo 3
long lastPulse1 = 0; // the time in millisecs of the last pulse of servo 1
long lastPulse2 = 0; // the time in millisecs of the last pulse of servo 2
long lastPulse3 = 0; // the time in millisecs of the last pulse of servo 3
int val_1 =0; // variable used to store data from potentiometer 1
int val_2 =0; // variable used to store data from potentiometer 2
int val_3 =0; // variable used to store data from potentiometer 3
int refreshTime = 20; // the time in millisecs needed in between pulses
int minPulse = 500; // minimum pulse width
void setup() {
pinMode(servoPin1, OUTPUT); // Set servo pin 1 as an output pin
pinMode(servoPin2, OUTPUT); // Set servo pin 2 as an output pin
pinMode(servoPin3, OUTPUT); // Set servo pin 3 as an output pin
pulseWidth1 = minPulse; // Set the motor position to the minimum
pulseWidth2 = minPulse; // Set the motor position to the minimum
pulseWidth3 = minPulse; // Set the motor position to the minimum
Serial.begin(9600); // connect to the serial port
Serial.println("Three servos with two potentiometers ready");
}
void loop() {
val_1 = analogRead(potPin1); // read the value from the sensor 1, between 0 - 1024
val_2 = analogRead(potPin1); // read the value from the sensor 2, between 0 - 1024
val_3 = analogRead(potPin2); // read the value from the sensor 3, between 0 - 1024
Serial.println(potPin1);
Serial.println(potPin2);
if (val_1 > 0 && val_1 <= 999 ) {
pulseWidth1 = val_1*2 + minPulse; // convert angle to microseconds
pulseWidth2= val_2*2 + minPulse;
}
updateServo1(); // update servo 1 position
updateServo2(); // update servo 2 position
Serial.println("Servos 1 and 2 updated");
if (val_3 > 0 && val_3 <= 999 ) {
pulseWidth3 = val_3*2 + minPulse; // convert angle to microseconds
}
updateServo3(); // update servo 3 position
Serial.println("Servo 3 updated");
}
void updateServo1() {
if (millis() - lastPulse1 >= refreshTime) {
digitalWrite(servoPin1, HIGH);
delayMicroseconds(pulseWidth1);
digitalWrite(servoPin1, LOW);
lastPulse1 = millis();
}
}
void updateServo2() {
if (millis() - lastPulse2 >= refreshTime) {
digitalWrite(servoPin2, HIGH);
delayMicroseconds(pulseWidth2);
digitalWrite(servoPin2, LOW);
lastPulse2 = millis();
}
}
void updateServo3() {
if (millis() - lastPulse3 >= refreshTime) {
digitalWrite(servoPin3, HIGH);
delayMicroseconds(pulseWidth3);
digitalWrite(servoPin3, LOW);
lastPulse3 = millis();
}
}
Image
Video Links
1. Wall-E doesn't quite make it
http://www.youtube.com/watch?v=rqJEUWc1sF4
2. Wall-E meets Eva