Example Code for micro:bit-Plant Incubator

To create a plant growth monitoring system, gather sensors for soil and air humidity, temperature, a buzzer, LED, micro:bit, and BOSON board. Use Mind+ or MakeCode to program. Set an 'environmental indicator' variable, measuring conditions; if unsuitable, the LED lights up and the buzzer sounds. It's like having a digital gardener watching over your plants.

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