I have a AH3503 hall sensor to my UNO in analog0 and just doing a simple read.
When doing nothing I have a reading around 635-638, which sounds ok. Now when I place some metal in front of it or even a magnet, it only goes up by 2-3, the highest I have seen is 641.
I have connected it like this
and this is my code
void setup()
{
Serial.begin(9600);
}
void Measurement()
{
int raw = analogRead(0); // Range : 0..1024
Serial.print("Output: ");
Serial.println(raw);
}
void loop()
{
delay(1000);
Measurement();
}
Can't be more simple than that I think. What could I be doing wrong and shouldn't I get a much higher reading almost no matter what I put in front of it?
robtillaart:
just interested, what ranges do you get now?
I get up to +/-350 from the midpoint when the magnet is sitting on the sensor. I actually hoped it would be more sensitive and that it was able to measure when metal was close to it, but that's probably the way the sensor works.
Just wanted to post my last code if anyone else want to play with it. Didn't find that many examples on the net.
The sensors are not all equal, so this finds the midpoint when starting up and then shows the difference when its more or less than 2. Tweak it to your liking
int mid;
int diff = 2;
int raw;
int calruns = 10;
unsigned long calibration = 0;
void setup()
{
Serial.begin(9600);
findmid();
}
void Measurement()
{
raw = analogRead(0); // Range : 0..1024
if(raw < mid-diff || raw > mid+diff)
{
Serial.print("Output: ");
Serial.println(raw-mid);
}
}
void findmid()
{
delay(100);
Serial.println("Setting up... Please wait");
for(int i = 0; i < calruns; i++)
{
raw = analogRead(0);
calibration = calibration + raw;
delay(200);
}
mid = calibration / calruns;
Serial.print("Midpoint found at ");
Serial.println(mid);
Serial.println("Ready:");
}
void loop()
{
delay(25);
Measurement();
}