[No.10] Invent a Trash Can That Opens by Itself!

Programming and Making

Opening the lid of a trash can is surprisingly annoying... especially when your hands are full of trash... When you want to solve a "little problem" like that, leave it to SPACEBLOCK, the tiny computer for making things!! This time, let's upgrade a trash can so its lid pops open by itself when you go to throw something away. Here's the trash can we'll upgrade! It sits on your desk, so it's handy for tossing the wrapper from a snack you ate while studying. It'll come in handy during allergy season too!

Elementary School ~ Intermed. 55 min
It has a lid, so it's neat and tidy, but opening it is a bit of a hassle...

For this upgrade, we'll use the "180° Micro Servo Motor" and the "IR Obstacle Avoidance Sensor Module."

What You Need & Getting Ready

Top left: SPACEBLOCK Standard Package. Bottom left: obstacle avoidance sensor. Right: servo motor

Connect the Add-On Parts to SPACEBLOCK

First, let's connect the servo motor and the obstacle avoidance sensor we're using this time to SPACEBLOCK.
How everything is connected

For the details, look at the next picture. The obstacle avoidance sensor has 4 pins, but you only use the 3 labeled "G," "V," and "S."

Pay attention to the jumper wire colors and the pin socket positions when you connect them

What Can a Servo Motor Do?

A servo motor is a motor whose shaft turns anywhere from 0° to 180°, and you can make it turn to the angle you choose. If you attach the included parts called servo horns to the shaft and get creative, you can make all kinds of motions, like pulling, turning, tipping, and waving. This time, we'll use it as the power to open the trash can lid.
Attach the included servo horns and get creative with crafts, and a servo can power all sorts of things

To program it, use the [Move servo (A0 (T2)) to (90) degrees] block in the "Output" category.

Use the servo motor block in your program

What Can the Obstacle Avoidance Sensor Do?

The obstacle avoidance sensor uses infrared light to detect whether there is an obstacle within a certain distance. This time, we'll use it to detect when a hand comes near the trash can.

It tells the computer whether there's an obstacle or nothing at all, but it can't tell how far away the obstacle is or how big it is. Sending just two kinds of information like this, "there is" or "there isn't," is called digital input.

When there's no obstacle, the obstacle avoidance sensor makes the voltage on its pin high, and when there is an obstacle, it lowers the voltage. We won't use them this time, but programs sometimes use the values true and false. With digital input, the program gets true when the voltage is high and false when the voltage is low.

The obstacle avoidance sensor decides whether there is an obstacle or not

To program it, use the [When the voltage of (A0) (rises)] block in the [Input] category. The voltage goes down when an obstacle is detected, so to program what happens when there's an obstacle, set it to [When the voltage of (A0) (falls)].

The program block to use with the obstacle avoidance sensor

You can adjust how far away the sensor detects obstacles by turning a small knob on it, called a potentiometer, with a screwdriver. When the obstacle avoidance sensor is connected to SPACEBLOCK and the power is on, you can check whether it detects an obstacle by looking at its light.

Turn the distance potentiometer gently, only as far as it turns easily

A Program That Opens the Lid When You Hold Your Hand Over It

Now let's make a device that opens the trash can lid automatically when you go to throw something away. Here's how it works: when the obstacle avoidance sensor detects your hand coming to throw trash away, the servo motor opens the lid.

First, build the program as in the next picture.

A program that opens the lid automatically when something is detected and closes it 3 seconds later

Run the program and bring your hand close to the obstacle avoidance sensor. The servo motor whirs and moves, then 3 seconds later whirs back to where it started.

Watch it in the video.

QR code for project
Now let's build the device!

Using the Servo's Power to Open the Lid

Let's make a system that opens the trash can lid with the servo motor's movement. Wrap a straw around one of the parts that come with the servo to make it longer. This part will take some force, so we recommend reinforcing it well and then cutting it to a length that works.
Make it longer with a straw

The plan is to attach this part inside the trash can and use it to push the lid up.


Attach the servo here...
The straw pushes the lid up

This spot takes some force, so reinforce it...

A trick to make more surface to stick to the trash can

Here's how we attached it.

Just tape it in place

Set Up the Obstacle Avoidance Sensor

Next, attach the obstacle avoidance sensor. Put it where your hand naturally passes when you throw trash away. If you fix the sensor pulled back inside, it will think the side of the trash can is an obstacle, so we made a slightly larger hole for it.
Make a hole here, with a little extra room
Tape the obstacle avoidance sensor to the inside of the trash can

Here's what it looks like from above.

The servo motor and obstacle avoidance sensor are in place

Test It & It's Done!!

First, test how it moves. If the lid flies open too hard or doesn't open well, try changing the servo angle in the program, adjusting where the servo is attached, or changing the length of the straw, and you'll find what works best. If you want to change how close your hand has to be, adjust it with the obstacle avoidance sensor's potentiometer.
As the straw tilts, it pushes the lid up

Let's watch it in the video.

Finally, stick SPACEBLOCK and the battery box somewhere out of the way, and protect them so they won't get dirty or broken when trash goes in. Your automatic trash can is complete!
The finished trash can: the lid pops open as you go to throw something away

Let's watch a video of someone throwing trash away.

It opens so smoothly that it's kind of fun, and you'll want to keep throwing trash away! There are probably other ways to open a lid with a servo too. Try it yourself!

Let's keep solving everyday "problems" and "hassles" with your SPACEBLOCK inventions!!