Night Light

Here we're making a simple Night Light that turns on when it gets dark, and off when it's light.

On the 2400mAh battery used it should last around 4 months assuming the LED is on for 4 hours a day.

You might also want to check out the Puck.js Night Light which glows a colour to show you the temperature.

You'll need




var light = 0, on = false;

setInterval(function() {
  light = analogRead(LED2);
  if (light < 0.16) on = true;
  if (light > 0.18) on = false;
}, 2000);

// Only use this code if you want to make the light
// invisible on Bluetooth until the button is pressed
setWatch(function() {
}, BTN1);

Just upload the code above to flash the MDBT42Q. Once uploaded it'll disconnect from Bluetooth and will be a usable night light.

However, you'll probably want to tweak the numbers for when the LED turns on and off. Simply do this by removing the last bit of code, then while connected type light into the Web IDE's console to find out what the light value is at different brightness levels.


As noted in the video, the usage of hysteresis can help to stop the light from flickering on and off, however there are some other additions that can really help.

3D Printed Case

The case was designed with OpenSCAD - it is simply a hollow cylinder:

difference() {
  translate([0,0,-1.5]) cylinder(r=36/2,h=60);

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