Introduction

The Micro:bit board is a compact and powerful educational microcontroller designed to inspire creativity and programming learning in young people. Launched in 2015 by the BBC in the UK as part of the “Make It Digital” initiative, the Micro:bit has quickly become a popular tool worldwide for teaching programming and computer science.

The Micro:bit measures around 4 centimetres by 5 centimetres and is packed with a variety of features, making it an ideal choice for programming beginners.

In this course, we’ll be using the Wet Sen1 humidity sensor. This is connected to pins 1 and 2 of the Micro:Bit board, as well as to its GND:

 

The aim of the project is for the humidity sensor to tell you whether or not you need to water your plant.

This is the program that reads the values from the humidity sensor and tells you if you need to water your plant. If your plant needs water, droplets will appear on the LED panel of the Micro:Bit. When these droplets disappear, the plant is sufficiently watered:

moisture = 0
x = 0
y = 0

def on_forever():
  global moisture
  global x
  global y
  pins.digital_write_pin(DigitalPin.P1, 1)
  basic.pause(10)
  moisture = Math.map(pins.analog_read_pin(AnalogPin.P2), 0, 813, 0, 100)
  pins.digital_write_pin(DigitalPin.P1, 0)
  if moisture < 50:
    x = randint(0, 4)
    y = 0
    for index in range(9):
      led.plot_brightness(x, y, 255)
      led.plot_brightness(x, (y - 1), 32)
      led.plot_brightness(x, (y - 2), 8)
      led.plot_brightness(x, (y - 3), 2)
      led.plot_brightness(x, (y - 4), 0)
      y += 1
      basic.pause(50)
  else:
    basic.pause(1000)
basic.forever(on_forever)

You can now simulate the circuit on Tinkercad. You can change the humidity by clicking on the humidity sensor and dragging on more or less water: