Christmas is just around the corner! In this project, we will make a small acrylic LED Arduino Christmas Tree with Arduino Mega and RGB LEDs. We’ll be using ROHM’s temperature sensor and barometric pressure sensor to change the LED colors. It’s easy to build and code the program. It’ll be super fun to decorate your home with this LED Christmas Tree!
A guide to how to setup the sensor shield and connect to Arduino was covered in the previous article. If you haven’t already, please refer back to ROHM Sensor Evaluation Kit Overview!
The Christmas tree will do the following:
Figure 1. Arduino Mega 2650 (left), ROHM Arduino Shield(right), ROHM sensors(top)
Figure 2. RGB LED with common cathode (-) (left), RGB LED with common anode (+) (right)
Figure 3. Male- female connectors
Figure 4. Power supply 12V
To start let’s make the Christmas tree base using acrylic. Draw the tree on a paper that cover the acrylic then use a small hacksaw to cut the acrylic to make the base for the tree (Figure 5). Next drill holes for the following:
Let’s also cut a small star shape using the leftover acrylic (Figure 6) and glue to the tree (use CA or strong glue).
Figure 5. Christmas trees base from acrylic.
Place red LEDs onto the Christmas tree through the drilled holes then solder the wires so that all the red LEDs are connected in parallel. Make sure all the LEDs are correctly positioned so all anode (+) and cathode (-) are separately connected together. Serially solder a 39 Ohm resistor to red LED’s cathode(-). Also solder 2 connectors: Red connector will go to Arduino Pin 24 and brown connector will go to Arduino Pin GND.
There are 2 types of RGB LED: RGB LED with common cathode(-) as in Figure 2 (left) and RGB LED with common anode(+) as in Figure 2 (right). Both can be used in this project. The only difference between the two is, for the common cathode you need to connect the (-) pin into Ground(GND) and for common anode, you need to connect the (+) pin into 5V.
To show how to use these 2 types of RGB LEDs, we will use 3 common anode RGB LEDs (RGB LED1, RGB LED2 and RGB LED3) and 2 common cathode RGB LEDs (RGB LED4 and RGB LED5). Attach this 5 RGB LEDs to the Christmas tree using double tape (see Figure 6).
Figure 6. Christmas Tree with attached RGB LEDs, red LEDs and connectors
You can see the installation (back side) in Figure 7. Lastly, solder all connections between LEDs, wires, and resistor.
Figure 7. View from the back
Next, connect the 3 wires male-female connectors to RGB LED’s pin, each wire to R-pin, G-pin and B-pin. Figure 8 shows which pins in Arduino Mega these wires are connected to:
Figure 8. With RGB LEDs connectors
Connect 3 parallel wires to RGB LED 1 (+), RGB LED 2(+) and RGB LED 3(+) and the other end to Arduino Pin 5V.
Connect 2 parallel wires to RGB LED 4 (-) and RGB LED 5(-) and the other end to Arduino Pin GND.
Figure 9. With all LEDs and connectors
Attach 3 hex nut standoff to Arduino Mega as shown below:
Figure 10. Arduino Mega with attached hex nut screw standoffs
Attach ROHM Shield on top of Arduino Mega (make sure the pins are aligned), then connect the ROHM Temperature Sensor to Analog 2 header and ROHM Barometric Pressure sensors to I2C header on the ROHM Sensor Shield.
Figure 11. Arduino Mega with attached ROHM Sensor Shield and two sensors on top
The Barometric Sensor work with either 1.8V or 3V, and the Temperature sensor work only with 3V or 5V. So we must set the voltage to 3V by putting the jumper into 3V (Figure 12).
For more information on ROHM sensors, please refer back to ROHM Sensor Evaluation Kit Overview.
Figure 12. Putting jumper into 3V
Remember we drilled the holes for the Mega? Attach the Mega and ROHM Sensor Shield to the Christmas tree using 3 screws.
Figure 13. Arduino Mega and ROHM Shield after attached to Christmas tree.
Now connect 3 wires cable from RGB LEDs to Arduino pins. Use the following table and Figure 8 as a guide. The program that will be discussed later will use the following pins so make sure the pins match as below.
Assignment of pins from RGB LEDs to Arduino:
Connection to Arduino | RGB R- Pin | RGB G- Pin | RGB B- Pin |
RGB Led 1 | Arduino Pin 36 | Arduino Pin 34 | Arduino Pin 38 |
RGB Led 2 | Arduino Pin 3 | Arduino Pin 4 | Arduino Pin 2 |
RGB Led 3 | Arduino Pin 6 | Arduino Pin 5 | Arduino Pin 7 |
RGB Led 4 | Arduino Pin 9 | Arduino Pin 8 | Arduino Pin 10 |
RGB Led 5 | Arduino Pin 12 | Arduino Pin 13 | Arduino Pin 11 |
Figure 14. Connect RGB LED’s wires to Arduino
Then connect 3 parallel wires (from RGB LED (+)) into 5V and 2 parallel wires (from RGB LED(-)) into GND.
Connect others cable from red LED (-) into the other GND pin in Arduino and from red LED (+) into pin 24.
Figure 15. Attach other wires to Arduino.
Figure 16. Zoomed in on the connection
Attach the base to make it stand by itself. Now we have finished making of Christmas tree! Figure 17 shows what it looks like when everything is assembled:
Figure 17. Complete LED Christmas tree
Program to test sensors
Now let’s test the sensors using the following program. This program was developed using two sample programs from ROHM. Basically it reads data from the sensors and print it into serial monitor.
First, download two libraries (BM1383GLV.h and BD1020.h) from this website : http://www.rohm.com/web/global/sensor-shield-support/pressure-sensor and http://www.rohm.com/web/global/sensor-shield-support/temperature-sensor
Then, copy them into Arduino Library together with other libraries that were already installed before. Next, copy the following program and upload into the Arduino board. Don’t forget to specify “Arduino/Genuino Mega or Mega 2560” in Tools/Board Manager!
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 |
//****************************************************************************** #include <Wire.h> #include <BM1383GLV.h> #include <BD1020.h> int tempout_pin = A2; BM1383GLV bm1383; BD1020 bd1020; //***********setup******************* void setup() { Serial.begin(9600); while (!Serial); bd1020.init(tempout_pin); byte rc; while (!Serial); Wire.begin(); rc = bm1383.init(); } //*********** start loop *************** void loop() { //******* read Barometric Pressure***** byte rc; float press; rc = bm1383.get_val(&press); if (rc == 0) { Serial.write("BM1383GLV (PRESS) = "); Serial.print(press); Serial.println(" [hPa]"); Serial.println();} //******** read Temperature ********** float temp; bd1020.get_val(&temp); //********* print to serial monitor ****** Serial.print("BD1020HFV Temp="); Serial.print(temp); Serial.print(" [degrees Celsius], ADC="); Serial.println(bd1020.temp_adc); //**************end loop*************** } //***************************************************************************** |
When the program runs correctly open the serial monitor and you will see display similar to below:
Now we are ready for the final program. This program will do the following:
Next copy the following program into your Arduino IDE, then change the value of temperature and barometric pressure to suite your local environment.
Finally check again that assignment of pins match as shown in Table 1 and Figure 8.
When everything is correct upload them into the board.
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 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 |
//****************************************************************************** #include <Wire.h> #include <BM1383GLV.h> #include <BD1020.h> BM1383GLV bm1383; int tempout_pin = A2; // analog temperature sensor BD1020 bd1020; //******* RGB Led 1 (non PWM) ******* int redPin1 = 36; int greenPin1 = 34; int bluePin1 = 38; //******* RGB Led 2 (PWM ) ******* int redPin2 = 3; int greenPin2 = 4; int bluePin2 = 2; //******* RGB Led 3 (PWM) ******* int redPin3 = 6; int greenPin3 = 5; int bluePin3 = 7; //******* RGB Led 4 (PWM) ******* int redPin4 = 9; int greenPin4 = 8; int bluePin4 = 10; //******* RGB Led 5 (PWM) ******* int redPin5 = 12; int greenPin5 = 13; int bluePin5 = 11; //******* red Led (non PWM) ******* int redLed = 24; int time1 = 1000; int time2 = 500; int count = 0; //uncomment this line if using a Common Anode LED #define COMMON_ANODE //******************************************************************************** void setup() { pinMode(redPin1, OUTPUT); pinMode(greenPin1, OUTPUT); pinMode(bluePin1, OUTPUT); pinMode(redPin2, OUTPUT); pinMode(greenPin2, OUTPUT); pinMode(bluePin2, OUTPUT); pinMode(redPin3, OUTPUT); pinMode(greenPin3, OUTPUT); pinMode(bluePin3, OUTPUT); pinMode(redPin4, OUTPUT); pinMode(greenPin4, OUTPUT); pinMode(bluePin4, OUTPUT); pinMode(redPin5, OUTPUT); pinMode(greenPin5, OUTPUT); pinMode(bluePin5, OUTPUT); pinMode(redLed, OUTPUT); Serial.begin(9600); while (!Serial); bd1020.init(tempout_pin); byte rc; while (!Serial); Wire.begin(); rc = bm1383.init(); } //*********************** start loop ************************************** void loop() { //*********************** read barometric oressure ************************ byte rc; float press; rc = bm1383.get_val(&press); if (rc == 0) { Serial.write("BM1383GLV (PRESS) = "); Serial.print(press); Serial.println(" [hPa]"); Serial.println();} //********************** read Temperature ******************************** float temp; bd1020.get_val(&temp); Serial.print("BD1020HFV Temp="); Serial.print(temp); Serial.print(" [degrees Celsius], ADC="); Serial.println(bd1020.temp_adc); Serial.println(count); //********************* set color for RGB Led 1 **************************** // This non PWM digital input, so we only put high (128 - 255) or low (0 -127) if (count == 0) {setColor1(128,128,128); // white delay(time1); setColor1(0, 0, 0); // off digitalWrite(redLed, HIGH); delay(time2); digitalWrite(redLed, LOW);} if (count == 1) {setColor1(255,0,0); // red delay(time1); setColor1(0, 0, 0); // off digitalWrite(redLed, HIGH); delay(time2); digitalWrite(redLed, LOW);} if (count == 2) {setColor1(0,255,0); // green delay(time1); setColor1(0, 0, 0); // off digitalWrite(redLed, HIGH); delay(time2); digitalWrite(redLed, LOW);} if (count == 3) {setColor1(0,0,255); // blue delay(time1); setColor1(0, 0, 0); // off digitalWrite(redLed, HIGH); delay(time2); digitalWrite(redLed, LOW);} count = count + 1; if (count > 3) {count = 0;} //********************* set color for RGB Led 2 and 3 ****************** if (temp > 32.00) // *********** Change temperature ( in degree Celcius) to adapt local temp ****** {setColor2(50, 0, 0);// red delay(time1); setColor2(0, 0, 0); // off digitalWrite(redLed, HIGH); delay(time2); digitalWrite(redLed, LOW);} else if (temp > 30.00) // *********** Change temperature ( in degree Celcius) to adapt local temp ****** {setColor2(50, 25, 0); delay(time1); setColor2(0, 0, 0); // off digitalWrite(redLed, HIGH); delay(time2); digitalWrite(redLed, LOW);} else if (temp > 28.00) // *********** Change temperature ( in degree Celcius) to adapt local temp ****** {setColor2(25, 50, 0); delay(time1); setColor2(0, 0, 0); // off digitalWrite(redLed, HIGH); delay(time2); digitalWrite(redLed, LOW);} else if (temp > 26.00) // *********** Change temperature ( in degree Celcius) to adapt local temp ****** {setColor2(0, 50, 0); // green delay(time1); setColor2(0, 0, 0); // off digitalWrite(redLed, HIGH); delay(time2); digitalWrite(redLed, LOW);} else if (temp> 24.00) // *********** Change temperature ( in degree Celcius) to adapt local temp ****** {setColor2(0, 50, 25); // delay(time1); setColor2(0, 0, 0); // off digitalWrite(redLed, HIGH); delay(time2); digitalWrite(redLed, LOW);} else if (temp > 22.00) // *********** Change temperature ( in degree Celcius) to adapt local temp ****** {setColor2(0, 25, 50); // delay(time1); setColor2(0, 0, 0); // off digitalWrite(redLed, HIGH); delay(time2); digitalWrite(redLed, LOW);} else if(temp <= 22.00) // *********** Change temperature ( in degree Celcius) to adapt local temp ****** {setColor2(0 ,0 ,50); //blue delay(time1); setColor2(0, 0, 0); // off digitalWrite(redLed, HIGH); delay(time2); digitalWrite(redLed, LOW);} //************************* set color for RGB Led 4 and 5 ****************** if (press > 1020.00) {setColor3(50, 0, 0); // red delay(time1); setColor3(0, 0, 0); // off digitalWrite(redLed, HIGH); delay(time2); digitalWrite(redLed, LOW);} else if (press > 1015.00) {setColor3(50, 50, 0); // yellow delay(time1); setColor3(0, 0, 0); // off digitalWrite(redLed, HIGH); delay(time2); digitalWrite(redLed, LOW);} else if (press > 1010.00) {setColor3(0, 50, 0); // green delay(time1); setColor3(0, 0, 0); // off digitalWrite(redLed, HIGH); delay(time2); digitalWrite(redLed, LOW);} else if (press <= 1010.00) {setColor3(0, 0, 50); // blue delay(time1); setColor3(0, 0, 0); // off digitalWrite(redLed, HIGH); delay(time2); digitalWrite(redLed, LOW);} //************************ end of loop ***************************************** } //******************************** RGB Led 1 ********************************************* void setColor1(int red1, int green1, int blue1) { #ifdef COMMON_ANODE red1 = 255 - red1; green1 = 255 - green1; blue1 = 255 - blue1; #endif analogWrite(redPin1, red1); analogWrite(greenPin1, green1); analogWrite(bluePin1, blue1); } //*******************************RGB Led 2 ********************************************** void setColor2(int red2, int green2, int blue2) { #ifdef COMMON_ANODE red2 = 255 - red2; green2 = 255 - green2; blue2 = 255 - blue2; #endif analogWrite(redPin2, red2); analogWrite(greenPin2, green2); analogWrite(bluePin2, blue2); analogWrite(redPin3, red2); analogWrite(greenPin3, green2); analogWrite(bluePin3, blue2); } //***************************** RGB Led 3 ************************************************* void setColor3(int red3, int green3, int blue3) { analogWrite(redPin4, red3); analogWrite(greenPin4, green3); analogWrite(bluePin4, blue3); analogWrite(redPin5, red3); analogWrite(greenPin5, green3); analogWrite(bluePin5, blue3); } //***************************** end of program******************************** |
If all is good, then run the program. The result should be similar to the video above. In the video, we demonstrate how the electronic Christmas tree works. It shows an increase in temperature by using hairdryer will change the color of RGB LED 2 and RGB LED 3 from green into red and when the temperature is back to normal, it changes the color back to green.
I hope you enjoyed this project! Merry Christmas and Happy New Year to you all!
Figure 18. Final Christmas Tree (front view)
Figure 19. Complete Christmas Tree (side view)