User login

Powered by Drupal, an open source content management system

Theory and Practice of Tangible User Interfaces

Servo Skier

Submitted by sarah_vanwart on Wed, 10/22/2008 - 21:09

Assignment: Servo Motor: Actuation Assignment 2

Collaborators:

Ljuba Miljkovic

Description

The purpose of this lab was to create an interesting Servo Motor to control motion.

Components Used

  • Arduino board
  • 2 Servo Motors
  • 1 Pot
  • Wires
  • colored paper
  • coffee cup lid
  • plastic cup
  • foam board
  • dowels

Cross Country Skier

Ljuba and I created a cross-country skier to experiment with the ways in which a servo motor can be used to control motion. The arms of the cross country skier move automatically at a regular interval to propel the skier forward.

Circuit Photos

Arduino Code

/*
 * Cross Country Skiier - by Ljuba and Sarah
 */

boolean onSwitch = false;
int servoPinLeg1 = 6;   // Control pin for servo motor leg 1
int servoPinLeg2 = 7;   // Control pin for servo motor leg 2
int potPinLeg1   = 0;   // select the input pin for pot controlling leg 1
int refreshTime  = 20;   // the time in millisecs needed in between pulses
int evenOdd      = 0;
int minPulse     = 500;     // minimum pulse width
int counter      = 0;
int potVal       = 0;
int lastPulse    = 0;
int minVal       = 1280;
int maxVal       = 1600;

void setup() 
{
  pinMode(servoPinLeg1, OUTPUT);  // Set servo pin as an output pin
  pinMode(servoPinLeg2, OUTPUT);  // Set servo pin as an output pin
  Serial.begin(9600);             // connect to the serial port
  Serial.println("servo_serial_better ready");
}


void loop() 
{
  potVal = analogRead(potPinLeg1);
  onSwitch = potVal > 200;
  if(onSwitch)
  {
     int timeElapsed = millis() - lastPulse;
     if(evenOdd == 0)
     {    
        for(int i=0; i < 30; i++)
        {
           digitalWrite(servoPinLeg1, HIGH); // Turn the motor on
           delayMicroseconds(minVal);    // Length of the pulse sets the motor position
           digitalWrite(servoPinLeg1, LOW);  // Turn the motor off
        
           digitalWrite(servoPinLeg2, HIGH); // Turn the motor on
           delayMicroseconds(minVal);    // Length of the pulse sets the motor position
           digitalWrite(servoPinLeg2, LOW);  // Turn the motor off
           evenOdd = 1;
           Serial.print("LEG 1 (even): ");
           Serial.println(minVal, DEC);  
           lastPulse = millis();
        }
     }
     else
     {
        for(int i=0; i < 30; i++)
        {
           digitalWrite(servoPinLeg1, HIGH); // Turn the motor on
           delayMicroseconds(maxVal);        // Length of the pulse sets the motor position
           digitalWrite(servoPinLeg1, LOW);  // Turn the motor off
        
           digitalWrite(servoPinLeg2, HIGH); // Turn the motor on
           delayMicroseconds(maxVal);    // Length of the pulse sets the motor position
           digitalWrite(servoPinLeg2, LOW);  // Turn the motor off
        
           evenOdd = 0;
           Serial.print("LEG 1 (odd): ");
           Serial.println(maxVal);  
           lastPulse = millis();
        }
     }
  }
}

Skier Photo

Link to video