Here's the fine video of my IR sensor actually working!!
Another IR sensor + 3 LEDS from Joana Kelly on Vimeo.
I had some wacky issues connecting my IR sensor, but found a useful diagram, also including here:
I ended up adapting Matt's code also. My original code made the lights flicker a lot, but Matt averaged out the IR signal quite effectively. Kudos to you, sir. Matt's code is also after the jump.
Code
// Code to control 3 LEDs based on hand placement in relationship to an IR sensor
// M Bethancourt
// 2008#define NUMREADINGS 10
int readings[NUMREADINGS]; // the readings from the analog input
int index = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the averageint rLed = 9; // which light connected to digital pin 9
int gLed = 10;
int bLed = 11;int rValue = 255; // variable to keep the actual value
int gValue = 255; // variable to keep the actual value
int bValue = 255; // variable to keep the actual valueint rangeFinder = 5;
int closeValue = 0;void setup()
{
Serial.begin(9600); // setup serial
for (int i = 0; i < NUMREADINGS; i++)
readings[i] = 0; // initialize all the readings to 0
}void loop() {
total -= readings[index]; // subtract the last reading
readings[index] = analogRead(rangeFinder); // read from the sensor
total += readings[index]; // add the reading to the total
index = (index + 1); // advance to the next indexif (index >= NUMREADINGS) // if we're at the end of the array...
index = 0; // ...wrap around to the beginningaverage = total / NUMREADINGS; // calculate the average
Serial.println(average); // send it to the computer (as ASCII digits)
closeValue = average;
if(closeValue < 75){
analogWrite(rLed, 255);
analogWrite(gLed, 0);
analogWrite(bLed, 0);
} else if(closeValue >= 75 && closeValue <= 500){
analogWrite(rLed, 0);
analogWrite(gLed, 255);
analogWrite(bLed, 0);
} else if(closeValue > 500) {
analogWrite(rLed, 0);
analogWrite(gLed, 0);
analogWrite(bLed, 255);
}}
I've being researching about IR Devices and reading your blog, I found your post very helpful :) . I thought I would leave my first comment. I don't know what to say except that I have enjoyed reading.
Posted by: Surveillance Solutions | March 22, 2010 at 06:21 AM
A sensor what a great idea I watch the video its really a sensor great job and idea , thanks for sharing your project I hope other people watch this I mean view this post.
gu10 led
Posted by: Account Deleted | August 18, 2011 at 03:38 AM