Making Things Interactive

February 12, 2008

Assignment 5: Making Motion

Filed under: 5: Making Motion,Siddartha Butalia — sbutalia @ 1:43 am

For this assignment I wanted to understand the basics of motor control and how to switch using a transistor. On the other side, i wanted to experiement with photo sensors as I may end up using them in my end of year project. The program I wrote basically takes two analog inputs from two seperate photo sensors which are connected as switches, these in turn control individual motors. I experimented a lot with the analog inputs creating a calibration phase and implementing a sensitivity factor into the sensors. I found it to work quite well, and the calibration section was definetley (successfull under dark and light conditions). The one thing i noticed while fine tuning the sensors is that they are very tricks to use when there is one source of light and not much ambient light. If i had more time i would have wanted to incorporate more photosensors to actually try and analyze the environment, understanding whehter or not the light is ambient, or harsh directional through differences in calibration voltages.

Free Image Hosting at www.ImageShack.us

 heres the code:


int ledPin = 13; // defines the check pin
int CalPin = 12; // defines the Calibration LED Pin
int inputPin = 2; // defines input for sensor A
int inputPin1 = 3; // defines input for sensor B
int ValA = 0; // Initializes Sensor A reading
int ValB = 0; // Initializes Sensor B reading
int motorPin = 8; // defines output for motor A
int motorPin1 = 9; // defines output for motor B
int CalA = 0; // Initializes Sensor A calibration reading
int CalB = 0; // Initializes Sensor B calibration reading
float Sens = .85; // Defines the sensitivity of the photocells (0 - 1.0 "always on")

void setup() {

pinMode(ledPin, OUTPUT); // declare check LED Pin
pinMode(motorPin,OUTPUT); // declare Motor PinA
pinMode(motorPin1, OUTPUT); // declare Motor PinB
pinMode(12,OUTPUT); // declare Calibration Complete Pin
pinMode(inputPin, INPUT); // declare SensorA input Pin
pinMode(inputPin1, INPUT); // declare SensorB input Pin

Serial.begin(9600);
digitalWrite(CalPin, HIGH);
delay(500);
digitalWrite(CalPin, LOW);
delay(500);
CalA = analogRead(1); // Retrieve Ambient Light value for A
CalB = analogRead(0); // Retrieve Ambient Light value for B
digitalWrite(CalPin, HIGH); // Confirms Calibration Complete
delay(500);
digitalWrite(CalPin,LOW);
}

void loop(){

ValA = analogRead(1); // Retrieve Light value Sensor A
ValB = analogRead(0); // Retrieve Light value Sensor B

if (ValA > CalA*Sens) { // check if the input is larger than the threshold (taken from calibration & sensitivity factor)
digitalWrite(ledPin, LOW); // turn check LED OFF
digitalWrite(motorPin,LOW); // turn Motor A OFF
}
else {
digitalWrite(ledPin, HIGH); // turn check LED ON
digitalWrite(motorPin,HIGH); // turn Motor A ON
}

if (ValB > CalB*Sens) { // check if the input is larger than the threshold (taken from calibration & sensitivity factor)
digitalWrite(ledPin, LOW); // turn check LED OFF
digitalWrite(motorPin1,LOW); // turn Motor B OFF
}
else {
digitalWrite(ledPin, HIGH); // turn check LED ON
digitalWrite(motorPin1,HIGH); // turn Motor B ON
}
}

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: