Magnetic Contact Sensor

/media/uploads/Alexw2011/magswitch.png

Magnetic contact sensors are widely used in the majority of home security systems today. Generally, they are placed on windows or doors to detect when these fixtures are unwillingly opened. While most security systems incorporate the sensors into the main alarm system, our example will sound a (slightly) less annoying alarm using only one sensor.

How It Works

Magnetic contact sensors are essentially "Reed Switches". A "Reed Switch" consists of a set of electrical connectors that are spaced slightly apart and are pulled together when when a magnetic field is placed parallel to it. Typical door / window sensors consist of one Reed Switch and one magnet. There are two types of circuits: normally open, and normally closed. A normally open circuit works as shown in the image below:

/media/uploads/Alexw2011/how-no-reed-switches-work.gif

A normally closed circuit is the exact opposite, with the electrical contacts starting out together and moving apart as a magnetic field is applied:

/media/uploads/Alexw2011/entry_sensor_reed_switch_small.png

The magnetic sensor used in the demo is a normally closed switch; however, by reversing the positive and negative leads, you can turn your sensor into a normally open one.

Pinout / Schematic

/media/uploads/Alexw2011/untitled.png

The picture above is a side view, with the Reed Switch on the bottom and the magnet up top. To connect the sensor to the mbed, you'll need to connect the COMM pin to any of the AnalogIn pins, and the NO / NC pins voltage and ground, respectively.

The connections used for the MagSensor to the mbed are as follows:

/media/uploads/Alexw2011/untitled_pJEKBw1.png /media/uploads/Alexw2011/10583863_10154656809741040_3194556409989897977_n.jpg

Hello World

A Simple Demo

Import programSimple_MagSensor_Demo

A simple demo turning the LED on when contact between the sensor is broken.

Interrupt Alarm Demo

Import programMagSensor_Interrupt_Demo

An interrupt option to using the Magnetic Reed Switch Sensor

Import libraryMagSensor

Library to setup MagSensor / MagSensor interrupt objects

In the majority of alarm systems, you most likely want the contact break between the sensor and the magnet to interrupt the main loop and not reset until the authorities arrive or you choose to reset it. This program creates a simple demonstration of this

Alarm Demo

Import programMagSensor_Alarm_Demo

A demo of the mag-sensor as an alarm

Import libraryMagSensor

Library to setup MagSensor / MagSensor interrupt objects

This alarm demo is similar to the interrupt example above, but shows a continuous use of the magnetic sensor turning on and off whenever the contact is maintained / broken.


Please log in to post comments.