Pages: [1]   Go Down
Author Topic: Help setting up Hall Effect Sensor A3144  (Read 6644 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 49
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am interested in hall effect sensors to read the presence of a magnet.  I have purchased a set of 10 A3144's and I am having a hard time getting them to read a value.

I found documentation here http://iteadstudio.com/store/images/produce/Sensor/Hall_Effect_Sensor/A3144EU_IC-ON-LINE.CN.pdf, but I must admit that I am not the most knowledgable user here.

This seems like it should be a simple setup.  
Pin one = 5v
Pin two = Ground
Pin 3 = Digital Pin2 on arduino

I have a pretty powerful magnet, and no matter what I do, or what angle I approach the sensor, digital read is always returning 0, even with the magnet out of range.

Is there anything obvious that I am missing?  Does anyone out there have any experience with this type of component?

Code:
int sensorPin = 2;
int counter = 0;

void setup()
{
  // setup serial - diagnostics - port
  Serial.begin(9600);
  pinMode(sensorPin, INPUT);
}

void loop()
{
  counter++;
  int sensorValue = digitalRead(sensorPin);
  Serial.print(counter);
  Serial.print(" ");
  Serial.println(sensorValue);
  delay(1000);
}
« Last Edit: February 13, 2012, 01:37:52 am by roaming_builder » Logged

Montreal
Online Online
Faraday Member
**
Karma: 29
Posts: 2590
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Open-Collector 25 mA Output ... Compatible with Digital Logic
You need pull-up resistor, external between input and +5V or you could activate internal,
look here : http://arduino.cc/en/Reference/DigitalWrite
Logged

Chile
Offline Offline
Sr. Member
****
Karma: 0
Posts: 260
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This sensors are magnet pole sensitive. After implementing the pull up resistor as the other post stated, try it using the different sides of your magnet.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This sensors are magnet pole sensitive. After implementing the pull up resistor as the other post stated, try it using the different sides of your magnet.


That is not correct, at least for that device. Switching on and off happens at a certain gauss value (+/- hystrisis value), it is not sensitive to the magnetic polarity of the field. The OP just needs to provide a pull-up to the proper voltage for the device to operate.

 From the datasheet:

Quote
The output of these devices (pin 3) switches low when the magnetic field
at the Hall sensor exceeds the operate point threshold (BOP). At this point, the
output voltage is VOUT(SAT). When the magnetic field is reduced to below the
release point threshold (BRP), the device output goes high. The difference in
the magnetic operate and release points is called the hysteresis (Bhys) of the
device. This built-in hysteresis allows clean switching of the output even in
the presence of external mechanical vibration and electrical noise.

Lefty
Logged

0
Offline Offline
Shannon Member
****
Karma: 206
Posts: 12179
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Poor datasheet - its really unclear if its sensitive to B or |B|
Logged

[ I won't respond to messages, use the forum please ]

0
Offline Offline
Newbie
*
Karma: 0
Posts: 49
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Perfect!

Thanks for the help Magician, and all.

That worked perfectly.  Was it the "Open Collector" that gave you that answer?  I am a bit noobish here.  That was much simpler than I thought it was going to be.

It turns out that the sensor is sensitive to polarity.  One side will read a north value, and one will read a south value, not that I know which side is which =)

A side question about the programming.  I have the code below, and if you read it you might be able to see what I am trying to do.  Basically, I want to do "something" when the magnet is detected and when it leaves, non-repeating.  Right now it is just printing a message, and it is trivial.  I am just trying to learn more about this type of development.  I am a programmer by trade, but this type of programming is completely new to me. 

It would be very easy to tie up the processor waiting for the event to occur, but that would mean that nothing else could happen while we were waiting for the events.  What I have works perfectly for now, but I was wondering if anyone had a more "elegant" way of doing this.  Basically my if statements in the loop method.

If I lost you with my explanation, let me know that too, it has been a long day =)

Quote
int sensorPin = 2;
int counter = 0;
boolean sensorState = false;

void setup()
{
  // setup serial - diagnostics - port
  Serial.begin(9600);
  pinMode(sensorPin, INPUT);
  digitalWrite(sensorPin, HIGH);
}

void loop()
{
  if(magnetPresent(sensorPin) && !sensorState)
  {
    sensorState = true;
    printMessage("Magnet Present");
  }
  else if(!magnetPresent(sensorPin) && sensorState)
  {
    sensorState = false;
    printMessage("Magnet Gone");
  }
}

void printMessage(String message){
  counter++;

  Serial.print(counter);
  Serial.print(" ");
  Serial.println(message);
//  delay(1000);
}

boolean magnetPresent(int pin){
  return digitalRead(pin) == LOW;
}

Logged

Montreal
Online Online
Faraday Member
**
Karma: 29
Posts: 2590
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It would be very easy to tie up the processor waiting for the event to occur, but that would mean that nothing else could happen while we were waiting for the events.
That isn't quite correct, "if/else" statement doesn't hold program from running, and code "reasonable" when main "loop" isn't too big and there is no "delay" inside. Of course, there is always way to improve something, try to experiment with http://arduino.cc/en/Reference/AttachInterrupt for starting, "falling" interrupt would save couple instruction in current code, and increase "responsiveness" for fast varying magnetic fields.
Logged

Oslo
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Open-Collector 25 mA Output ... Compatible with Digital Logic
You need pull-up resistor, external between input and +5V or you could activate internal,
look here : http://arduino.cc/en/Reference/DigitalWrite
Thank you thank you thank you.

You made my month, even though it stupid that I didn't try to set the resistor into 5v....
Logged

Jan Ole

Pages: [1]   Go Up
Jump to: