Temperature Controlled Night Light With Puck.js
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: Easy
Platforms: Espruino
Estimated time: 3 hours
License: Apache License 2.0 (Apache-2.0)
Items used in this project
Hardware components
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:
- var light = {
- 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],
- 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],
- 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]
- };
- var offset = 20.2 - 17.75;
- function tempTest() {
- var temp = E.getTemperature()+offset;
- print("Temperature:"+temp);
- if (temp < 16)
- Puck.IR(light.cold);
- else if (temp <= 20)
- Puck.IR(light.normal);
- else
- Puck.IR(light.hot);
- }
- 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
Credits
Espruino
Espruino, Espruino Pico and Puck.js are low-power Microcontrollers that run JavaScript. 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 that form a complete solution for embedded software development.
Leave your feedback...