Arduino-controlled IKEA Lamp

This is a project I have been working on for the past 2-3 weeks. I wanted to create a night light which had to be very simple to use and with no parts that can be consumed by babies! 🙂

I used 20 RGB LEDs (which I got from www.oomlout.co.uk), an old Eriksson phone charger and, of course an arduino board (actually I used an old SparkFun clone). And a push button… And an Ikea lamp (“Lampan”, currently priced at £2.59 in the UK, around $5 in the States, http://www.ikea.com/gb/en/catalog/products/40055420). This is a very cheap lamp, very hackable and safe for kids too (as all the components are safely hidden away). Many projects are based around this lamp:
http://ikeahacker.blogspot.com/2007/08/new-look-for-lampan-lamp.html
http://www.instructables.com/id/Big-lamps-from-Ikea-lampan-lamps./

I found that the old Eriksson charger delivers approx 6V, which is good enough for the Arduino. I removed the original plug from the charger and added a standard 9V clip instead.

erikkson adapter

I did the same on the IKEA lamp – I added 9V clips on both sides of the cable.
lamp_inside

Charger Connected

I fitted the 20 LEDs on one board. It’s important to note that the LEDs fit nicely on a standard board if you put them diagonally. I’m not good at soldering, but putting together this board was actually easier than I originally anticipated.
For more information on these RGB LEDs, have a look at this great one page summary kindly put together from the Oomlout team: http://oomlout.com/RGBL/RGBL-Guide.pdf

20_leds

leds_diagonal

A useful, probably obvious, tip is that it helps if, throughout the project, you are using colour coded cables (i.e. red cable for the red pins etc…).
leds_back

Here is the final lamp:
combination

Here is a video demonstration – at the end of the video you can see the random mode, where the colours change gradually:

Arduino-powered IKEA Lampan Lamp from Arkadian.Eu on Vimeo.

… and here is the arduino code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#include <EEPROM.h>
 
//RGB LED pins - These pins must be PWM
//here: 9 = redPin, 10 = greenPin, 11 = bluePin
int ledAnalogOne[] = {
  9, 10, 11}; 
 
// Push button, any free digital pin will do
int myButton = 7;
// I will fix pin 13 at HIGH at setup and use it as another voltage pin.
// It also lights the onboard led.
int my13 = 13;
 
// Reading the previous selection from the eeprom memory
int myOption = EEPROM.read(0);
 
int options = 15;
 
// these following are useful for debouncing
int mydelay = 10;
int reading = 0;
long lastDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 300;   // the debounce time; increase if the output flickers
 
//Defined Colors (different RGB (red, green, blue) values for colors
const byte RED[] =     {255, 0, 0}; 
const byte ORANGE[] =  {83, 4, 0}; 
const byte YELLOW[] =  {255, 255, 0}; 
const byte GREEN[] =   {0, 255, 0}; 
const byte BLUE[] =    {0, 0, 255}; 
const byte WHITE[] =   {255, 255, 255}; 
const byte BLACK[] =   {0, 0, 0}; 
const byte PINK[] =    {158, 4, 79}; 
const byte B2[] =      {0, 128, 255}; 
const byte G2[] =      {128, 255, 0}; 
const byte R2[] =      {255, 128, 0}; 
const byte B3[] =      {128, 0, 255}; 
const byte G3[] =      {0, 255, 128}; 
const byte R3[] =      {255, 0, 128}; 
 
byte myOldC[] = {255, 255, 255};
 
void setup(){
for(int i = 0; i < 3; i++){pinMode(ledAnalogOne[i], OUTPUT);}
setColor(ledAnalogOne, BLACK);       //Turn off led 1
pinMode(my13, OUTPUT);   
digitalWrite(my13, HIGH);
Serial.begin (9600);
}
 
void loop(){  
 
  readButton();
 
    if(myOption==0){
    mydelay = 15;
    randomC();
    }
 
    if(myOption==1){
    mydelay = 0;
    setColor(ledAnalogOne, RED);
    }    
 
    if(myOption==2){
    mydelay = 0;
    setColor(ledAnalogOne, BLUE);
    }       
 
    if(myOption==3){
    mydelay = 0;
    setColor(ledAnalogOne, GREEN);
    }  
 
    if(myOption==4){
    mydelay = 0;
    setColor(ledAnalogOne, YELLOW);
    }  
 
    if(myOption==5){
    mydelay = 0;
    setColor(ledAnalogOne, PINK);
    }    
 
    if(myOption==6){
    mydelay = 0;
    setColor(ledAnalogOne, ORANGE);
    } 
 
    if(myOption==7){
    mydelay = 0;
    setColor(ledAnalogOne, B2);
    }  
 
    if(myOption==8){
    mydelay = 0;
    setColor(ledAnalogOne, G2);
    }  
 
    if(myOption==9){
    mydelay = 0;
    setColor(ledAnalogOne, R2);
    }     
 
    if(myOption==10){
    mydelay = 0;
    setColor(ledAnalogOne, B3);
    }  
 
    if(myOption==11){
    mydelay = 0;
    setColor(ledAnalogOne, G3);
    }  
 
    if(myOption==12){
    mydelay = 0;
    setColor(ledAnalogOne, R3);
    }     
 
    if(myOption==13){
    mydelay = 0;
    setColor(ledAnalogOne, WHITE);
    }    
 
    if(myOption==14){
    mydelay = 0;
    setColor(ledAnalogOne, BLACK);
    } 
}
//////////////////////////////////////////////////////////////
 
void readButton(){
 
   reading = digitalRead(myButton);
   if ((millis() - lastDebounceTime) > debounceDelay && digitalRead(myButton)== HIGH) {
     // whatever the reading is at, it's been there for longer
     // than the debounce delay, so take it as the actual current state:
     lastDebounceTime = millis();
 
   myOption = (myOption + 1) % options;
   EEPROM.write(0, myOption);
//   Serial.print ("PRESSED - ");
//   Serial.println (myOption);
   }
}
 
 
//////////////////////////////////////////////////////////////
void randomC(){
 int tmp = int(random(0,12));
 byte myRandomC[] = {0,0,0};
 
  if(tmp == 0){for(int i = 0; i < 3; i++){myRandomC[i] = RED[i];}}
  if(tmp == 1){for(int i = 0; i < 3; i++){myRandomC[i] = ORANGE[i];}}
  if(tmp == 2){for(int i = 0; i < 3; i++){myRandomC[i] = YELLOW[i];}}
  if(tmp == 3){for(int i = 0; i < 3; i++){myRandomC[i] = GREEN[i];}}
  if(tmp == 4){for(int i = 0; i < 3; i++){myRandomC[i] = BLUE[i];}}
  if(tmp == 5){for(int i = 0; i < 3; i++){myRandomC[i] = B2[i];}}
  if(tmp == 6){for(int i = 0; i < 3; i++){myRandomC[i] = G2[i];}}
  if(tmp == 7){for(int i = 0; i < 3; i++){myRandomC[i] = R2[i];}}
  if(tmp == 8){for(int i = 0; i < 3; i++){myRandomC[i] = B3[i];}}
  if(tmp == 9){for(int i = 0; i < 3; i++){myRandomC[i] = G3[i];}}
  if(tmp ==10){for(int i = 0; i < 3; i++){myRandomC[i] = R3[i];}}
  if(tmp ==11){for(int i = 0; i < 3; i++){myRandomC[i] = WHITE[i];}}
  if(tmp ==12){for(int i = 0; i < 3; i++){myRandomC[i] = PINK[i];}}
 
    fadeToColor(ledAnalogOne, myOldC, myRandomC,  mydelay );     
 
    myOldC[0]= myRandomC[0];
    myOldC[1]= myRandomC[1];
    myOldC[2]= myRandomC[2];
}
 
//////////////////////////////////////////////////////////////
////////////// Functions from oomlout.co.uk.... //////////////
//////////////////////////////////////////////////////////////
/* Sets the color of the LED to any RGB Value
 led - (int array of three values defining the LEDs pins (led[0] = redPin, led[1] = greenPin, led[2] = bluePin))
 color - (byte array of three values defing an RGB color to display (color[0] = new Red value, color[1] = new Green value, color[2] = new Red value
 */
void setColor(int* led, byte* color){
  for(int i = 0; i < 3; i++){             //iterate through each of the three pins (red green blue)
    analogWrite(led[i], 255 - color[i]);  //set the analog output value of each pin to the input value (ie led[0] (red pin) to 255- color[0] (red input color)
    //we use 255 - the value because our RGB LED is common anode, this means a color is full on when we output analogWrite(pin, 0)
    //and off when we output analogWrite(pin, 255). 
  }
}
 
/* A version of setColor that takes a predefined color (neccesary to allow const int pre-defined colors */
void setColor(int* led, const byte* color){
  byte tempByte[] = {color[0], color[1], color[2]};
  setColor(led, tempByte);
}
 
/* Fades the LED from a start color to an end color at fadeSpeed
 led - (int array of three values defining the LEDs pins (led[0] = redPin, led[1] = greenPin, led[2] = bluePin))
 startCcolor - (byte array of three values defing the start RGB color (startColor[0] = start Red value, startColor[1] = start Green value, startColor[2] = start Red value
 endCcolor - (byte array of three values defing the finished RGB color (endColor[0] = end Red value, endColor[1] = end Green value, endColor[2] = end Red value
 fadeSpeed - this is the delay in milliseconds between steps, defines the speed of the fade
 */
void fadeToColor(int* led, byte* startColor, byte* endColor, int fadeSpeed){
  int changeRed = endColor[0] - startColor[0];                            //the difference in the two colors for the red channel
  int changeGreen = endColor[1] - startColor[1];                          //the difference in the two colors for the green channel 
  int changeBlue = endColor[2] - startColor[2];                           //the difference in the two colors for the blue channel
  int steps = max(abs(changeRed),max(abs(changeGreen), abs(changeBlue))); //make the number of change steps the maximum channel change
 
    for(int i = 0 ; i < steps; i++){                                       //iterate for the channel with the maximum change
    byte newRed = startColor[0] + (i * changeRed / steps);                 //the newRed intensity dependant on the start intensity and the change determined above
    byte newGreen = startColor[1] + (i * changeGreen / steps);             //the newGreen intensity
    byte newBlue = startColor[2] + (i * changeBlue / steps);               //the newBlue intensity
    byte newColor[] = {newRed, newGreen, newBlue};                         //Define an RGB color array for the new color
    setColor(led, newColor);    //Set the LED to the calculated value
    readButton();  
    if(myOption==0){delay(fadeSpeed);}  
  }
  setColor(led, endColor);                 //The LED should be at the endColor but set to endColor to avoid rounding errors
}
 
/* A version of fadeToColor that takes predefined colors (neccesary to allow const int pre-defined colors */
void fadeToColor(int* led, const byte* startColor, const byte* endColor, int fadeSpeed){
  byte tempByte1[] = {startColor[0], startColor[1], startColor[2]};
  byte tempByte2[] = {endColor[0], endColor[1], endColor[2]};
  fadeToColor(led, tempByte1, tempByte2, fadeSpeed);
}
//////////////////////////////////////////////////////////////

If you are thinking of building something similar and you have any questions, just drop me a line.

10 thoughts on “Arduino-controlled IKEA Lamp

  1. Hi Alessandro,

    adding a remote control is a great idea!

    I just had a look at your post about your remote control and looks very cool!
    I have a couple of projects in mind that need remote controls, so I will definitely borrow a few lines from your code!

    thanks!

  2. did you put a resistor on the color leads? if so, what value?
    what did you connect each of the 4 wires coming off the board to?
    thanks!

  3. Hi Nick,

    Thanks for leaving a comment!

    I connected the LED’s straight on the arduino (with no resistors). Oomlout.co.uk (where I bought the LEDs from) suggest a 270 Ohm resistance on each RGB pin.

    For this project to work, you need to use the PWM pins. I used 9,10 & 11 for R, G & B.

    I connected the common anode directly on the 5V coming from the power adapter.

  4. Can you post a few more pictures of how you enclosed the Arduino and how you placed the LED board in the lamp? I think this is a fantastic project, thank you so much for sharing!

  5. Hi Jay,

    thanks for your comment!

    When I reached the stage of putting the arduino and the LEDs in the lamp, I got so focused on putting it together that I forgot to take any photos…

    Anyway, here is a short description of the process:

    1. I used my soldering iron to make the hole for the button (I have a tip that I only use for melting plastic).

    2. I didn’t want to make any holes for securing the arduino+LED board in place, so, I took two transparent sheets of plastic, made 4 holes at the four edges so that I could put 4 tiny bolts.

    3. I hotglued the bottom sheet on the base of the lamp with the tiny bolts pointing up, then I placed the arduino & the LED board. Finally, I placed the other plastic sheet on top and secured everything with some small nuts.

    Next time, I’ll make sure I use my camera…

  6. Is there any possible way you could add pictures of how you mounted the Arduino? I’m having some trouble understanding your description.

Comments are closed.