For this month’s post, we’re going to show you how to make an alarm that is triggered by nearby objects. We used it to deck out a high-tech blanket fort!
If you’ve visited our blog before, you may already know that forts are big in our house. The last time we posted about an electrical engineering project for a blanket fort, we built a wacky doorbell using an electromagnet.
This is a fun and straightforward electrical engineering project for anyone to build. Kids love the magic of triggering the alarm just by getting close. They also love the fun of securing their own rooms with this alarm to keep adults out!
This electrical engineering project demonstrates how to build a circuit using a MOSFET, which is a common circuit design that can be useful to know for building other circuits using a variety of sensors.
If you aren’t already familiar with breadboards, you should check out this post on how to use a breadboard first. And, if you’re new to all this, here’s a quick crash course on electric current, resistance, and voltage.
We’ll tell you what parts we used to make the alarm and a bit about how they work. Then we’ll give you step-by-step instructions to make your own alarm.
You can check out our video tutorial here and subscribe to our YouTube channel to keep up with new projects.
We explain everything below as well (but you have to watch if you want to see what happens when Dad tries to break in to the fort!)
How to make an alarm circuit: proximity sensors, MOSFETS, and resistor values
We want to make a security alarm that triggers when someone gets too close to the entrance of the fort. To do that, we’ll use a proximity sensor.
How a proximity sensor works
Two parts make up our proximity sensor: an infrared-light-emitting diode and a phototransistor.
Let’s talk about the infrared-emitting diode first.
A diode is an electrical component that only allows current through in one direction. Infra-red light is the same type of radiation as visible light, but it has a longer wavelength, so our eyes can’t see it. The infrared-emitting diode in our proximity sensor does just what it sounds like– it emits infrared light.
The phototransistor detects infrared light. If something gets close to the proximity sensor, then the infrared light emitted by the infrared-emitting diode bounces back and the phototransistor detects it.
When the phototransistor is triggered by infrared light, it puts out an electric current.
So far so good. The infrared-emitting diode emits infrared light. If there is an object nearby, the infrared light will bounce off that object and return to be detected by the phototransistor. If the phototransistor detects infrared light, it outputs an electric current.
Now, what do we do with that electric current? We’d like to use it to power a loud buzzer. The problem is that the current generated by a phototransistor is very weak. In order to power the alarm buzzer, we’ll need to amplify that current, and we can do that using a device called a MOSFET.
What is a MOSFET?
MOSFET is short for “metal-oxide-semiconductor field-effect transistor.” As you may have guessed from its name, a MOSFET is a type of transistor. (Fun fact: there are billions of MOSFETS working inside your computer).
There are a few different kinds of MOSFETS. Specifically, we used an n-channel enhancement type MOSFET. For a deep dive into how MOSFETS are designed and how they function, head over to Wikipedia.
For our purposes, all you need to know is that a MOSFET has three pins: drain, source, and gate. Don’t think too hard about why the pins are named this way – it isn’t super intuitive!
First we have to connect the drain to a positive voltage and the source to ground.
The voltage at the gate determines whether the MOSFET will allow electricity to flow from the drain to the source.
When no voltage is applied at the gate, the MOSFET does not allow electricity to flow.
When there is sufficient voltage on the gate pin, the MOSFET lets electricity flow from the drain to the source.
So, by allowing electricity to flow through a MOSFET, a weak voltage can be amplified by the MOSFET.
Figuring out resistor values and the final circuit design
Before we make our alarm circuit, there are just two more things we have to do: we have to figure out what resistors we’ll need, and we have to figure out how all the parts need to be connected.
Just like with any other light-emitting diode (LED), we need to protect our infrared-emitting diode with a resistor to limit the current flowing through it.
Ohm’s law tells us: Voltage / Resistance = Current
Voltage is measured in volts.
Resistance is measured in ohms.
Current is measured in amps.
We’re using a 9-volt battery to power the circuit.
To determine the maximum current, we can look at the data sheet for our proximity sensor. We see that the infrared-emitting diode’s maximum rated forward current is 50 milliamps, which is 0.05 amps.
Plugging in voltage and current, we can use Ohm’s law to calculate the needed resistance: 180 ohms.
To figure out how to connect the proximity sensor pins, we can again look at the data sheet. The cathode and anode of the infrared-emitting diode connect to the positive and negative buses respectively, one of them through a 180-ohm resistor (as we calculated above).
On the phototransistor side, current flows from the collector to the emitter, so the collector connects to the positive bus and the emitter to the MOSFET.
All that’s left is connecting the negative buzzer contact to the MOSFET and the positive contact to the positive bus on the breadboard. And we have to connect the 9-volt battery leads to the positive and negative buses.
It’s good practice to also connect the phototransistor emitter to ground through a large resistor. That way, if there is any “leakage” of electrical current through the proximity sensor, it does not trip the MOSFET and buzzer. Through trial and error, we found a 100K-ohm resistor worked best
Here are the step-by-step instructions to make an alarm that is triggered by nearby objects.
Supplies to make an alarm
Resistors – 180 ohm and 100k ohm
Steps to make an alarm
Step 1: Insert the proximity sensor and resistors
Here’s a photo of our completed circuit.
Start out by inserting the proximity sensor so that it straddles the groove going down the middle of the breadboard. Make sure that the infrared-emitting diode (the clear side) is on the right and the phototransistor (the dark side) is on the left, as shown above.
Next, break out the resistors.
Put one leg of the 180 Ohm resistor in one of the breadboard holes that is electrically connected to the contact directly below the infrared-emitting diode. The other leg of that resistor can connect to your negative bus.
Put one leg of the 100K Ohm resistor in one of the breadboard holes that is electrically connected to the contact directly below the phototransistor. The other leg of that resistor also connects to your negative bus.
Step 2: Make connections from proximity sensor pins and resistors
To finish wiring up the proximity sensor, we need to connect both of its upper contacts to the positive bus.
Put one end of a jumper wire in one of the holes electrically connected to the contact directly above the infrared-emitting diode. Connect the other end of that jumper wire to your positive bus.
Then, with another jumper wire, put one end in one of the holes electrically connected to the contact directly above the phototransistor. The other end of the jumper wire goes in your positive bus.
Finally, we need to connect the proximity sensor to the MOSFET.
Step 3: Insert the MOSFET and connect pins
The data sheet for the MOSFET tells us that the left-most pin is the gate. So, insert the MOSFET into the breadboard so that the left-most pin goes into one of the breadboard holes that is electrically connected to the contact directly below the phototransistor. (One leg of the 100K-ohm resistor should already be somewhere in that row of electrically connected holes – we put it there in Step 1.)
Make sure that neither of the other two MOSFET pins are in any holes that are electrically connected to any other parts of this circuit.
The MOSFET data sheet also shows us that the right-most pin is the source pin. Put one end of a jumper wire into one of the holes that is electrically connected to the source pin, and put the other end of the jumper wire into one of the holes of your negative bus.
The middle MOSFET pin is the drain pin, which is where the buzzer will connect…
Step 4: Connect the buzzer
Insert the end of your buzzer’s negative lead into one of the holes electrically connected to the MOSFET’s middle drain pin.
Insert the end of your buzzer’s positive lead into one of the holes on your positive bus.
Step 5: Connect the battery
Attach the 9-volt battery to the battery connector. Then, insert the end of the positive battery connector lead into the positive bus. The last step is to insert the end of the negative battery connector lead into the negative bus (not shown in the photo).
Voila! If you got this far, good work! Test out your alarm circuit. Does it work?
If you build this project, please let us know how it went. Are there other projects you’d like us to build? Please leave us a comment!
Check out all of our cool engineering projects.
We also have a helpful basic electronics page that teaches skills such as how to use a breadboard and multimeter.