User login

Powered by Drupal, an open source content management system

Theory and Practice of Tangible User Interfaces

Lab 6: Runaway Hummer

Submitted by ngandomi on Wed, 10/15/2008 - 17:15

Assignment: DC Motor: Actuation Assignment 1

Collaborators:

 

 

The Runaway Car

 

 

Materials:

 

  • mini-breadboard
  • arduino
  • 9v battery, 9v battery clip, 2.5mm power plug (to make arduino cordless)
  • AA battery pack to power motor
  • 1 3v motor
  • photosensor
Design:
This toy will attempt to escape from the grasp of anyone that comes close to it. I modified a cheap toy by pulling out its controller, replacing it with arduino, and attaching a photosensor to the top of the toy. When the photosensor senses an approaching object, the motor spins, increasing with proximity.
Problems: 
  • The motor was weaker than I expected, and doesn't move the car very fast.
  • The photosensor needs to be calibrated for different rooms (light values) or else it will run the motor even without a change in value. 
Code:
/*
/*
 * one pot fades one motor
 * modified version of AnalogInput
 * by DojoDave <http://www.0j0.org>
 * http://www.arduino.cc/en/Tutorial/AnalogInput 
 * Modified again by dave
 */
#include <math.h> //
int potPin = 0;   // select the input pin for the potentiometer
int motorPin = 9; // select the pin for the Motor
int val = 0;      // variable to store the value coming from the sensor
int br = 1000;     //variable to store a value for the brightness of the room
void setup() {
  Serial.begin(9600);
}
void loop() {
  val = analogRead(potPin);    // read the value from the sensor, between 0 - 1024
  Serial.println(val);
  
   if (br - val <50)
  analogWrite(motorPin, 0);
  else if (br - val <75)
  analogWrite(motorPin, val/1000); // analogWrite can be between 0-255
 else if (br-val<100)
  analogWrite(motorPin, val/500);
  else if (br-val<130)
  analogWrite(motorPin, val/250);
   else if (br-val<170)
  analogWrite(motorPin, val/125);
   else if (br-val<200)
  analogWrite(motorPin, val/65);
   else if (br-val<240)
  analogWrite(motorPin, val/33);
  else if( br-val<270)
  analogWrite(motorPin, val/15);
  else if (br-val<320)
   analogWrite(motorPin, val/7); // analogWrite can be between 0-255
  else if( br-val<380)
  analogWrite(motorPin, val/2);
  else if (br-val<450)
  analogWrite(motorPin, val);
  else if (br-val>450)
  analogWrite(motorPin, 0); //do something cool
  
  
 
}