In this article we are going to explain how to attach a Hall-Effect sensor (Melexis MLX90217) to the SquidBee mote in order to detect small magnetic fields. This application was thought to tell when a door or a window is open by detecting the magnetic field generated by a magnet inserted into its frame.
The sensor is connected to the SquidBee through a probe protected by a Heat-shrinkable sleeve, in the same way as the other tentacle sensors. The sensor consists of a digital logic that recognizes the variation of the flux density on a plate turning on a digital signal in presence of a magnetic field. The sensor requires a pull-up resistor (5.6K) connected between the output and the 5V. supply.
We have connected the output of the sensor to the SquidBee through the digital input 2 so we can attach an interrupt to it and use it to wake up SquidBee from the sleep mode when the magnetic field of the magnet is not detected anymore. We have also included the XBee sleep mode described in the article 'How to save energy in the WSN sleeping the motes'.
In the next video we have used a speaker magnet to test the sensor. We can see how when we separate the magnet from the sensor an alarm message appears in the screen of the computer pointing that the door is open. In the second example we can see the real application, the SquidBee set to the frame of the door and the magnet fixed to the door itself, and how when we open it we can see the same message in the screen.
* Copyright (C) 2008 Libelium Comunicaciones Distribuidas S.L.
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* Version 0.1
* Author: Marcos Yarza <m.yarza [at] libelium [dot] com>
int wakePin = 2; // pin used for waking up
int XBee_wake_pin = 7; // pin used for waking up XBee (connected to pin 9 in XBee)
void wakeUpNow() // here the interrupt is handled after wakeup
// do nothing
attachInterrupt(0, wakeUpNow, HIGH); // use interrupt 0 (pin 2) and run function
// wakeUpNow when pin 2 gets LOW
void sleepNow() // here we put the arduino to sleep
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
sleep_enable(); // enables the sleep bit in the mcucr register
// so sleep is possible. just a safety pin
attachInterrupt(0,wakeUpNow, LOW); // use interrupt 0 (pin 2) and run function
// wakeUpNow when pin 2 gets LOW
sleep_mode(); // here the device is actually put to sleep!!
// THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
sleep_disable(); // first thing after waking from sleep:
// disable sleep...
detachInterrupt(0); // disables interrupt 0 on pin 2 so the
// wakeUpNow code will not be executed
// during normal running time.
digitalWrite(XBee_wake_pin, LOW); // after wakes up the micro, wakes up XBee
Serial.println("Alarm: Door open!!#"); // sends the alarm messge
digitalWrite(XBee_wake_pin, HIGH); // sleep XBee again
sleepNow(); // sleep function called here