15. Case 13:The Smart Farm#

../../_images/microbit-Smart-Agriculture-Kit-13-01.png

15.1. Introduction#


To build a smart farm with the Smart Agriculture Kit and the Carton models.

15.2. Functions#


15.3. Materials Required#


Smart Agriculture Kit

Link: https://shop.elecfreaks.com/products/elecfreaks-micro-bit-smart-agriculture-kit-without-micro-bit-board?_pos=2&_sid=2c86b7764&_ss=r

../../_images/microbit-Smart-Agriculture-Kit-case-01-02.png

Smart Agricultural Carton Model

../../_images/microbit-Smart-Agriculture-Kit-13-02.png

Double-sided tapes: Fix the sensors and the postion of the models.

15.4. Assembly#


Step 1: Take out the cardboards and splice the baseboard.

../../_images/microbit-Smart-Agriculture-Kit-13-03.png

Step 2: Fold the cardboards with the crease and fasten the buckles.

../../_images/microbit-Smart-Agriculture-Kit-13-04.png

Finished models after the assembly:

1.The baseboard

../../_images/microbit-Smart-Agriculture-Kit-13-05.png

2.The fish pond

../../_images/microbit-Smart-Agriculture-Kit-13-06.png

3.The cabbin

../../_images/microbit-Smart-Agriculture-Kit-13-07.png

4.The fence

../../_images/microbit-Smart-Agriculture-Kit-13-08.png

5.SThe plant

../../_images/microbit-Smart-Agriculture-Kit-13-09.png

Step 3: Put the models on the baseboard

../../_images/microbit-Smart-Agriculture-Kit-13-10.png

Tip: Please can glue the models with the double-sided tapes.

15.5. Hardware Connections#


Connect the soil moisture sensor to P1 on IoT:bit; the 180 degrees servo to P2; the DHT 11 to P3; the rainbow LED to P4; the water level sensor to P10; the DS18B20 sensor to P13; the infrared sensor to P14; the sonar:bi to P15; and the OLED display to IIC on Iot:bit.

../../_images/microbit-Smart-Agriculture-Kit-13-11.png

15.6. Add Extensions#


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

../../_images/microbit-Smart-Agriculture-Kit-case-01-04.png

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

../../_images/microbit-Smart-Agriculture-Kit-case-01-06.png

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

../../_images/microbit-Smart-Agriculture-Kit-case-03-06.png

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.

../../_images/microbit-Smart-Agriculture-Kit-case-01-05.png

15.7. Programming#


Initialize the OLED screen and disable the LED functions on the micro:bit, initialize the rainbow LED.

../../_images/microbit-Smart-Agriculture-Kit-13-12.png

Get the values from all sensors and display them on the OLED screen.

../../_images/microbit-Smart-Agriculture-Kit-13-13.png

If the returned value from the soil moisture is below the threshold, make the servo rotate to 0 degree to simulate the opening of the water valve; or make it rotate to 180 degrees to simulate the closing of the water valve.

../../_images/microbit-Smart-Agriculture-Kit-13-14.png

If there is any obstables detected among 4~400cm by the sonar:bit, detect if there is any movement with the infrared sensor, if yes, program to light on the red light or program to light on in green.

../../_images/microbit-Smart-Agriculture-Kit-13-15.png

Code:

../../_images/microbit-Smart-Agriculture-Kit-13-16.png

Reference link: https://makecode.microbit.org/_eYRf5hcaDEeR

15.8. Result#


The values of the soil moisture, the temperature and humidity of the farmland, the water level and the water temperature shall be displayed on the OLED screen. If the value of the soil moisture is below the threshold, the device would turn on the water valve for irrigating; or it’s in the close status to save water. If there is any one getting closer, the rainbow LED lights on in red for warning; or it light on in green.

Tip: As the models are made of paper, please prepare with water-proofs solutions if your project needs water. For example: we can put a plastix box inside of the fish ponds for protection.