Temperature Controlled Night Light With Puck.js

Made by Espruino

About the project

If you've got a baby you're supposed to keep room temperature between 16 and 20 degrees Celsius - but how do you know at night? Here, we'll make a night light that changes color depending on the temperature.

Project info

Difficulty:

Categories:

Home Automation
Lights
Sensors
Weather

Platforms:

Espruino

Estimated time:

3 hours

Published:

17th April 2018

Items used in this project


Hardware components

Puck.js

http://www.espruino.com/Puck.js

x 1
IR controlled RGB Light bulb

http://rover.ebay.com/rover/1/711-53200-19255-0/1?icep_id=114&ipn=icep&toolid=20004&campid=5337979701&mpre=http%3A%2F%2Fwww.ebay.com%2Fsch%2Fi.html%3F_nkw%3Drgb%2Bled%2Blight%2Bir%2Bremote%2Bcontrol%26_sacat%3D0

x 1
Infrared Receiver x 1

Story



Software

First, you need to get the Infrared codes for your light bulb - you can just follow the instructions here for that.

Then, the code to use is simply:


  1. var light = {
  2. normal : [8.9,4.5,0.5,0.5,0.6,0.5,0.6,0.5,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,1.7,0.5,1.7,0.5,1.7,0.6,1.8,0.4,1.7,0.5,1.7,0.5,1.7,0.5,1.7,0.5,1.7,0.5,0.6,0.5,1.7,0.5,1.7,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,1.7,0.5,0.6,0.5,0.6,0.5,1.7,0.5,1.7,0.5,1.7,0.5,1.7,0.5,39.9,8.9,2.2,0.5],
  3. hot : [8.9,4.5,0.5,0.6,0.5,0.5,0.6,0.5,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,1.7,0.5,1.7,0.5,1.7,0.5,1.7,0.5,1.7,0.5,1.7,0.5,1.7,0.5,1.7,0.5,1.7,0.5,0.6,0.5,0.6,0.5,1.7,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,1.7,0.5,1.7,0.5,0.6,0.5,1.7,0.5,1.7,0.6,1.7,0.5,1.7,0.5,39.9,8.9,2.3,0.5],
  4. cold : [8.9,4.5,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.5,0.6,1.7,0.5,1.7,0.5,1.7,0.6,1.8,0.5,1.7,0.5,1.7,0.5,1.7,0.5,1.7,0.5,0.6,0.5,1.7,0.6,1.7,0.5,1.7,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,1.7,0.5,0.5,0.6,0.5,0.5,0.6,0.5,1.7,0.5,1.7,0.5,1.7,0.5,1.7,0.5,39.9,8.9,2.3,0.5]
  5. };
  6. var offset = 20.2 - 17.75;
  7.  
  8. function tempTest() {
  9. var temp = E.getTemperature()+offset;
  10. print("Temperature:"+temp);
  11. if (temp < 16)
  12. Puck.IR(light.cold);
  13. else if (temp <= 20)
  14. Puck.IR(light.normal);
  15. else
  16. Puck.IR(light.hot);
  17. }
  18.  
  19. setInterval(tempTest, 30*1000);

Once uploaded, it will run until the battery runs down or is removed. If you want to save everything so it runs even after a battery removal, simply type save() on the left-hand side.

Notes

  • Puck.light() can be used to get a rough idea of ambient light - to turn off the night light in the day time.
  • Since Puck.js has Bluetooth, you could use a Bluetooth LE light bulb as well. They're often harder to reverse-engineer though!
  • Puck.js has RGB lights on board so you could use those for the night light, but I didn't because:
    • The battery would run down pretty quickly (a day or two) with the LEDs on all night
    • The act of powering the LEDs will raise the die temperature of Puck.js, messing up the temperature reading. It's another reason to only measure the temperature every few seconds rather than all the time.



Code


Source code

Credits


Espruino

Espruino is a JavaScript Interpreter for Microcontrollers that is designed to make development quick and easy. The Espruino interpreter is firmware that runs on a variety of different microcontrollers, but we also make Espruino Boards that come with the interpreter pre-installed and are the easiest devices to get started with. However Espruino itself isn't just the interpreter firmware or hardware - there's also the Web IDE, command-line tools, documentation, tutorials, and modules which form a complete solution for embedded software development.


Leave your feedback...