As I mentioned yesterday, I’m currently testing a new sensor: the Allegro A3214 Hall-Effect switch. This very small sensor looks like a very good candidate for my own Door & Window sensors. A sample of this sensor was given to me by Jean-Claude Wippler a few weeks ago, and now that I’m waiting for some Mantis parts I ordered and have no more time to spend on the Arduino Workshop, it was time for something new.
Some characteristics of the A3214:
- 2.4 to 5.5V battery operation
- minimal power requirements
- pole independent switching
- small size
How small is small??
The magnet (upper left) measures 3x3x3 mm, the sensor dimensions are 4 x 3 x 1.5 mm. Yep, that’s really small
First thing I did yesterday, was putting this sensor on a breadboard and connecting it to a JeeNode. I wrote a small sketch that used LED2 of the Bridge Board to visually show the status of the sensor output:
#include <Ports.h>
#include <RF12.h>
Port one (1);
Port four (4);
void setup() {
one.mode(OUTPUT); // LED2 of Bridge Board is connected to Port 1 Digital.
four.mode(INPUT); // the sensor is connected to Port 4.
four.digiWrite(HIGH); // enable pullup
}
void loop() {
one.digiWrite(four.digiRead());
}
It worked, wow! Moving the magnet towards the sensor made the LED go off (the output is high when the magnetic field isn’t strong enough), moving the magnet away made the LED go on again. The distance between sensor and magnet when the output value changes is approx. 10 mm.
Today I wanted to do some power usage measurements, so I changed the sketch a bit:
#include <Ports.h> #include <RF12.h> // needed to avoid a linker error#include <Sleep.h> #define DEBUG 0 int INTpin = 3; Port one (1); volatile boolean wdt_expired=0; // Interrupt Serive Routine that will be executed when the Watchdog Timer expired. ISR(WDT_vect) { wdt_expired=1; } //**************************************************************** // 0=16ms, 1=32ms,2=64ms,3=128ms,4=250ms,5=500ms // 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec void setup_watchdog(int ii) { byte bb; int ww; if (ii > 9 ) ii=9; bb=ii & 7; if (ii > 7) bb|= (1<<5); bb|= (1<<WDCE); ww=bb; MCUSR &= ~(1<<WDRF); // start timed sequence WDTCSR |= (1<<WDCE) | (1<<WDE); // set new watchdog timeout value WDTCSR = bb; WDTCSR |= _BV(WDIE); } void setup(void) { pinMode(INTpin, INPUT); digitalWrite(INTpin, HIGH); one.mode(OUTPUT); // LED2 of Bridge Board is connected to Port 1 Digital. #if DEBUG Serial.begin(9600); #endif } void loop(void) { #if DEBUG Serial.print(millis(), DEC); Serial.print(" I'm awake, caused by "); #endif if (wdt_expired==1){ wdt_expired=0; #if DEBUG Serial.println("the WDT"); #endif // Do something, like sending a heatbeat // sometimes } else { // External interrupt triggered! byte val = digitalRead(INTpin); // disable LED during power measurements //one.digiWrite(val); #if DEBUG Serial.print(val, DEC); Serial.println(" INT0"); Serial.print("Doing some serious stuff now..."); #endif // measure awake delay(5000); #if DEBUG Serial.println("finished!"); #endif } // #if DEBUG Serial.print(millis(), DEC); Serial.println(" Sleeping..."); delay(100); // wait for serial to finish #endif // go to sleep and wake up // on watchdog or IRQ pin change setup_watchdog(9); Sleep.powerDownAndWakeupExternalEvent(1, CHANGE); // sleep function called here }
- JeeNode awake: 7 mA;
- JeeNode asleep, magnet in range of sensor: 38 μA;
- JeeNode asleep, magnet out of range: 14 μA.
That’s very good… I’m sure this power usage will be good enough to live on 1 set of AA batteries for a long time.
Of course, Door & Window sensors is the most obvious application for these sensors. But the small size makes me wonder if I can come up with more useful ideas…
On to the next step!











Recent Comments