IoT Projects | Kuriosity
Thyme to Grow!

Difficulty Level: 3/3

Time Required: 15 Mins

Simulate a live monitoring system for plants. Use the micro:bit to set environment light and temperature levels, and program Button 'A' and 'B' to adjust them. Track and graphically display the data on IoT cloud platform, ThingSpeak.

Hardware Required:

  • micro:bit x 1

  • micro-USB cable x 1

  • micro:IO-Extender Expansion Board x1 

  • OBLOQ IoT Module x1

Hardware Set-Up

1) Slot the micro:bit into the into the expansion board

2) Connect the IoT module to the expansion board by connecting the following pins:

OBLOQ IoT Module > Expansion Board

Green Wire > Pin 1 (Green)

Blue Wire > Pin 2 (Green)

Red Wire > Pin 1 (Red)

Black Wire > Pin 1 (Black)

ThingSpeak Set-Up

1) Open a new browser tab and go to  https://thingspeak.com. Sign in (or sign up for free if you do not have an account). 

2) On the home page, select "Channels" from the top menu to be taken to the "My Channels" page.

3) Click "New Channel"

4) You will be taken to this form. Under "Name", type in "Demo".

5) Tick the first 3 "Field" checkboxes. Under "Field 1", type in "Temperature". Under "Field 2", type in "Light". Leave "Field 3" as is.

6) Scroll down and click "Save Channel".

7) You will be taken to the "Demo" Channel dashboard. The data collected from your project will be charted here.

8) Click "API Keys".

9) You will find your "Write API Key". Save this information for later!

Coding Steps

1) In your new MakeCode project, select “HTTP_MQTT” from the code drawer. Drag “Setup wifi” to the “On Start” block to run the IoT Module. 

2) Enter your personal Wi-Fi credentials under “name” and “password”. Note: SSID and password are case sensitive.

3) Select “Variables” and click “Make a Variable...”. Name the variable “Temperature”.

4) Select “Variables” again and click “Make a Variable...”. Name the variable “Light”.

5) Select “Variables” again and drag "set variable to" below the "Setup wifi" block. Type in "10" to replace “0”. Click the drop-down menu and select "Temperature".

6) Repeat step 5, but change the drop-down menu value to "Light".

7) Select “Input”. Drag “on button A pressed” into a blank area in the workspace. Delete the “forever” block if there is an existing one as we will not be using it.

8) Let's send data over to ThingSpeak. Select "Basic". Drag "show string" to the "on button A pressed" block.

9) Select "HTTP_MQTT". Drag "ThingSpeak(Get)" to replace "Hello!" in the "show string" block.

10) Remember your "Write API Key" from ThingSpeak Set-Up Step 9?  Key it in under "write key".

11) We can only send text to the cloud for now but our sensor readings are in numbers. We will need to convert them to text. Select “Text”. Drag “convert to text” twice, under the “value 1” and "value 2" fields. 

12) Select "Variables". Drag "Temperature" into the "value 1 > convert to text” field. 

13) Select "Variables". Drag "Light" into the "value 2 > convert to text” field. 

14) Leave "value 3" empty for now.

15) Select “Variables” again and drag "change variable by" below the "show string" block. Type in "5" to replace “0”. Click the drop-down menu and select "Temperature". This will increase the temperature value by 5, every time the button 'A' is pressed.

16) Repeat step 5, but change the drop-down menu value to "Light". Type in "10" to replace “0”. This will increase the light value by 10, every time the button 'A' is pressed.

17) Since button 'A' is programmed to increase the temperature and light values, let's use button 'B' to decrease them. Right-click the "on button A pressed" block and select "duplicate"

18) In the duplicated block, click the "button" drop-down menu and change "A" to "B".

19) In the "change Temperature by" block, type in "-5" to replace “5”. This will decrease the temperature value by 5, every time the button 'B' is pressed.

20) In the "change Light by" block, type in "-10" to replace “10”. This will decrease the light value by 10, every time the button 'B' is pressed.

Run The Program

1) Download the .hex file and transfer it to the micro:bit drive.

2) Turn the micro:bit on.

3) Press button ‘A’ and button 'B'. Go to the ThingSpeak dashboard to check if the data charts.

Great Work!

You've simulated a live temperature and light level monitoring system! Real time data can be fed to and charted in the ThingSpeak IoT cloud platform. This allows us to monitor the data and make decisions accordingly - in this case, we can decide whether to increase or decrease the temperature and light levels. What other uses can you think of for the ThingSpeak platform?

©2020 by kuriosity.sg