MISSION 13

Floor Mat Alarm

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.

Algorithm

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.

Build

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.

What You Will Need

Images   Two pieces of cardstock

Images   Tinfoil to cover one side of each of the A4 cards

Images   Two crocodile clips

Images   Foam, cut to just bigger than A4 size

Images   Tape

Images   Scissors

Images

Figure 13.1    Your tools.

Build

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.

Images

Figure 13.2    Card ready.

Images

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.

Images

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).

micro:bit

Build

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.

Images

Figure 13.5    Catching intruders.

Code

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.

Expert Level

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.

Images

Figure 13.6    micro:bit floor mat.

Circuit Playground Express

Build

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.

Images

Figure 13.7    Circuit Playground Express floor mat alarm.

Code

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.

Images

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).

Images

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).

Images

Figure 13.10    Send a radio message.

4.   You’ll find an example of this code in Mission 12 (Figure 12.12).

Debug

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!

Expert Level

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.

Raspberry Pi

Build

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.

Images

Figure 13.11    Code.

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.

Images

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.

Debug

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.

Expert Level

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.255.44