Example Code for micro:bit-Plant Incubator

The article offers example code and setup instructions for a micro:bit-powered plant incubator, utilizing sensors to monitor soil humidity, air humidity, and temperature. It provides detailed hardware and software preparations, wiring diagrams, and sample programs using Mind+ and MakeCode. The system alerts users when environmental conditions are unsuitable for plant growth, ensuring optimal cultivation.

Hardware Preparation

  • soil humidity sensor
  • air humidity sensor
  • temperature sensor
  • buzzer module
  • LED module
  • micro:bit
  • BOSON expansion board

Software Preparation

  • Mind+
  • MakeCode

Wiring Diagram

Other Preparation Work

Init the variable: set the variable "environmental indicator" to 0;
Measure the soil humidity: if the soil humidity is less than 200 or more than 800, set the "environmental indicator" to 1;
Measure the temperature: call the function to get the temperature, if it is less than 10 or over 40, set the "environmental indicator" to 1;
Measure the air humidity: if the air humidity is less than 60%, set the "environmental indicator" to 1;
Determine if the environment is appropriate for plant:if the environment indicator is 1, the current environment is not suitable for plant growth, the LED lights up and the buzzer starts making sound for 5s; otherwise, do nothing.

Sample Code

Mind+ Example Program:

MackCode Example Program:

Result

If there is one parameter exceeding the preset range, the LED lights up and the buzzer starts making sound for 5s; otherwise, do nothing.

Was this article helpful?

TOP