Blog Archives

PB100 – Prototyping Board


WSN1101L Pin Out


WiSense network stack


Build a door alarm using a reed switch

A reed switch can be switched  on/off by applying a magnetic field.  You can read up on reed switches here –  Reed switches can be normally open or normally closed.


We bought some reed switches and magnets from Digikey. Found one local vendor ( while writing this post.

Let’s build a simple door alarm using a “normally open” reed switch, a small magnet and a WiSense sensor node. Let’s assume that the sensor node is powered by a coin cell battery.  We can use one plastic enclosure to house the sensor node and the reed switch. We also need a tiny enclosure to house the magnet.


When installing the magnet and the sensor/switch enclouse, make sure that the magnet is sufficiently close to the reed switch when the door is in the closed position.

Obviously we want the battery to last as long as possible.  The micro (MSP430) and the radio (cc2520) on the sensor node should stay in deep sleep as much as possible.  We need an interface circuit which will generate an interrupt on a GPIO pin whenever the switch changes state. This will wake up the micro-controller (from its deep sleep mode) whenever the switch opens or closes. This technique keeps energy consumption to a minimum. It also ensures that the device immediately reacts whenever the door being monitored opens or closes.


In the circuit shown above, when the reed switch is open, the GPIO pin is pulled high to Vcc.  So when the door is open, there is no magnetic field acting on the switch and it stays open. When the door is closed, the magnetic field closes the switch which pulls the GPIO pin to ground. When the doors opens, we expect the GPIO pin to go from low to high sending a positive edge triggered interrupt to the micro. When the door closes, we expect the GPIO pin to go from high to low sending a negative edge triggered interrupt to the micro. Things are not as simple because of a phenomenon called switch bounce. I will explain this in another post.

It is important to remember that not all ports on the MSP430 are interrupt capable. WiSense sensor nodes use either MSP430G2553 or MSP430G2955. In both variants, only ports P1 and P2 have interrupt capability.  I have a few useless PCBs lying around which were designed on the assumption that all ports have interrupt capability.

Let us divide the software implementation of this alarm between a reed-switch specific driver and an application layer entity (app).  The driver will be responsible for initializing the GPIO pin allocated to the switch, handling the interrupt, debouncing the switch and finally informing the application about the new state of the switch. Once the application is informed about the state change, it can take any action according to the requirement of the alarm.  Typically it will send a message indicating the new state of the door to any interested application entity within or outside the WiSense sensor network.  If the WiSense sensor network has an interface to the internet, an SMS can be sent to the property owner. In addition a message can be sent (through the WiSense network) to an AC powered alarm siren. Once the application has successfully sent out the message, it should allow the node to go back to deep sleep mode.

We have written a simple library for this switch. Refer to the files listed below. You can access the sensor_framework repository at

  • “sensor_fw/pltfrm/src/reed_switch.c”
  • “sensor_fw/pltfrm/inc/reed_switch.h”