9. Case 07: Crops Height Detection#

9.1. Introduction#

  • The height of the crops is an important factor in determining crop yield. Deducing plants height could increase plants fertilizer tolerance and lodging resistance, and increase harvest index and final yield. This also fully shows that plants height is an important selection indicator in the breeding process.

9.2. Function#

  • Detect if the height of the crops is exceeding the standard with the sonar:bit.

9.4. Picture#


9.5. Hardware Connection#

Connect the sonar:bit to P1 and the OLED display to IIC on IoT:bit.


9.6. Software Programming#

Click “Advanced” in the MakeCode to see more choices.


For programming, we need to add a package: click “Extensions” at the bottom of the MakeCode drawer and search with “iot-environment-kit” in the dialogue box to download it.


Notice: If you met a tip indicating that some codebases would be deleted due to incompatibility, you may continue as the tips say or create a new project in the menu.

9.7. Program#

Initialize the OLED display as 128×64.


Set the ultrasonic sound sensor to connect to P1 with unit in cm, save the returned value as the variable “ultrasonic_distance”.


Clear the OLED display and display the value from the ultrasonic sound sensor.


Judge if the returned value is in the scope of the threshold, if yes, it means the height of the plants is over the standards, prgram to display “x”; or program to display “√”.


Link: https://makecode.microbit.org/_4rfVpw74kVdW

9.8. Result#

  • Detect if the height of the plants is over the threshold with the sonar:bit.