Case 06: Insect-catching Device
7. Case 06: Insect-catching Device#
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.
Attract the pests through the LED and drive the servo to catch them.
7.5. Hardware Connection#
Connect the Rainbow LED to P1 and the servo to P2 on IoT:bit.
7.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 “neopixel” in the dialogue box to download it.
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.
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.
Drag the on start block from the drawer, initialize the strip connecting to P1 with 1 led, program to show white color.
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.
After powering on, the LED lights on in white and the servo rotates every 5 seconds.