WiFi Module with micro:bit

Written By: Cherie Tan

Dash icon
Difficulty
Easy
Steps icon
Steps
16
The Internet of Things or IoT for short, is a network of physical devices connected to the internet. By creating a network of devices, such as sensors or other physical devices embedded with computing systems, all these devices are connected and can exchange data seamlessly. Learn to add WiFi capability to your micro:bit with an ESP8266 WiFi module, and create your own IoT system. Complete this guide to send data such as the micro:bit's light level and temperature readings over the internet using Thingspeak!

Step 1 The WiFi Module

This is the WiFi module, it has 6 pins and they are labelled as such: 
  • 1. Ground 
  • 2. TX
  •  3. GPIO 2
  • 4. CH_EN
  • 5. GPIO 0
  •  6. Reset
  •  7. VCC (+3.3V)
  •  8. RX. 
We'll be using four of these pins today to connect the micro:bit to the Wifi module!

Step 2 Connect 3V3 to 3.3V

Connect a red jumper wire from 3V3 on the Wifi Module to the breadboard as shown. It should be connected to the + power rail on the breadboard. This will later be connected to 3.3V on the micro:bit.

Step 3 Connect EN to + Power Rail

Next, connect EN on the WiFi Module to the + power rail on the breadboard

Step 4 Connect TX to P1

Connect TX on the module to B4 on the breadboard, so it should be connected to P1 on the micro:bit

Step 5 Connect RX to P0

Connect RX of the WiFi Module to P0 of the micro:bit

Step 6 Connect GND to GND

Connect GND on the WiFi module to GND on the micro:bit

Step 7 Connect + Power Rail to 3.3V

Finally, remember to connect a red jumper wire from the + power rail to 3.3V on the micro:bit

Step 8 Create a ThingSpeak account

Go to ThingSpeak's website and sign up for an account: https://thingspeak.com/

Step 9 Create a New Channel from Thingspeak Dashboad

Click on the Channels button up the top where the navigation bar is. Next, click on New Channel button to create a new channel for the micro:bit Set up the settings for the channel, name field 1 : Light level Next name field 2: Temperature Remember to finalise changes by clicking the Save changes button down below

Step 10 Find the Write API Key

Now click on API Keys tab to find your newly created channel's Write API Key, copy this.

Step 11 Add the ThingSpeak MakeCode Extension

Go over to MakeCode editor: https://makecode.microbit.org/#editor Click on Advanced > Extensions Search for thingspeak in the search field. Then click on ESP8266_ThingSpeak to add it to the editor.

Step 12 Add an Initialise Esp8266 block

Click on ESP8266 ThingSpeak tab, and look for the initialize esp8266 block. Drag and drop this block into on start.

Step 13 Add an Upload Data to ThingSpeak block

Drag and drop an upload data to Thingspeak block into the forever block. From the Input tab, drag and drop a light level block into Field 1. Drag and drop a temperature block into Field 2. Finally, remember to paste the Write API Key you got in your channel into Write API Key. Also make sure to add your WiFi network's SSID and password details into the Wifi SSID and WiFi PW fields accordingly.

Step 14 Add a Serial on data received new line block

Finally, click on Serial tab and drag and drop a serial on data received new line block. From Basic tab, drag and drop a show string block into the serial on data received block. Now add a serial read string block into show string. You can find this in the Serial tab.

Step 15 Connect battery pack to micro:bit

To make this project portable, connect the battery pack to the micro:bit so that it can run without being connected to your computer.

Step 16 Upload the Code to Micro:bit and View Channel

With your micro:bit connected via USB to your computer, click the Download button in the editor to get the hex file. Then drag and drop this into the MICROBIT drive. Go over to ThingSpeak dashboard, and click on Channels and navigate to your newly created channel. The data should now be showing up and updating in Private View. The channel stats should show the micro:bit's light level and temperature data! Congratulations, you have now successfully connected your micro:bit to the internet!