Learning Outcome

In this chapter, we learn to


Introduction: Servo Motor and Proximity Sensor.

Activities: Build an Automated Waste Bin (Trashbot Smart Bin).

Challenge: Upgrade trashbot to include light and sound, making it more interactive.

Introduction to Servo Motor

Servo motors are essential components in the world of robotics and automation. They allow precise control over the angular position of a shaft, making them ideal for applications like controlling robotic arms, steering mechanism, or even opening and closing doors. In this activity, you will learn how to connect and control the servo motor to specific angles with the EDU PICO.

> Libraries <

-> Libraries: board, time, servo, pwmio, adafruit_motor.

-> Servo Motor Configuration:

< CircuitPython Code >

Click here to download code

< Expected Output >

Upon completion of the activity, you should be able to:

-> Run the program and the servo motor will rotate to each angle position from 0 to 45, 90, 135, and 180 degrees repetitively.

Introduction to Proximity Sensor

The proximity sensor detects the presence or absence of objects using the reflection of infrared light (IR) without physical contact. They are used in various applications, such as touchless switches in public restrooms, automatic faucets, and smartphones. Proximity sensors are also important in industrial automation, robotics, and automotive systems for tasks like object detection and machine safety features.

> Libraries <

-> Libraries: board, time, busio, adafruit_apds9960.

-> Proximity Sensor I2C Pins Configuration: SCL = GP5 and SDA = GP4.

-> Input: Move your hand up and down above the proximity sensor

-> Action Required: Enable the plotter function in Thonny IDE to have a better visual on the proximity value.

< CircuitPython Code >

Click here to download code

< Expected Output >

Upon completion of the activity, you should be able to:

-> The proximity sensor will continuously read and print the proximity values to the shell console.

-> If the obstacle is getting closer to the sensor, the proximity value will be greater.

-> The program will continuously update and display the proximity value at an interval of 0.1 second.

Mini Activity Proximity Sensor

Let's turn this activity into an obstacle-detection beeping device! First, import simpleio library so that we can initialize the buzzer's GP21 pin.

> Libraries <

-> Libraries: board, time, busio, adafruit_apds9960, simpleio.

-> Proximity Sensor I2C Pins Configuration: SCL = GP5 and SDA = GP4.

-> Input: Move your hand up and down above the proximity sensor

-> Action Required: Enable the plotter function in Thonny IDE to have a better visual on the proximity value.

< CircuitPython Code >

Click here to download code

< Expected Output >

Upon completion of the activity, you should be able to:

-> The proximity sensor will continuously read and print the proximity values to the shell console.

-> If the obstacle is getting closer to the sensor, the proximity value will be greater.

-> The program will continuously update and display the proximity and duration value.

Automated Waste Bin

TrashBot Smart Bin

Time to build your very own TrashBot! Equipped with an IR sensor and a servo motor, it detects the presence of your hand (or any object) and automatically opens its lid, eliminating the need for physical contact. This makes using it more convenient and hygienic, reducing the risk of the germs spreading.

> Libraries <

-> Libraries: board, time, busio, adafruit_ssd1306, adafruit_motor, pwmio, adafruit_apds9960, font5x8.bin.

-> Proximity Sensor and OLED Configuration: SCL = GP5 and SDA = GP4.

-> Servo Motor Configuration: GP6 with orange wire connected to (S), red to (+), and brown to (-), as shown in the illustration below

-> Input: Place your hand (or any object) roughly 1 cm above the proximity sensor to activate the servo motor.

< CircuitPython Code >

Click here to download code

< Expected Output >

Upon completion of the activity, you should be able to:

-> If proximity sensor detect an object, the servo motor will rotate from 70 to 150 degrees, opening the lid of the trashbin.

-> The OLED will print the status of the lid from "Status: Lid Close" to "Status: Lid Open" once the sensor is triggered.

-> The lid remains open for 5 second before closing.

Challenges

#1 - Automated Waste Bin

Now that we've got the Trashbot running, why don't we introduce two more elements into the project? The first element, let's light up the RGB LEDs in green when an obstacle is detected and remain red when there are no obstacles. After that, the RGB LEDs starts a countdown to indicate how much time is left before the lid of the bin closes.

The next element we will introduce is sound; let's add a soothing buzz tone when the lid returns to its closed state. The tone will indicate to the user that the Trashbot's work is done.

Ready? Let's give it a try!

> Libraries <

-> Libraries: board, time, busio, adafruit_ssd1306, neopixel, simpleio, adafruit_motor, pwmio, adafruit_apds9960, font5x8.bin.

-> Proximity Sensor and OLED Configuration: SCL = GP5 and SDA = GP4.

-> Servo Motor Configuration: GP6 with orange wire connected to (S), red to (+), and brown to (-), as shown in the illustration below

-> Input: Place your hand (or any object) roughly 1 cm above the proximity sensor to activate the servo motor.

< CircuitPython Code >

Click here to download code

< Expected Output >

Upon completion of the activity, you should be able to:

-> If proximity sensor detect an object, the servo motor will rotate from 70 to 150 degrees, opening the lid of the trashbin and green LEDs will light up.

-> Each LEDs will turn to red in every second for 5 seconds and buzzer will play a tone.

-> After 5 seconds, the servo motor will rotate from 150 to 70 degrees, closing the lid of the trashbin.

You've mastered Chapter 5! Continuing the journey to the next chapter!