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

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

By r September 12th, 2024 426 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

组装步骤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 13 on the board and link the board to computer via USB cable.

44_15

Open KidsBlock and click File –> Load from your computer.

3111

Choose D:\Code\1.Code_kidsuno to open Servo_Calibration.sb3

44_16

Click 3209 and connect to port, and then 2210 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

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

In D:\Code\1.Code_kidsuno, choose to open 4.4Smart bin_Manual mode.sb3

4403

Click 3209 to connect to port and then 2210.

Explanation

5top

Code Blocks

Blocks

Code block

Events

begin

P

setmode

JS

readjs

servo270

setdegree

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 Kidsuno
Previous
HOW to Achieve Light Adjustment with Kidsuno
Read More
How to Program Relay Module on Kidsuno
Next
How to Program Relay Module on Kidsuno
Read More
Message Us