IKEA makes pretty ghost-shaped night lights, but the power cable of these "SPÖKA" is very thin. One children has torn this cable and called Yoctopuce for help. At first, we thought that we would simply fix the power cable but, in the end, we decided to improve this night light by transforming it into a "connected night light" with a Yocto-Color-V2 and a YoctoHub-Wireless-SR.
The aim was to configure the night light color from a smart phone and to add a "wake up" function to the night light so that it changes color depending on the time of day. The interest of this "wake up" function is to allow children who cannot yet tell the time to know whether they must stay in bed or whether they can go wake their parents up.
For this DIY, we need Yocto-Color-V2 and a YoctoHub-Wireless-SR. The Yocto-Color-V2 enables us to illuminate the inside of the night light in any color and the YoctoHub-Wireless-SR is used to connect the night light to the wifi network. In the opposite to the basic version, this "IoT" night light won't have a battery and is designed to work only when connected to a phone charger.
To have a "punchy" enough night light, we used a NeoPixel 12 led ring instead of the two leds included in the Yocto-Color-V2. This ring is available on the Adafruit web site for less than $8. In the end, the two leds from the Yocto-Color-V2 would have been quite enough.
The hardware
The first step is to cleanly disassemble the night light to recover the flexible part shaped like a ghost. You must simply stretch the flexible part and extract the transparent plastic containing the electronics.
The disassembled SPÖKA night light
The YoctoHub is unfortunately to large to be hidden inside the night light. So we created a base containing the two Yoctopuce modules, on which we fixed the ghost. Inside the base, the Yocto-Color-V2 and the YoctoHub-Wireless-SR are connected with Board2Board-127 and some Fix-2.5mm, to take as little room as possible.
A cylinder with two lips is assembled at the top of the base to fix the ghost. Finally, the led ring is glued on the top of the cylinder to light the ghost from the inside.
The exploded view of the base of the night light
The base is printed in 3D and assembled with 8 3mm countersunk screws. We published the base 3D model on Thingiverse.
The SPÖKA night light, modified by Yoctopuce
The software
We wrote the application in PHP and hosted it on a local server (in the present case a NAS QNAP). The application is made of a web interface allowing the user to configure the night and wake up hours, as well as the colors and animations that the night light must perform. The configuration is saved directly in a JSON file instead of using a data base.
The web interface allows you to configure distinct animations for day and night
The other part of the web application is the HTTP callback that the YoctoHub-Wireless-SR is using. The HTTP callback parses the configuration file and applies the planned color and/or animation to the YColorLedCluster object. The code is rather simple, and using the YColorLedCluster object has been already explained in a previous post ;
* @param YColorLedCluster $ledCluster
* @param object $allconfigs
* @param object $currentConfig
*/
function applyPattern($ledCluster, $allconfigs, $currentConfig)
{
$nbled = $ledCluster->get_activeLedCount();
$speed = (int)$currentConfig->speed;
$color1 = hexdec($currentConfig->color1);
$color2 = hexdec($currentConfig->color2);
$pattern = $currentConfig->pattern;
if (($speed == (int)$allconfigs->last_color->speed) &&
$pattern == $allconfigs->last_color->pattern &&
$color1 == hexdec($allconfigs->last_color->color1) &&
$color2 == hexdec($allconfigs->last_color->color2)
) {
// no change
return false;
}
switch ($pattern) {
case 'off':
$ledCluster->set_rgbColor(0, $nbled, 0);
break;
case 'static':
$ledCluster->set_rgbColor(0, $nbled, $color1);
break;
case 'fade':
$ledCluster->resetBlinkSeq(0);
$ledCluster->addRgbMoveToBlinkSeq(0, $color1, $speed);
$ledCluster->addRgbMoveToBlinkSeq(0, $color2, $speed);
$ledCluster->linkLedToBlinkSeq(0, $nbled, 0, 0);
$ledCluster->startBlinkSeq(0);
break;
case'blink':
$ledCluster->resetBlinkSeq(0);
$ledCluster->addRgbMoveToBlinkSeq(0, $color1, 0);
$ledCluster->addRgbMoveToBlinkSeq(0, $color1, $speed);
$ledCluster->addRgbMoveToBlinkSeq(0, $color2, 0);
$ledCluster->addRgbMoveToBlinkSeq(0, $color2, $speed);
$ledCluster->linkLedToBlinkSeq(0, $nbled, 0, $nbled);
$ledCluster->startBlinkSeq(0);
break;
}
$allconfigs->last_color = $currentConfig;
return true;
}
Finally, we must configure the wifi network and the HTTP callback URL on the YoctoHub-Wireless-SR.
As usual, the complete source code is available on GitHub: https://github.com/yoctopuce-examples/spoka
Demo
The Yocto-Color-V2 allows you to easily transform any lighting into a connected lamp.
Now, let's just hope that the children go back to sleep :-)