IR Sensor + Multi-LED
http://vimeo.com/moogaloop.swf?clip_id=1905873&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1
Multicolor LED + IR sensor from Jessica Floeh on Vimeo.
Click below for the code:
http://vimeo.com/moogaloop.swf?clip_id=1905873&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1
Multicolor LED + IR sensor from Jessica Floeh on Vimeo.
Click below for the code:
http://vimeo.com/moogaloop.swf?clip_id=1908400&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1
Kissy Blushy monster from Subalekha Udayasankar on Vimeo
http://picasaweb.google.com/s/c/bin/slideshow.swf
int potPin = 3;
int potVal = 0;
int redPin = 9; // Red LED, connected to digital pin 9
int grnPin = 10; // Green LED, connected to digital pin 10
int bluPin = 11; // Blue LED, connected to digital pin 11
int pwr = 13;
int redVal = 0; // Variables to store the values to send to the pins
int grnVal = 0;
int bluVal = 0;
void setup()
{
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(grnPin, OUTPUT);
pinMode(bluPin, OUTPUT);
pinMode(pwr,OUTPUT);
}
// Main program
void loop()
{
potVal = analogRead(potPin); // read the potentiometer value at the input pin
digitalWrite(pwr,HIGH);
if (potVal < 341) // Lowest third of the potentiometer’s range (0-340)
{
potVal = (potVal * 3) /4; // Normalize to 0-255
redVal = 256 – potVal; // Red from full to off
grnVal = potVal; // Green from off to full
bluVal = 1; // Blue off
}
else if (potVal < 682) // Middle third of potentiometer’s range (341-681)
{
potVal = ( (potVal-342) * 3) /4; // Normalize to 0-255
redVal = 1; // Red off
grnVal = 256 – potVal; // Green from full to off
bluVal = potVal; // Blue from off to full
}
else // Upper third of potentiometer"s range (682-1023)
{
potVal = ( (potVal-683) * 3) /4; // Normalize to 0-255
redVal = potVal; // Red from off to full
grnVal = 1; // Green off
bluVal = 256 – potVal; // Blue from full to off
}
analogWrite(redPin, redVal); // Write values to LED pins
analogWrite(grnPin, grnVal);
analogWrite(bluPin, bluVal);
/*
digitalWrite(pwr,HIGH);
digitalWrite(redPin, LOW); // Write values to LED pins
digitalWrite(grnPin, LOW);
digitalWrite(bluPin, LOW);
*/
}
Last week’s assignment was "re-packaged" into the soap box. Few steps were necessary for this to work.
The LED was cut and a wire was attached to each leg:
Holes were drilled into the lid, and the sensor was glued:
http://vimeo.com/moogaloop.swf?clip_id=1971198&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=ffffff&fullscreen=1
Color Mixer in Soap Box from Fuki on Vimeo.
What a disaster! I’ve ruined one an IR sensor, and only just about managed to get this second one in action. I haven’t changed my code (yet), so I’m still using the code from the Arduino site. The code can been seen below.
http://vimeo.com/moogaloop.swf?clip_id=1906225&server=vimeo.com&show_title=1&show_byline=0&show_portrait=0&color=00ADEF&fullscreen=1
Color Mixer with an IR Sensor and a tri-color LED from Joana Kelly on Vimeo.
Here are some fine photos of the thing in action.
The Color Mixer
This is what my color mixer looks like from the top. The black rectangle on the right is my IR sensor. I’d like to make a nicer case for this soon.
The Innards
Here are the innards of my color mixer. It’s kind of a mess.
The Disaster
Through the simultaneous use of solder, wrapping wire, and hot glue, I finally got this working, for the most part. I do not recommend this approach. Jumper wires are definitely the way to go.
What up yo!
Check out my lil IR sensor with a full-color LED (aka RGB). It didn’t have to change my code, only replace my potentiometer with my IR sensor and my 3 LEDs with the 1 full-color LED.
Sweetness.

