7. Case 06: Insect-catching Device

7.1. Introduction


  • In agricultural planting, insect pests affect the yield and the quality of crops. Pests are active at night, gnawing, laying eggs and breeding crops are also carried out at night. Thus, we can make use of the phototaxis of pests to make an automatic insect-catching device that attracts and catches them.

7.2. Function


  • Attract the pests through the LED and drive the servo to catch them.

7.4. Picture


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

7.5. Hardware Connection


Connect the Rainbow LED to P1 and the servo to P2 on IoT:bit.

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

7.6. Software Programming


Click “Advanced” in the MakeCode 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 “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 “servo” in the dialogue box to download it.

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

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.

7.7. Program


Drag the on start block from the drawer, initialize the strip connecting to P1 with 1 led, program to show white color.

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

Drag the forever block from the drawer, set the servo connecting to P2 to drive to 0°, pause for 1 sec and set the servo to drive to 180° and pause another 5 sec.

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

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

7.8. Result


  • After powering on, the LED lights on in white and the servo rotates every 5 seconds.