Skip to content

Week 13: IoT. Administration of IoT in schools.

Assignments

  • Connect your microcontroller board with other device
  • Reflection questions

Smart Farm with Micro:bit and IoT

For this week’s assignment I am working on a previous project I built a year ago. I purchased a Smart Agriculture Kit to be used with the micro:bit and I integrated it with a LEGO farm.

Previously, I managed to make all the sensors work and display data on a small OLED display. I also included a small water pump that is activated when the soil moisture goes below a certain value.

The kit includes an IoT expansion board which uses an ESP8266 for Wi-Fi and serial communication with the micro:bit. It also extends the available I/O ports of the micro:bit using GVS (ground, voltage, signal) pins. The IoT:bit also includes a buzzer and an onboard RTC clock with its own power supply.

  • photo
  • photo

My aim is to refine the code (using the MakeCode platform), as I think I have too many operations running in parallel and that is affecting the correct functioning of some sensors, such as the PIR and distance sensors, which are not very reliable.

I also want to make the most of the IoT expansion board and connect to a platform that receives the sensor data so it can be visualised in graphs.

Improving the code

Here I show how I used the pins to connect the sensors:

  • P14: DHT11 (temperature + humidity)
  • P2: Soil moisture (0–100)
  • P3: Water level (0–100)
  • P16: DS18B20 (water temperature)
  • P13: Ultrasonic (Sonar:bit distance)
  • P10: PIR digital read
  • P15: NeoPixel
  • P9: Relay / pump control

sample photo

Before, I had three “forever” loops and now I have only one, with the rest of the loops working as “Every x ms”. For example, the reading and displaying of sensors runs every 3000 ms. I also included variables such as pumpStart and pumpRunning, and used running time (ms) to make the pump work in bursts of 2 seconds rather than working continuously.

sample photo

IoT

To send the data via Wi-Fi to a platform I am using ELECFREAKS Smart IoT, which focuses on STEAM education, collecting and visualising real-time sensor data.

In MakeCode it is necessary to add the Environment and Science IoT extension, which adds the menus to control the ESP8266_IoT menu, the OLED display, the sensor readings, and the RTC1307 clock.

To be able to upload the sensor readings to the Smart IoT platform it is necessary to connect the board to the internet using the SSID and key of the local Wi-Fi. After creating an account in Smart IoT you get a user token (a code). Then you create a device or project (in my case “Smart_Farm”) which is assigned a topic (number). With this information you can connect the micro:bit + the IoT board to the Smart IoT server.

sample photo

The data visualisation consists of a line chart that gets updated every time that new data is uploaded by the micro:bit. There are other graphs you can add such as gauges, pie charts, and numeric displays. For my project I created gauges for each uploaded sensor value: ambient temperature, ambient humidity, soil moisture, water tank level, and water temperature.

sample photo sample photo

The photo shows the electronics and sensor integration to make the smart farm. sample photo

This includes a greenhouse alarm that uses the PIR and distance sensors to detect intruders. If activated, the green LED turns red. There is also a weather station that monitors ambient temperature and relative humidity. The smart farm includes automatic irrigation. The soil moisture sensor sends readings to the microcontroller and the pump starts automatically if the value is less than the threshold. You can also monitor the water level and temperature in the water tank and display its status on the OLED screen and in the Smart IoT interface.

The video shows how the Smart IoT platform receives data from the sensors.

Reflection

  • What are some opportunities in your context to work within your local community? Who you could collaborate with? How? What should happen to succeed in the collaboration?

  • What are the next steps in development further a makerspace in your school? How do you envision the maker space?

  • What is the potential of physical computing and IoT for your teaching? Do you have any ideas on how you are planning to integrate those techniques in your context?

Tools