The Allegro A3214 Hall-Effect Switch

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??

This is small!

Allegro A3214

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
}
The A3214 output was moved to an external interrupt pin, I disabled LED2 and wrote down the power usages with the JeeNode, Bridge Board and A3214 connected to a 3 x AA battery pack producing 4.1 V:
  • 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!

Small, smaller, smallest?

Really small...Sensors that are used a lot in the house, can’t be small enough in my opinion. As long as it’s not SMD, I know I can handle it. And where possible, I want my sensors to be as invisible as possible of course. In the lower right part of the image there’s a new sensor, connected to a Bridge Board & JeeNode. This is small enough I’d think! This is the first time I have this sensor on a breadboard for testing; the next couple of days I hope to find some time to do more tests with this sensor and explain what it actually is and what it can be used for. The first results are encouraging! That’s all for now 🙂

Adding the end-stops

Sometimes it’s good to follow a certain path to a goal; not skipping those less interesting things that have to be done to build something that’s really finished. That’s why I decided to not go rushing towards building something  asap with the Mantis, but take one step at a time; all the steps! One of those is adding end-stops to the 3 axes. The Ultimaker board has 6 screw terminals to which you can connect switches; in this case, micro switches. Each axis can be ‘protected’ by 2 micro-switches, so that the stepper motor will automatically be halted by the software when a limit is reached. Sounds like a good idea to implement, so I did, although I was tempted to skip it – I want to see the Mantis building something! I have to restrain myself, or I’ll end up with a partly finished “thing”; and we all know what happens next with those.. nothing!

So I didn’t skip adding these end-stops, cause I know that if I skip this step now, I’ll never do it.

X- end stop Z- end stop

So no rush, taking it one step at a time… and to be honest, with the current weather conditions I don’t really feel like starting a garden irrigation project anyway! 🙂