X
Home > Blog > STEM for Arduino > HOW to Build a Smart Trash Can (Automatic Mode) with Kidspico

HOW to Build a Smart Trash Can (Automatic Mode) with Kidspico

By r October 8th, 2024 53 views

We will construct an automatic trash can with obstacle avoidance sensor, active buzzer and servo.

Flow

4501

Assembly

line1

Required:

44_00

line1

Step 1 to 10 are the same as those in 4.4, so you can directly use the form in 4.4 here.

① Remove the joystick.

② mount from step 11.

Yet if you have not assemble the building blocks in 4.4, please start from step 1.

line1

Step 1

44_01

line1

Step 2

44_02

line1

Step 3

44_03

line1

Step 4

44_04

① Hold with your fingers.

② Insert the rod.

ATTENTION: keep the lid flatwise.

44_14

line1

Step 5

44_05

line1

Step 6

44_06

line1

Step 7

44_07

line1

Step 8

44_08

line1

Step 9

44_09

line1

Step 10

44_10

The servo need to be calibrated before using. Connect the servo to pin io19 on the board and link the board to computer via USB cable.

44_15

Open Servo_Calibration.py and click 1407.

'''
 * Filename    : Servo_Calibration
 * Thonny      : Thonny 4.1.4
 * Auther      : http//www.keyestudio.com
'''
from machine import Pin, PWM
import time

servo = PWM(Pin(19))
servo.freq(50)  #T = 1/f = 20ms

def angle(x):
    return int((((x + 45) * 1.8 / 270) + 0.6 )/ 20 *65535)

while True:   
    servo.duty_u16(angle(90))

After calibration, disconnect the board to computer and continue to mount.

ATTENTION: During mounting, please hold and keep the lid flatwise.

44_11

line1

Step 11

45_12

line1

Step 12

45_13

line1

Step 13

45_14

line1

Step 14

45_15

line1

Completed!

45_16

line1

Wiring Diagram

4502

Test Code

Open 4.5Smart bin_Automatic mode.py and click 1407.

'''
 * Filename    : Smart bin_Automatic mode
 * Thonny      : Thonny 4.1.4
 * Auther      : http//www.keyestudio.com
'''
from machine import Pin,PWM
import time

servo = PWM(Pin(19))
servo.freq(50)  #T = 1/f = 20ms

def angle(x):
    return int((((x + 45) * 1.8 / 270) + 0.6 )/ 20 *65535)


Obsensor = Pin(22,Pin.IN)
Buzzer = Pin(2,Pin.OUT)

while True:
    Obsensor.value()
    if Obsensor.value() == 0: #detects something
        Buzzer.on()           #buzzer alarms
        servo.duty_u16(angle(-45))  #lid opens
    else:                     #detects nothing
        Buzzer.off()          #buzzer stays quiet
        servo.duty_u16(angle(90))  #lid closes
    time.sleep(0.5)

Explanation

5top

Conceive:

  1. Initialization: set the pins of obstacle avoidance sensor, buzzer and servo, set the servo output frequency.

  2. Loop:

    ① Read the digital power level of obstacle avoidance sensor.

    ② Determine whether the read value equals 0.

    • If it is 0, i.e., the sensor detects obstacles, the buzzer will emit sound. At this time, the servo rotates to open the lid.

    • If it is not 0, i.e., there is no obstacle, the buzzer will not alarm and the servo rotates to close the lid.

5bottom

Test Result

4top

After uploading code, we first need to adjust the obstacle avoidance sensor (please see chapter 3.5 for details).

After adjusting, place something in the sensing range in front of the obstacle avoidance sensor.

When the obstacle avoidance sensor detects it, the buzzer makes a sound, and the servo rotates to open the lid; When the thing leaves the sensing range, the sensor detects nothing, and the buzzer stops alarming, and the servo rotates to close the lid.

4503

4bottom

HOW to Build a Smart Trash Can (Manual Mode) with Kidspico
Previous
HOW to Build a Smart Trash Can (Manual Mode) with Kidspico
Read More
Comprehension! HOW to Monitor Smart Home Environment with ESP32
Next
Comprehension! HOW to Monitor Smart Home Environment with ESP32
Read More
Message Us