For rooms where there are no doors or doors on which we don’t want to put electronics on the outside of, we can create a floor mat alarm. This is perfect if you share a room with a sibling and don’t want him or her on your side of the room. You create a sensor that will set off an alarm if he or she steps on it.
This sensor is basically the opposite of the door and cookie sensors. Rather than breaking the circuit, the circuit is created. It’s Mission 1 with a floor mat instead of you!
If circuit is created
Set off alarm
What’s very different is the build. The first part of the build is the same for all three devices.
The build is the same for all devices, up to the moment you attach the device. We’re going to create a “circuit sandwich.” The circuit will be complete when the two pieces of bread touch each other. In the middle there will be some filling to stop the bread from touching all the time. There will be a hole in the filling so that the circuits can touch when the sandwich is squished. I’m going to use some foam to create my filling.
Two pieces of cardstock
Tinfoil to cover one side of each of the A4 cards
Two crocodile clips
Foam, cut to just bigger than A4 size
Tape
Scissors
Figure 13.1 Your tools.
1. Cover one side of the card in foil.
a. Cut off a strip of tinfoil that is a bit longer than the A4 piece of card.
b. Place the card on top of the tinfoil.
c. Tape down the tinfoil.
d. Do the same for the other piece of card.
2. Cut a hole in the middle of the piece of foam.
3. Place the card, tinfoil face down, onto each side of the foam.
Figure 13.2 Card ready.
Figure 13.3 Holey foam.
4. I used a strong tape to tape the card onto the mat.
5. Do the same on the other side of the mat.
6. Test your setup by squishing the card down onto the mat. Does it touch the other card through the hole? It can be difficult to tell.
7. Add a crocodile clip to the tinfoil on each side of the mat.
Figure 13.4 Floor mat.
My blue card is on the other side.
Now add this floor mat to your device. Here it is in practice at my front door (I’ve hidden it under a doormat).
1. Connect one crocodile clip from the mat to ground (GND) on the micro:bit.
2. Connect the other crocodile clip from the mat to pin 1 on the micro:bit.
3. Add the speaker to pin 0 and GND.
Figure 13.5 Catching intruders.
Way back in Mission 1, you created the same code for this project with the touch sensor. Add everything we’ve learned since then into the alarm from Mission 12.
Sometimes people don’t set off the alarm. They step around the sensor, or they are cats and don’t weigh enough to press down on the sensor. To scare these smug people, set off the floor mat micro:bit alarm from a second micro:bit.
Figure 13.6 micro:bit floor mat.
1. Connect one crocodile clip from the mat to GND on the Circuit Playground Express.
2. Connect the other crocodile clip from the mat to pin A1 on the Circuit Playground Express.
3. Add the speaker to pin A0 and a different GND.
Figure 13.7 Circuit Playground Express floor mat alarm.
Way back in Mission 1, you created the same code for this project with the touch sensor.
Let’s add everything we’ve learned since then into this alarm.
Figure 13.8 Code from Mission 1.
1. We need the pin to pull up on start.
2. Add a speaker to pin A0, and play a tune when the mat is stepped on (Figure 13.9).
Figure 13.9 Play some tunes.
3. Send an infrared signal from this Circuit Playground Express to another Circuit Playground Express with the speaker attached (Figure 13.10).
Figure 13.10 Send a radio message.
4. You’ll find an example of this code in Mission 12 (Figure 12.12).
Did it work? Problems with this mission can come from the build. Your foam might be too thick, or the hole might not be big enough. If your foam isn’t thick enough, it won’t bounce back, and the cards will continue to touch. You might need to rebuild the mission with different materials if it’s not working for you.
Mission 1 was designed to check whether someone was a zombie, so it would show a green light. This is an intruder! We need a red light! Or a flashing red light!
I set up this floor alarm trap for my family, and my youngest son stepped on it, smiled at me, and then stepped off. The alarm didn’t go off! But it went off for his brother and Dad. Why?? It turns out that he’s not that heavy! His weight did not push the cards together through the foam. You might find that it doesn’t work for small pets either.
To scare these smug people, set off the floor mat alarm from a second Circuit Playground Express.
This is the same build as the door alarm.
1. Connect one crocodile clip from the mat to the male end of a male-to-female jumper wire.
2. Connect the female end to a ground pin on the Raspberry Pi.
3. Connect the other crocodile clip from the mat to the male end of a male-to-female jumper wire.
4. Connect the female end to a data pin on the Raspberry Pi. I went with GPIO 2.
5. Connect a speaker to the Raspberry Pi.
Figure 13.11 Code.
In Mission 8, we created the door sensor alarm. This went off when the door was opened. We just need to tweak that code to go off when the circuit is closed.
1. I’ve changed door to floor.
2. And I called when_pressed instead of when_released.
Let’s add everything we’ve learned since then into this alarm.
1. Send an email when the floor mat is pressed.
Figure 13.12 Code.
2. Remember to change the email addresses and the password to yours as in Mission 12.
3. You’re not going to bring the monitor and keyboard to the floor mat. Set up a crontab to run this code when the Raspberry Pi powers up. Find the steps on how to do that in Mission 8.
As with the door project, the tricky part of this project is the build. You need the foam to be thick enough so that the cards don’t touch all the time, but not too thick so that the cards do touch when pressed.
How about adding the number lock from Mission 11 here? When you enter your house, you have to enter the correct code, or the alarm will go off.
3.17.75.43