http://vimeo.com/moogaloop.swf?clip_id=1907094&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1
IR sensor light from Lynn WasHere on Vimeo.
p.s. here’s the code:
/*
* Code for making one potentiometer control 3 LEDs, red, grn and blu, or one tri-color LED
* The program cross-fades from red to grn, grn to blu, and blu to red
* Debugging code assumes Arduino 0004, as it uses Serial.begin()-style functions
* Clay Shirky <clay.shirky@nyu.edu>
*/
// INPUT: Potentiometer should be connected to 5V and GND
int potPin = 0; // Potentiometer output connected to analog pin 3
int potVal = 0; // Variable to store the input from the potentiometer
// OUTPUT: Use digital pins 9-11, the Pulse-width Modulation (PWM) pins
// LED’s cathodes should be connected to digital GND
int redPin = 9; // Red LED, connected to digital pin 9
int grnPin = 10; // Green LED, connected to digital pin 10
int bluPin = 11; // Blue LED, connected to digital pin 11
// Program variables
int redVal = 0; // Variables to store the values to send to the pins
int grnVal = 0;
int bluVal = 0;
int DEBUG = 1; // Set to 1 to turn on debugging output
void setup()
{
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(grnPin, OUTPUT);
pinMode(bluPin, OUTPUT);
if (DEBUG) { // If we want to see the pin values for debugging…
Serial.begin(9600); // …set up the serial ouput in 0004 format
}
}
// Main program
void loop()
{
potVal = analogRead(potPin); // read the potentiometer value at the input pin
if (potVal < 341) // Lowest third of the potentiometer’s range (0-340)
{
potVal = (potVal * 3) / 4; // Normalize to 0-255
redVal = 256 – potVal; // Red from full to off
grnVal = potVal; // Green from off to full
bluVal = 1; // Blue off
}
else if (potVal < 682) // Middle third of potentiometer’s range (341-681)
{
potVal = ( (potVal-341) * 3) / 4; // Normalize to 0-255
redVal = 1; // Red off
grnVal = 256 – potVal; // Green from full to off
bluVal = potVal; // Blue from off to full
}
else // Upper third of potentiometer"s range (682-1023)
{
potVal = ( (potVal-683) * 3) / 4; // Normalize to 0-255
redVal = potVal; // Red from off to full
grnVal = 1; // Green off
bluVal = 256 – potVal; // Blue from full to off
}
analogWrite(redPin, redVal); // Write values to LED pins
analogWrite(grnPin, grnVal);
analogWrite(bluPin, bluVal);
if (DEBUG) { // If we want to read the output
DEBUG += 1; // Increment the DEBUG counter
if (DEBUG > 100) // Print every hundred loops
{
DEBUG = 1; // Reset the counter
// Serial output using 0004-style functions
Serial.print("R:"); // Indicate that output is red value
Serial.print(redVal); // Print red value
Serial.print("\t"); // Print a tab
Serial.print("G:"); // Repeat for grn and blu…
Serial.print(grnVal);
Serial.print("\t");
Serial.print("B:");
Serial.println(bluVal); // println, to end with a carriage return
}
}
}
Video coming soon.
Uses the same code as the earlier iteration of the hacked touch lamp.
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.
So here it is! And it works pretty well. With my setup, the long pin on the LED actually goes to power and the other three hook up to the PMW pins on the Arduino and then go to ground (I stuck some resistors in there before taking that pins to ground). Here’s what it looks like:
http://vimeo.com/moogaloop.swf?clip_id=1903107&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1
IR Proximity Color Mixer w/ Tri-Color LED from Katrina Bekessy on Vimeo
And here’s some pics of the box itself and its innards:
The Box
Just a little cardboard gift box I cut up to make little windows with vellum paper…I used Velcro to keep the top closed.
The Insides!
Bascially the breadboard is stacked on top of the battery pack which is on top of the Arduino. Not elegant at all…
Close up of LED
Just a closer peek at the LED setup with the resistors
I found this webpage with a great example of a tri-color LED used with the exact IR sensor we’re using. It gave code for averaging/normalizing the sensor readings so that it won’t flicker at all. I tried to use it, but I couldn’t get it to work correctly. If anyone else wants to take a stab at it, check it out: http://letsmakerobots.com/node/672
Here’s a plain text file of my Arduino code. In a different file, I used the serial commands to read the range of my sensor…The highest it went was about 620, but I wasn’t really sure what that meant or how to make that meaningful through the way it would change the colors of the LED.
Reply