[Solved] Problem with AH3503 hall sensor

Hi

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?

can you post a link to the datasheet of this sensor?

635 seems to be around 3V

If you remove the 10K resistor what does it do?

Datasheet: http://p.globalsources.com/IMAGES/PDT/SPEC/229/K1011923229.pdf

If I remove the resistor, everything goes to 0 no matter if I use a magnet or not

Can it be that you switched pins 1 and 3?

robtillaart:
Can it be that you switched pins 1 and 3?

Doh!!!

The back looks like it was the front. It works alot better the other way around :slight_smile:

Thx for helping me

just interested, what ranges do you get now?

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 :slight_smile:

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();
}