IR controlled Mood Lamp
Here is a second fun project with High Power RGB LED Shield and Arduino.
It is very easy to make a Infrared remote controlled RGB mood lamp with Arduino. All you need are a common IR receiver diode and IR remote. Now, you have full control of color and brightness of the LED.
Receiving IR code from a remote is handled by Ken’s fantastic IRremote library.
http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html
What you need.
- Arduino (any version)
- High Power RGB LED shield
- RGB LED
- Infrared receiver diode (38KHz, TSOP328)
- IR remote (NEC, SONY, RC5, RC6 compatible)
You can find IR receiver diode from followings:
- Mouser : http://www.mouser.com/Search/ProductDetail.aspx?R=TSOP38238virtualkey61370000virtualkey782-TSOP38238
- Sparkfun : http://www.sparkfun.com/products/10266
- RadioShack : http://www.radioshack.com/product/index.jsp?productId=2049727
The IRremote library only decode 4 different IR codes, however they are very common types. It is highly likely you have one of those that are supported. I used a Canon camcorder remote.
Circuit
Depending on receiver diode. Normally 5V, GND, and signal.
Connect Signal pin to any digital pin (11). IR receiver does not look like in the picture though.
Setup Picture
Arduino + High Power RGB LED Shield + Heatsink + RGB LEDs + IR receiver
Arduino Code
First, install IRremote library from https://github.com/shirriff/Arduino-IRremote
You can find IR code of a remote by running IRrecvDemo example of IR remote library.
Change IR code of the sketch based on your IR remote code.
The Arduino sketch read IR code and output Hue or brightness value to the shield.
1: #include <Wire.h>
2: #include <HPRGB.h>
3: #include <IRremote.h>
4:
5: #define HUEUP 0xA16E54AB
6: #define HUEDOWN 0xA16ED42B
7: #define BRIGHTUP 0xA16E38C7
8: #define BRIGHTDOWN 0xA16EB847
9:
10: int RECV_PIN = 11;
11: int hueValue = 255;
12: int hueStep = 5;
13: int brightness = 255;
14: int brightnessStep = 5;
15:
16: HPRGB ledShield; // default mcp4728 id(0) and default czyRGB address(9)
17: IRrecv irrecv(RECV_PIN);
18: decode_results results;
19:
20: void setup()
21: {
22: ledShield.begin();
23: ledShield.setCurrent(700,700,700); // set maximum current for channel 1-3 (mA)
24: ledShield.setFreq(600);// operation frequency of the LED drive
25: ledShield.stopScript();
26: irrecv.enableIRIn(); // Start the receiver
27: }
28:
29: void loop() {
30: if (irrecv.decode(&results)) {
31: switch (results.value) {
32: case HUEUP: // Hue up
33: hueValue = hueValue + hueStep;
34: ledShield.fadeToHSB(hueValue, 255, brightness);
35: break;
36: case HUEDOWN: // Hue down
37: hueValue = hueValue - hueStep;
38: ledShield.fadeToHSB(hueValue, 255, brightness);
39: break;
40: case BRIGHTUP: // brightness up
41: if (brightness + hueStep < 255){
42: brightness = brightness + brightnessStep;
43: }
44: ledShield.fadeToHSB(hueValue, 255, brightness);
45: break;
46: case BRIGHTDOWN: // brightness down
47: if (brightness - brightnessStep > 0){
48: brightness = brightness - brightnessStep;
49: }
50: ledShield.fadeToHSB(hueValue, 255, brightness);
51: break;
52: }
53: irrecv.resume(); // Resume decoding (necessary!)
54: }
55: }
Video
Demonstration of setup and code