Temperature Controlled Night Light with Puck.js

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.

You'll need

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

This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.