12. Case 03: Garbage disposal system¶
Level:
12.1. Goal¶
Make a smart garbage bin by showing different colors of light according to the volume of garbage inside.
12.2. Background¶
What is garbage disposal system?
LED light on the garbage bin can show people the amount of garbage inside the garbage bin so that garbage truck can easily determine if the garbage is full or not. This can minimize the wastage of the garbage bags and become a more environmental-friendly city.
Garbage disposal system operation
The distance sensor should be able to sense the amount of garbage is inside the garbage bin. Multi-colour LED can be used to emit different colour of light (green and red light), which represent the emptiness of the garbage bin.
12.4. Assembly step¶
Step1
Attach the Multi-colour LED to C1 model with M4 * 10mm screws and nuts.
Step 2
Attach the distance sensor to C2 model with M4 * 10mm screw and nuts.
Step 3
Put together all the cardboard parts (C1-C2).
Step 4
Assembly completed!
12.5. Hardware connect¶
Connect the Distance Sensor to P14 (trig)/ P15 (echo) port of IoT:bit
Connect Multi-color LED to P1 port of IoT:bit
12.6. Programming (MakeCode)¶
Step 1. Set variable and initialize multi-colour LED
Inside
on start
, snapset variable distance to 0
fromvariables
Snap
set strip to NeoPixel at pin...
fromNeopixel
. Set pin P1 with 1 led of the block.Snap
strip set brightness
fromNeopixel
>more
and set brightness 50Snap
pause
to wait 5 seconds
Step 2. Get distance value
Inside block
forever
. Setdistance
toget distance unit cm trig P14 echo P15
, that’s say get the distance value by connecting the distance sensor to P14 and P15Snap
if statement
intoforever
, setdistance ≤ 4
intoif statement
Snap
Pause
to the loop to wait 1 second for next checking
Step 3. Show indicating colours with distance value
If distance ≤ 4, then
strip show color red
, elsestrip show color green
Full Solution
12.7. Result¶
The distance sensor can return the distance value between the top of the garbage bin and the level of garbage inside the garbage bin. The LED light is used to indicate if the bin is full or not. If it is empty or there are some garbage, the LED turns green, if it is full, the LED turns red.