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

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

By r September 23rd, 2024 53 views
In this project, we use a joystick and a servo to control the trash can lid.

Flow

4401

Assembly

line1

Required:

44_00

line1

Step 1

44_01

line1

Step 2

44_02

line1

Step 3

44_03

line1

Step 4

44_04

① Hold the lid still to make it align with the hole.

② 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 click File –> Load from your computer.

3111

Open D:\Code\2.Code_kidsIOT and choose Servo_Calibration.sb3.

44_16

Click 3209 to connect to the port and then 2210.

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

44_12

line1

Step 12

44_13

line1

Completed!

44_17

line1

Wiring Diagram

4402

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.4Smart bin_Manual mode.sb3

4403

Click 3209 to connect to the port and then 2210 the code.

Explanation

5top

Code Blocks

Blocks

Code block

Events

begin

servo270

setdegree

JS

readjs

Serial

serialbegin

Serial

serialprint

Operators

![less than](media/less than.png)

Control

forever

Control

ifelse

Control

wait

line5

Conceive:

  1. Initialization

    Set the servo pin and baud rate.

    4404

line3

  1. Main Code

    Loop: read the value of joystick in y-axis and refresh it every 0.1 seconds, and print it on serial monitor.

    If the value in y-axis is less than 490, set the servo to 45°. If not, set the servo to 180° so then the lid will be closed.

    4405


    Conceive:

    ① Build blocks as follows: Read the value of joystick in y-axis and refresh it every 0.1 seconds.

    4406

    ② Put the following code blocks in “forever”.

    4407

    Determine whether the value in y-axis is less than 490.

    • If yes: set the servo to 45° to open the lid.

    • If not: set the servo to 180° to close the lid.

5bottom

Test Result
4top
Upload code and push the joystick as follows, and the lid will open. If you release the joystick, the lid will close. Now you can control the trash can manually!
4408
4bottom
HOW to Achieve Light Adjustment with KidsIOT
Previous
HOW to Achieve Light Adjustment with KidsIOT
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