SquidBee as an infrared light mote : Detecting presence
Víctor Gracia - July 29, 2008


Important: Libelium has launched a new sensor device: Waspmote. It is ready for research and market applications. You can discover the differences between both platforms in the document: Waspmote vs SquidBee.


2
The PIR (Passive InfraRed) sensor from Parallax is a detection device containing a photodiode which outputs an analog signal when excited with infrared radiation; a Fresnel lens focuses this light and an on-board amplifier together with a simple digital I/O stage generate the necessary signal to be read by our SquidBee circuit.

We have soldered the three pins from the PIR board and a standard red LED to the following Arduino ports:

Vdd connected to the 5Vdc output (red)

Vss connected to one of the GND outputs (black)

OUTPUT connected to the DIGITAL-2 input (purple)

LED connected through a 500Ω resistor to the DIGITAL-11 and GND outputs (blue)

 

4

As we did with the SONAR mote, the lens and a standard red LED are placed through two holes in the box. A 9Vdc transformer feeds the main board from a constant 220Vac power supply and the mote is hung on the wall close to the stairs.

Whenever somebody comes into the monitored area, the mote detects presence (see datasheet due to the fact that every body at any temperature radiates infrared light; then, it sends a single warn and the LED blinks once. The detection pattern covers around a 60° sector with a radius dependant upon the temperature of the intrusion body, but for this application we have verified that the mote detects people presence at a maximum distance of around 4m.

We have programmed this mote with a standard wake-up trigger code to wirelessly send an alarm at any time presence is detected. The mote is kept in a sleep mode until the PIR sends a pulse; then it wakes up, sends the alarm and automatically changes to sleep mode again. This is a very good example of how a mote can use a battery and accomplish full functionality with a low power consumption.

#include <avr/sleep.h>

 

/*
* Copyright (C) 2008 Libelium Comunicaciones Distribuidas S.L.
*
* This file is part of SquidBee code examples
* squidbee_pir.pde 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 2 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
*/

/* Name: squidbee_pir.pde
* Version 0.0.1
* Desc: A pir sensor is attached to SquidBee and we use an interrupt pin to activate SquidBee and send message
* Author: Marcos Yarza <m.yarza"at/removethis"libelium.com>
*/

int wakePin = 2; // pin used for waking up

int sleepStatus = 0; // variable to store a request for sleep

int count = 0; // counter

int led = 7;

 

void wakeUpNow() // herethe interrupt is handled after wakeup

{

// execute code here afterwake-up before returning to the loop() function

// timers and code using timers(serial.print and more...) will not work here.

// we don't really need toexecute any special functions here, since we

// just want the thing to wakeup

 

Serial.println("presenciaen la zona de la escalera...");

 

digitalWrite(led,HIGH);

for(float i=0;i<10000;i++){}

digitalWrite(led,LOW);

 

}

 

void setup()

{

pinMode(wakePin, INPUT);

pinMode(led, OUTPUT);

Serial.begin(19200);

 

/* Now is time to enable ainterrupt. In the function call

* attachInterrupt(A, B, C)

* A can be either 0 or 1 forinterrupts on pin 2 or 3.

*

* B Name of a function youwant to execute while in interrupt A.

*

* C Trigger mode of theinterrupt pin. can be:

* LOW a lowlevel trigger

* CHANGE achange in level trigger

* RISING arising edge of a level trigger

* FALLING afalling edge of a level trigger

*

* In all but the IDLE sleepmodes only LOW can be used.

*/

 

attachInterrupt(0, wakeUpNow,RISING); // use interrupt 0 (pin 2) and run function

//wakeUpNow when pin 2 gets LOW

}

 

void sleepNow() // herewe put the arduino to sleep

{

/* Now is the time to set thesleep mode. In the Atmega8 datasheet

*http://www.atmel.com/dyn/resources/prod_documents/doc2486.pdf on page35

* there is a list of sleepmodes which explains which clocks and

* wake up sources areavailable in which sleep modus.

*

* In the avr/sleep.h file,the call names of these sleep modus are to be found:

*

* The 5 different modes are:

* SLEEP_MODE_IDLE -the least power savings

* SLEEP_MODE_ADC

* SLEEP_MODE_PWR_SAVE

* SLEEP_MODE_STANDBY

* SLEEP_MODE_PWR_DOWN -the most power savings

*

* For now, we want as muchpower savings as possible, so we

* choose the according

* sleep modus:SLEEP_MODE_PWR_DOWN

*

*/

set_sleep_mode(SLEEP_MODE_IDLE); // sleep mode is set here

 

sleep_enable(); //enables the sleep bit in the mcucr register

//so sleep is possible. just a safety pin

 

/* Now is time to enable ainterrupt. we do it here so an

* accidentally pushedinterrupt button doesn't interrupt

* our running program. ifyou want to be able to run

* interrupt code besides thesleep function, place it in

* setup() for example.

*

* In the function callattachInterrupt(A, B, C)

* A can be either 0 or 1for interrupts on pin 2 or 3.

*

* B Name of a function youwant to execute at interrupt for A.

*

* C Trigger mode of theinterrupt pin. can be:

* LOW alow level triggers

* CHANGE achange in level triggers

* RISING arising edge of a level triggers

* FALLING afalling edge of a level triggers

*

* In all but the IDLE sleepmodes only LOW can be used.

*/

 

attachInterrupt(0,wakeUpNow,RISING); // 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.

 

}

 

void loop()

{

 

 

sleepNow();

 

 

}

gallery.png
theGroup.png

barra_lateral/rss
Research
  • Enclosure
  • Energy Management
  • GPS Mesh Networks
  • Hardware Node
  • Manager Platform
  • Mesh Routing Protocols
  • Securing the Mesh
  • Sensor Integration
  • System and Communications
  • System and Manager Platform
barra_lateral/techM