Maker Pro
Maker Pro

Hall Effect Sensor issues

elementcollector1

Feb 23, 2014
24
Joined
Feb 23, 2014
Messages
24
(Feel free to move this topic if it belongs in a more appropriate location.)
I've been programming on my Arduino, and have ran into an odd problem with my Hall Effect Sensors (ratiometric, model A1302). By all accounts, they seem to work - a quick circuit featuring an LED dimmed and brightened appropriately when a neodymium magnet was moved further and closer from each sensor. However, when I attempt to integrate these sensors into my Arduino programs, they begin acting very strange. The most recent error involved a reading of 509, which seems about right for not having a magnet near it. However, when a magnet *is* placed near it... There is no change whatsoever. It continues to read 509, despite all attempts to fix the issue. Any ideas on how to fix this, or should I just get some new sensors?
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Show us (a) the circuit you use with a LED, and (b) the way you're interfacing it to an input pin on the Arduino.

And I'll move this to the appropriate place :)
 

elementcollector1

Feb 23, 2014
24
Joined
Feb 23, 2014
Messages
24
Sure! Here are some pictures of the circuit in question:
tumblr_n1fmx9OsTV1t4jo74o2_250.jpg

You can see the Hall Effect Sensor connected to 4.5V DC and GND. The LED is connected to 4.5V and the output pin of the HES.
Here's a 'dim' shot, with the magnet about as far away as it can get with the light still showing...
tumblr_n1fmx9OsTV1t4jo74o5_250.jpg

Here's a brighter image, from moving the magnet closer:
tumblr_n1fmx9OsTV1t4jo74o4_250.jpg

The brightness of the LED varies pretty proportionally with the distance of the neodymium magnet to the sensor, to a cutoff of roughly 1/4" away. Even more oddly, this used to be much more sensitive, usually sensing this magnet from at least 1/2" away, if memory serves correctly.

As for the way I am attempting to interface to the Arduino, the output is attached to the analog pin A0 on the Arduino, with the other pins going to 5V and GND respectively. The LED is connected to pin D3. The code I am trying to use is below:
int hallPin = A0;
int HallState = 0;
int lightPin = 3;
void setup()
{
pinMode(hallPin, INPUT);
pinMode(lightPin, OUTPUT);
HallState = analogRead(hallPin);
Serial.begin(115200);
}
void loop()
{
Serial.println(HallState);
delay(100);
if (HallState>600)
{
digitalWrite(lightPin, HIGH);
}
}
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Try this:

Code:
int hallPin = A0;
int HallState = 0;
int lightPin = 3;

void setup()
{
  pinMode(hallPin, INPUT);
  pinMode(lightPin, OUTPUT);

  Serial.begin(115200);
}

void loop()
{
  HallState = analogRead(hallPin);
  Serial.println(HallState);

  if (HallState>600)
  {
    digitalWrite(lightPin, HIGH);
  }

  delay(100);
}

You were only reading the hall sensor once.
 

elementcollector1

Feb 23, 2014
24
Joined
Feb 23, 2014
Messages
24
Try this:

Code:
int hallPin = A0;
int HallState = 0;
int lightPin = 3;

void setup()
{
  pinMode(hallPin, INPUT);
  pinMode(lightPin, OUTPUT);

  Serial.begin(115200);
}

void loop()
{
  HallState = analogRead(hallPin);
  Serial.println(HallState);

  if (HallState>600)
  {
    digitalWrite(lightPin, HIGH);
  }

  delay(100);
}

You were only reading the hall sensor once.

Forgot to add an 'else digitalWrite(lightPin, LOW)' in there, but now it works perfectly, thanks! Both of my Hall Effect sensors work fine.
 
Last edited:
Top