Recently I purchased the following Hall switch sensor from farnell (UK component shop):
I have been experimenting with the sensor and have found it to not behave in any way you'd expect it to.
Below I have uploaded 4 videos showing my experiments. The arduino is set up to turn the LED on when the signal coming from the "hall switch" is low, in other words, the output that should occur when a magnetic field greater than the sensors threshold is present.
/*
* Hall switch test
* Turns on and off an LED connected to pin 13 when passing a magnet by the hall switch connected to pin 2
*/
int ledpin = 13; //Pin for LED
int hallpin = 8; //Pin for Hall switch
int val = 0; //Integer for reading Hall status
void setup(){
pinMode(ledpin, OUTPUT); //Declare LED pin as output
pinMode(hallpin, INPUT); //Declare Hall pin as input
}
void loop(){
val = digitalRead(hallpin); //Read Hall pin status
if (val == HIGH){ //If there is no magnet infront of Hall switch...
digitalWrite(ledpin, LOW); //Turn LED off
}
else{ //Otherwise...
digitalWrite(ledpin, HIGH); //Turn LED on
}
}
Experiment 1
The sensor appears to be unaffected by the magnet, but will switch to low output when a hand is brought into close proximity
Experiment 2
The same result is seen when the sensor is covered with an opaque bag (although some light can enter through the bottom)
Experiment 3
The sensor also switches to low output when hot air is blown onto it
Experiment 4
Perhaps the strangest result...
The sensor seems to switch low when I place my hand infront of my desk lamp
I am posting this to seek clarification on what sensor I have received, as I am now certain it is not a hall switch. Is it some sort of capacitive sensor? Or some sort of magic hand sensor?
Remove that resistor and wire your +5vdc breadboard voltage directly to the Vcc pin of the hall sensor.
Why did you think you needed a series resistor? Perhaps you meant to wire the resistor as a pull-up by
wiring it between the sensor signal and Vcc pins. But you have it in series with +5vdc?
The signal output from the sensor is a open drain type output, meaning that there is a pull-up resistor
required. The easist way to implement it is to just enable the internal pull-up for your input pin. Or you could
wire the removed resistor above and wire it correctly between signal and Vcc pins.
So in your setup function you have a:
pinMode(hallpin, INPUT); //Declare Hall pin as input
Add this after that command:
digitalWrite(hallpin, HIGH) // turn on internal pull-up
Try those two changes and get back to us if it's working or not.
I realise now that I had the resistor in the wrong place; I was following a similar digital input problem that came with my starter-kit and is also here:
Here they describe a pull-up resistor being placed between the Vsource and Vin of the button.
If I use the "digitalWrite(hallpin, HIGH);" line in the code, the LED is permanently on, with or without the pull-up resistor in the correct location
With the pull-up resistor in the correct location (and I used a higher resistance of 10kohms this time as suggested here): Arduino Playground - ReadingRPM
I can now trigger the hall switch with a magnet. However, I can also trigger it by moving my hand into close proximity.
5th experiment
Referring to my 4th video, where when I squeeze my desklamp the LED turns on. If I then ground myself through my laptop in my other hand, the LED does not turn on. I can actually do this with my friend holding the lamp, me holding my friends hand, and then touching the laptop.
I also don't see a series resistor wired to your led going to pin 13? You should either remove the led and just watch the on-board pin 13 led, or wire in a series with a resistor of say 200-500 ohms. You are in danger of destroying your output pin 13 as it is screaming in pain every time you turn it on.
I did not realise. I have now added a resistor between the Vsource and the LED.
I have 3 magnets. If I leave the weakest of the 3 magnets near the sensor the LED remains on. If I use any of the stronger magnets the LED remains off. If I touch my laptop, the LED turns off. I should note, that the arduino is being powered by my laptop currently. Whatever is happening, the problem is unfortunately still not solved.
I can't explain all the wavy hands and proximity stuff you are seeing. I have used that same sensor and it just worked as expected.
Perhaps you should add a bypass filter capacitor of .1ufd (or larger) between the hall effects Vcc pin and ground pin. I don't see anything wrong with your sketch.
Edit: You might try using a diffenet output pin for the led and change your code to match as maybe you damaged the pin 13.
Thankyou for your help anyway. With regards to your edit I already thought to try a different LED output pin, and the same results occur.
I guess I'll wait and see if Jd.steinberger has anything to suggest if he had a similar problem.
If there is no resolve, I still have reason to suspect I may of been sent an incorrect sensor model and I may return it. If you still have yours available could you let me know what markings it had on it?
If you still have yours available could you let me know what markings it had on it?
I bought my Allegro hall effect sensors about a year ago from an E-bay seller. I bought both 5 each of their analog sensor and switch sensor. Part number and device markings are:
Allegro analog hall sensor part # A1323LUA-T Device marking = 23L
Allegro digital switch sensor part # A3213EWA Device marking = 13E
retrolefty:
2. The signal output from the sensor is a open drain type output, meaning that there is a pull-up resistor
required. The easist way to implement it is to just enable the internal pull-up for your input pin. Or you could
wire the removed resistor above and wire it correctly between signal and Vcc pins.
Lefty, thanks for pointing this out. I just made a PCB without the knowledge of the output is open-drain. Glad that ATMEGA has internal pull-ups. I'm going to use the internal pull-up for sure.
In case any one stumbles upon this thread looking for a solution themselves, the problem was that the sensor required a resistor to be placed between the Vin and Vcc ports. With this in place, the sensor is functional.
Glad you got it working, in over 30 years I have never known Farnell to send a wrong part.
was that the sensor required a resistor to be placed between the Vin and Vcc ports. With this in place, the sensor is functional.
That resistor is called a pull up resistor, it was mentioned several times. Note that enabling the internal pull up resistors would have been a solution as well. This is done by doing a digitalWrite HIGH to the input pin you are using.