User login

Powered by Drupal, an open source content management system

Theory and Practice of Tangible User Interfaces

Lab 7: Servo Motors

Submitted by Seth Horrigan on Tue, 10/21/2008 - 22:04

Assignment: Servo Motor: Actuation Assignment 2

Collaborators:

Description

In this assignment we are supposed to create a "crawler" - employing the rotational motion of the servo to provide linear motion of our artifact.

I missed the lab concerning servos because I was flying to Georgia for my brother's wedding. As such, I did not get access to a servo motor until the day before the assignment was due. Happily, Lora Oehlberg loaned me a second servo, allowing me to create an interesting project in a very short time.

I experimented briefly with different forms of linear motion, but in the end I chose to employ a set-up that resembles the example from the lab that I missed. I used the same general application of rotational force to move an object; however, I decided to make it more interesting by turning my altoids tin into something resembling a Mad Max-style tank.

 

Components Used

  • 1 Arduino board
  • 1 generic solderless breadboard
  • 2 rubber bands to secure the Arduino board to the breadboard
  • wires
  • 1 1k Ohm resistor
  • 1 diode
  • 1 transistor
  • 1 DC high-rotation, low-torque motor
  • 2 AA batteries in a battery pack
  • 2 wooden coffee stirrers
  • electrical tape
  • 1 pieces of string
  • 2 servo motors
  • 1 full Altoids can
  • 1 potentiometer

 

Images and Video

Servo-Acutated Altoid Tank in motion

 

The beast

The guts

Ready to rock and roll

 

 

Arduino Code

/*
* Servo with Potentiometer control
* Theory and Practice of Tangible User Interfaces
* October 11 2007
*/

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(7, 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");
analogWrite(9, 100);
}

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(7, HIGH); // Turn the motor on
delayMicroseconds(pulseWidth); // Length of the pulse sets the motor position
digitalWrite(7, LOW); // Turn the motor off
lastPulse = millis(); // save the time of the last pulse
}
}