Recyclable Tilt Sensors
45 min
Ages 8+
What Will You Learn?
In this class, you’ll start playing with movement and how movement can close a switch. Build a tilt sensor out of foil and a toilet paper tube and use it to control the Scratch cat with Makey Makey!
Build a Toilet Tube Tilt Sensor!
Gather Materials
Grab your recyclables, foil, a marble, a glue-stick, and your Makey Makey kit, and let’s get making!
What you are building
A sensor is an input device that senses input from the physical world (like water, light, motion, sound) and then signals that information to an output device. Today we are building a tilt sensor as our input device and Scratch cat is going to read that information and perform the output!
The tilt sensor device you are building works by sensing angular movement. When you tilt your tilt sensor to the left, the metal ball inside will connect and complete the circuit and signal to the computer that the device is angled left. When you tilt to the right, the ball makes a different electrical connection and signals that the input device is at a right angle.
We can replicate a real tilt sensor with simple everyday materials like a toilet tube, foil, and paperclips. The foil inside your tube will be connected to EARTH, and the paperclips will be left and right inputs. Inside the tube, a metal marble will move when you tilt your sensor. When the marble tilts to the right, it will bridge the connection of the right input and EARTH and complete the circuit. This will signal the right arrow of your Makey Makey. When you tilt the tube to the left, the marble will touch the left input and EARTH and signal the left arrow key press.
You can follow along with this video to build your toilet tube tilt sensor or follow the steps below the video.
How to Build It
Step 1
Cut a piece of aluminum foil to fit inside your toilet tube and use a glue-stick to make it adhere to the inside of the toilet tube.
Step 2
Unfold a paperclip to be your right input and use a piece of Duct Tape to hold the paper clip to the tube. Make sure the paper clip DOES NOT touch the foil on the inside of the tube.
Step 3
Use a piece of Duct Tape to hold the paperclip onto the sensor. Before we put the paperclip o the right side, we need to add our marble that will make the electrical connections when we tilt our device.
Step 4
Let’s make your marble conductive! Simply wrap a marble in foil and make sure to smooth it onto the marble by rubbing it between your hands.
Step 5
Place the metal marble inside and make sure it doesn’t roll out of the tube. You might have to manipulate your paperclip to keep the marble in. Also check to see if your marble will connect the paperclip to the foil you placed inside.
Step 6
Use a second paperclip to be the left input. Unfold and tape the paperclip to the tube. Again, make sure the paperclip does not touch the foil on the inside of the tube.
Step 7
Use Duct Tape to secure your paperclip, and now you are ready to clip to Makey Makey and test your tilt sensor device!
Testing Your Tilt Sensor
Step 8
Connect an alligator clip to EARTH and the foil on the inside of your tilt sensor.
Make sure the metal on your clip connects to the foil! (The foil inside your tube must also be one continuous piece of foil for this sensor connection to work!)
Step 9
Plug an alligator clip from the RIGHT arrow to the right paperclip and another alligator clip from the LEFT arrow to left paperclip.
Step 9
Now you are ready to plug the red USB from the Makey Makey into your computer and connect your Tilt Sensor with your computer! We built this Scratch Project to test your connections.
If you tilt your sensor to the left, the virtual Makey Makey left arrow should light up, and the virtual tilt sensor will tilt left. Don’t forget to hit the green flag to focus your computer’s attention to this Scratch project. The Scratch cat won’t move yet! You have to code it Scratch cat to work with your toilet paper tube tilt sensor in the next step.
If your tilt sensor is working the next step is to code Scratch cat to move with your handmade tilt sensor!
Coding Scratch Cat to move with Tilt Sensor
Step 10
Getting Scratch cat to move with a left tilt and right tilt is actually pretty easy! Click on the cat sprite to code it. To move Scratch cat to the left when the left arrow is pressed, you need to nest this code inside an “if statement.”
Step 11
Open this Scratch Project, then hit REMIX, to code along with us!
This code signals to Scratch cat to point to the left by and move to the left by changing where the sprite is on the x axis. The x axis points changes the left and right direction of the sprite. To change up and down, you would change the coordinates on the y-axis.
To move left when the left arrow is pressed make sure the variable inside the “change x by” block is a negative number. This will make the cat move to the left.
Step 12
Step 12
To move right when the right arrow is pressed, duplicate this code and have the Scratch cat point in direction 90 and change the location on the x axis by positive 10.
Step 13
Place both of these if statements into a forever loop so that Scratch will constantly be checking to see if a left arrow or right arrow key is pressed. If Scratch gets a signal the arrow is pressed, then the cat will move accordingly.
The event to start all of this will be under the “When green flag is clicked” hat. If you want this to be triggered by a different event, you can have this code only work on a certain background, or after a sprite is clicked, etc.
Step 14
It’s always good to have your sprite know where to start on the screen when the green flag is clicked as well. To start the cat along the x/y axis, place the “go to x: ___ y: ___” block under the “When green flag is clicked.”
The variables we suggest here will start Scratch cat standing on the black line sprite to the far left of the screen. Try changing these coordinates !
Coordinates measure the distance of this point from the x- axis and y- axis. Where does Scratch cat land if you plot these points:
- (0, 150)
- (0, -150)
- (200, 0)
- What coordinates will put Scratch cat in the center?
Coding Raining Tacos
Step 15
Let’s motivate Scratch cat by coding some raining tacos!
Click on the taco sprite to code it. To start at the top of the screen, set the taco on the y axis with the coordinate: 180. To have the taco fall from this point, you want to change the y coordinate with a negative number. If you wanted your tacos to float up, what number would you use for changing the y coordinate?
Step 16
Once the taco reaches the black line, we want the taco to head back to the top of the screen! To have the taco populate at different spots on the x coordinate plane, just add the “go to random” block, but make sure you still set the y coordinate to 180.
Step 17
Step 18
Try your code! Does the taco appear at the top and fall to the bottom like rain? Need more taco rain drops? Before you duplicate this code, you need to create a scoring variable and have something happen when the taco sprite touches the cat sprite!
Step 19
Create a scoring variable in the variables palette. When the green flag is clicked, you want to set the score to 0. The score will increase if the taco sprite is touching the cat sprite. Find the “touching sprite” reporting block in the sensing palette.
Step 20
Add a sound, change the score, and change the xy coordinates of the taco so that it starts at the top of the screen again!
Step 21
Need more rain? Right click on the taco sprite to duplicate the sprite. The more taco sprites you create, the more tacos will rain! Change the wait time on taco sprites so they don’t all start raining at the same time
Step 22
Full Video for Coding the Scratch Cat and Tacos is available on our Youtube channel and below!
What's Next?
More Ideas
In this class, you’ve learned to make a tilt sensor and use it to code and control the Scratch cat.
- What other kind of game could you code for this sensor?
- Could you make a balancing game?
- Could you code a driving game? How could you add more input points on your physical tilt sensor so a sprite could move faster or be slowed down?
Makey Makey Classic Inventor's Kit
The original Makey Makey Classic – Named one of Consumer Reports’ “Best Tech Toys of 2014,” “Best of Toy Fair 2014” by Popular Science, and a finalist for Toy of the Year 2016.
Makes STEM Education fun! Start out easy with a banana piano. First setup takes seconds. Then make game controllers, musical instruments, and countless inventions. Advance to additional inputs and multi-key remapping up to 18 keys. Ages 8 to infinity.
Turn everyday objects like bananas into touchpads!
Connect the world around you to your computer! Setup takes just seconds.
Just plug, clip, and play! No programing knowledge needed. No software to install. Works with Mac and Windows.
1000s of possibilities! Draw your own game controller, sneak a cat selfie, and dance like never before.
Ages 8 to infinity.
Visit the Makey Makey website for tons of projects, educator resources, apps and more.
Materials:
- Makey Makey Classic
- Toilet Paper Tube
- Paperclips
- Foil
- Gluestick