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

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

By r September 24th, 2024 644 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 io33 on the board and link the board to computer via USB cable.

44_15

Open KidsBlock and connect to the board, click File –> Load from your computer.

3111

Choose D:\Code\2.Code_kidsIOT to open Servo_Calibration.sb3

44_16

Click 3209 to connect to port and 2210 the code.

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 KidsBlock and connect to the board, click File –> Load from your computer.

3111

Choose D:\Code\2.Code_kidsIOT to open 4.5Smart bin_Automatic mode.sb3

4503

Click 3209 to connect to port and then 2210.

Explanation

5top

Code Blocks

Blocks

Code block

Events

begin

P

setmode

P

readdigital

P

setout

servo270

setdegree

Operators

=

Control

forever

Control

ifelse

Control

wait

line5

Conceive:

  1. Initialization

    Set the pins of obstacle avoidance sensor, buzzer and servo.

    4504

line3

  1. Main Code

    Loop: Determine whether the read value equals 0.

    • If it is 0, i.e., the sensor detects obstacles, the buzzer will receive a high level so then emit sound. At this time, the servo rotates to 45° to open the lid.

    • If it is not 0, i.e., the sensor detects nothing, the buzzer will not alarm. At this time, the servo rotates to 180° to close the lid.

    4505

    6top

    Q : Function of the DELAY block?

    When the obstacle is leaving the sensing range, the lid will immediately close without delay. Thus, we add a delay time to maintain the state of the lid.

    A : Delay is used to maintain the state of the lid, which can be modified according to your needs.

    6bottom

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.

4506

4bottom

HOW to Build a Smart Trash Can (Manual Mode) with KidsIOT
Previous
HOW to Build a Smart Trash Can (Manual Mode) with KidsIOT
Read More
How to Program Relay Module on Kidsuno
Next
How to Program Relay Module on Kidsuno
Read More
Message Us