Be the life of the party with the new Makey Makey DIY Party Pack!
In our previous classes, we focused on creating simple buttons and interactive switches with different materials. In this class, you'll learn to code alarms with these inventions, and be challenged to design your own alarm system.
Coding an Alarm System- Momentary Switch |
Grab your paper clip push button switch from the first maker class, and let's learn how to code it in Scratch!
You need to code an alarm that will sound when you press the paperclip to the brass fastener. It isn't too difficult, but you will need a quick trick to make sure the alarm only sounds when you complete the circuit! To trigger your alarm sound, it's really pretty easy to code! You need an if/else statement nestled into a forever loop that will sound the alarm when the up arrow is pressed. Otherwise, you want the alarm sound to stop.
Since this code is in s forever-loop that reads from the top down, this is how Scratch is running the code:
This if/else statement works great for changing costumes, broadcasting messages, etc. However, it is trickier with sound as the code will never get to the else statement while the sound is playing, so if you want to stop the sound as soon as key is not pressed, you'll have to add another script. You need the reporting block "Not" from the Operator Palette. This code will be under a separate "When Flag Clicked" so that it will always be running and checking to see "if the up arrow is not pressed.
Now your code will only be triggered when the circuit is closed. If the two conductive touch points do not touch then the alarm will be silenced!
And that's really all you need to code for your alarm! You might want to add more effects, so check out this coding video walkthrough of using your momentary push button alarm from the first class in this series. Follow along to code your own Scratch project. Then design your own push button alarm! We want to see your ideas! Brainstorming and Testing Alarm SystemsDesign considerations:
In this video below, you can see how you could wire up your momentary push button as a doorbell outside your door. I used a phone with an adapter so I could leave the Makey Makey behind the door. To transform the doorbell into an alarm, I used a wire coat hanger (make sure you sand off coating to expose the metal if you use a coat hanger) hung it above a door and connected the coat hanger to the "Up arrow" on Makey Makey. On the door, I placed a strip of HVAC tape connected to "EARTH" on the Makey Makey. This alarm is triggered when someone opens the door as the coat hanger closes the circuit when it touches the aluminum foil strip. Also, the coat hanger is held with a binder clip to allow for movement! (Make sure to ask your parents before using any thumbtacks or applying tape to walls or doors in your room! )
We want to see your inventions! Ask your parents to share them with us on social media and we will highlight your inventions in this spot! One of our ambassadors shared how to make this alarm in his native language, Italian! Godere!
|
|
Coding an Always-on Alarm System- Non-momentary /Toggle Switch |
Now that you've coded a push button alarm, how about coding an alarm that is always set and will blast when someone opens the box that holds your precious goods? Grab your binder clip switch from the first class in this series and let's learn how to code it really quick! This switch is more like a light switch (which is a toggle switch) it comes on when you flip it and off when you turn the switch to "off." That means a light switch works by closing a circuit to turn on the light when you flip the switch one way, and turns it off (opens the circuit) when you flip the switch the other way. The coding for this project might look similar to the other alarm, but we need to switch things up a bit! (Get it? Switch???)
That's all you need to start a sound by releasing a key press, and stop the sound by pressing the key! You can use if/else statements to add interesting visuals to go with your alarm. This code will change the background based on a key press (or not.) You might want to add more effects, so watch this coding video walkthrough of using your non-momentary binder clip switch from the first class in this series. Follow along to code your own Scratch project and view the bonus feature with a real toy box alarm. Then design your own "Always - on alarm." Design considerations:
We want to see your inventions! Ask your parents to share them with us on social media and we will highlight your inventions in this spot! |
|
Next Class? |
Our next class will teach you how to create a tilt sensor with everyday household materials and code Scratch cat to move based on your real physical movements! |
Head to the next class:Recyclable Tilt SensorsGo Back to the Previous Class: Hack a Toy
|