This project teaches you the basics of using a WebThings Gateway and MicroBlocks to program a remote switch for home automation using two micro:bits. Your WebThings Gateway will control some garden lights, based on predefined rules. You’ll also learn how to turn a micro:bit into a radio transmitter/receiver pair that will allow you to radio-control things around the house.
You’ll need to have your WebThings Gateway kit up and running, you can learn here how to do it.
Once you’ve finished setting it up, log into your WebThings Gateway.
Once this is done you should have the LED Display menu added to your MicroBlocks.
MicroBlocks works by assembling “blocks” together. There are different kinds of blocks which are categorised and colour-coded. To test that your micro:bit and MicroBlocks are working, assemble the following blocks and then press the green arrow. Your micro:bit should display the smiley if everything is working.
While your micro:bit is connected, MicroBlocks constantly updates the code running on the micro:bit as you edit it in MicroBlocks.
Now everything is working, you can start a new project and install some additional libraries for WebThings and Radio functions.
The micro:bit Transmitter will connect to the WebThings Gateway kit and communicate wirelessly with the remote micro:bit switching the garden lights, but before that can happen it needs programming with MicroBlocks.
If you need to reconnect your micro:bit to MicroBlocks, click the USB icon and choose Connect – the USB icon has a green background when the micro:bit is connected.
The Remote micro:bit will be connected to a relay and will receive commands from the micro:bit Transmitter via radio. To do this we need to program a receiver using MicroBlocks.
Assemble the circuit as shown below. You can use a small breadboard, solder the connections, or use crocodile leads.
Ensure you are working on the 12V side of the PSU.
The micro:bit transmitter needs to be configured within the WebThings gateway so it can be controlled from a browser or mobile device.
Now you can turn the lights on and off from this page and the remote switch should turn on and off accordingly.
Now let’s add some rules to turn the lights on and off automatically.
Make sure you enable the rule using the button in the description block of each rule.
Now your lights will turn on and off automatically with the timer as well.
WebThings is a powerful and easy to use gateway which can connect to lots of different devices on your own home network. Using the MicroBlocks adapter for WebThings it’s possible to create your own micro:bit “things” which can be controlled using a browser, phone or tablet.
This project showed how to create a radio transmitter / receiver pair using micro:bits to control a remote relay switch, opening up all kinds of possibilities for connecting things around the home and controlling them through WebThings.
Please select an option to see content specific to your location and shop online.