Microbit to ThingSpeak

Upload data collected from micro:bit's in-built sensors to ThingSpeak


YOU WILL NEED

  • 1 x BBC micro:bit
  • 1 x Elecfreaks IoT:bit for micro:bit
  • 1 x micro USB cable
  • ThingSpeak account

Looking for parts to make this?


STEP 1

Connect the components
(a) Slot a micro:bit into the IoT:bit

(b) Toggle the IoT:bit's switch to 'on'




Materials

  • 1 x BBC micro:bit
  • 1 x Elecfreaks IoT:Bit
  • 1 x micro USB cable


STEP 2

Setting up ThingSpeak account
(a) Create a new channel

(b) Fill up the channel's name, description, and field(s). In this tutorial, we are going to collect data from one sensor, so we only need to fill in one field.

(c) Save channel
(d) Navigate to API Keys tab and take note of the API Keys



STEP 3

Importing Extension
To connect to ThingSpeak on makecode, we need to import a special package in MakeCode.

(a) Click on the ‘Advanced’ drawer, select 'Extensions'.

(b) Search ‘iot-environment-kit’ and click on it to import.

(c) You’ll need to re-import the extension again for new projects in the future.



STEP 4

Initialize WiFi module
(a) First off, we need to initialize the WiFi module (on the IoT:bit breakout board).
(b) From the ESP8266_IoT drawer, drag the following two blocks into an OnStart block. Make sure that you change the SSID field to your own WiFi network name and it's password



STEP 5

Upload data to ThingSpeak
In this step, we are going to continually upload data to ThingSpeak every 2 seconds.
(a) From the ESP8266_IoT drawer, drag out the following blocks
• Connect ThingSpeak
• Set data to send ThingSpeak (change the write API key to your own)
• Upload data to ThingSpeak
(b) Lastly, drag an pause (ms) block so that we will only upload data every 2 seconds.



STEP 6

View data on ThingSpeak
Once you’ve downloaded your code to the micro:bit, you can view
your data on ThingSpeak! Under the Private View tab, ThingSpeak
automatically creates simple visualisations for your data.


Code and References

Made this activity? Good Job! Now spread the word. Share a photo of your creation on social media with #letsgethacking #MicrobittoThingSpeak