Sunday, September 24, 2006

Lab: Comination Combo Lock & Luv Meter

I decided to combine these assignment, both as a challange and as a time saving device. What I came up with was a device with two photoells and two led's; the led's would switch from 'not' to 'hot' only when a certain (but different) range was returned on both photocells at the same time.

The code looks like this:

#define analogPin1 0 //photocell 1
#define analogPin2 1 //photocell 2
#define digitalPin1 3 //led 1
#define digitalPin2 4 //led 2

int analogInVar1;
int analogInVar2;
int digitalOutVar1;
int digitalOutVar2;

void setup (){
pinMode(analogPin1, INPUT);
pinMode (analogPin2, INPUT);
Serial.begin(9600);
}
void loop (){
analogInVar1 = analogRead(analogPin1);
analogInVar2 = analogRead(analogPin2);

Serial.print("Photocell 1 value: ");//get values
Serial.println(analogInVar1, DEC);
Serial.print("Photocell 2 value: ");
Serial.println(analogInVar2, DEC);

if (analogInVar1 < 30 && analogInVar2 < 800){
digitalWrite (3 , HIGH);
digitalWrite (4, LOW);
}
else{
digitalWrite (3, LOW);
digitalWrite (4, HIGH);
}
}

Here are some pictures:


The Interface


The Circuit

So from the code you can see that the wiring setup is fairly easy; the photocells go to analog pins 0 and 1 and the led's go to digial pins 3 and 4. The if statement is there to set the key to the lock - photo cell 1 must be < 30 and photo cell 2 must be <800 (I had wildly varient readings from the two photocells) for the led's to switch.

0 Comments:

Post a Comment

<< Home