← Back to list

Creating a light alarm clock with the MXChip

Wake up naturally with the help of some DIY tech!

Joseph Pitts · 2021-04-13 20:47 · 0 claps · 2.8 min read
#diy #mxchip #iot #code
Open on Medium ↗
Wiki topics: 📟 · Gadgets & IoT 🛠️ · Crafts & DIY

Creating a light alarm clock with the MXChip

Wake up naturally with the help of some DIY tech!

Introduction

This project uses a WS2812B LED strip controlled by an MXChip, if you want to see how this is done read this blog post first.

Now I don’t know about you but I hate waking up to a blaring alarm, it’s definitely not the way I want to be starting the day. A light alarm clock tries to remedy this by waking you up gradually with light, rather then all at once with sound. And now that we have the MXChip set up and controlling the LED strip it seemed like the perfect project (especially now i’m back to University and 9ams)!

First Step: Remote control

The first step to this project is developing a way to control the colour and brightness of the LED strip without having to re-flash the MXChip every time. I found the solution in Jim Bennets great blog post about controlling an IoT device from your phone. He writes about using devices twins to set an RGB and brightness value on the cloud and then writing a small amount of code on the MXChip to pull that information and set the LED colours accordingly.

This code is only a snippet of what's needed. The full code will be available to downloaded at the end.

[embed]

HTTP Endpoint

Now while technically we can remotely change the colour of the lights we have to do so by updating a JSON file manually. Thankfully we can automate this with a little bit of Node.js and the azure-iothub package.

[embed]

Now we can update the lights by typing the colours into a JavaScript file! Ok ok so not much of an improvement but thats where the cloud comes in, by using Azures serverless solution we can expose this JavaScript to a HTTP endpoint and update the LEDs by making a request and including the RGB and brightness values as URL parameters.

Azure makes creating a serverless function a breeze, it’s as easy as creating a new Function App resource, assigning it to a resource group and choosing what runtime stack you want (.NET, Python, Java, e.t.c) in this case we want Node.js.

Now we have a Function app we only have to make a few small changes to our code. First we need to change the hardcoded RGB values to the data thats being passed in with the HTML requests, this can be done like so parseInt(req.query.r) for each of the values. Secondly we need to export the function by simply wrapping it in module.exports async function (context, req) {}

When all is done you will have a URL like this example.azurewebsites.net/api/example?r=255&g=100&b=0&d=false&br=1 and by changing the RGB values in the URL you should be able to update the physical LED strip!

The alarm clock

Now we can change the LEDs colour (and more importantly for this application brightness) we need to trigger the lights to come on and gradually increase in brightness to wake us up. This can be achieved with an Azure Logic App. Logic Apps have a trigger and then work through a series of steps and trigger APIs. For this project we will be using a time trigger and setting the logic app to run every day at 6:50. From there we will make a HTTP request to the endpoint we just made to turn the lights on with a brightness of 1%. From there we can string together a delay and another HTTP call gradually increasing the brightness of the lights!

The Azure logic app.

The Azure logic app.

Conclusion

Overall we have created an Azure function and exposed it to a HTTP endpoint to change the colour and brightness of the LED strip and a logic app to send requests to this endpoint periodicity to gradually increase the brightness, and let me tell you it works great!

Originally published at https://joepitts.co.uk.


메타데이터
post_id
c0823f818e8b
slug
creating-a-light-alarm-clock-with-the-mxchip-c0823f818e8b
url
https://medium.com/@joepittsy/creating-a-light-alarm-clock-with-the-mxchip-c0823f818e8b
canonical_url
https://medium.com/@joepittsy/creating-a-light-alarm-clock-with-the-mxchip-c0823f818e8b
author_url
https://medium.com/@joepittsy
status
ok
fetched_at
2026-07-28 09:32:43