Pages: [1]   Go Down
Author Topic: Problem using a "Hall switch"  (Read 1883 times)
0 Members and 1 Guest are viewing this topic.
United Kingdom
Offline Offline
Newbie
*
Karma: 1
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Recently I purchased the following Hall switch sensor from farnell (UK component shop):

http://uk.farnell.com/allegro-microsystems/a1101eua-t/hall-effect-switch-sip-3-1101/dp/1198078

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.

Code:
/*
 * 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
http://youtu.be/D3E9Gl55wl8
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
http://youtu.be/IC5K88AgcaE
The same result is seen when the sensor is covered with an opaque bag (although some light can enter through the bottom)

Experiment 3
http://youtu.be/EMTKCNDFil8
The sensor also switches to low output when hot air is blown onto it

Experiment 4
http://youtu.be/TiJkIAZWlic
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?


Logged

Texas
Offline Offline
Jr. Member
**
Karma: 1
Posts: 97
Eso es lo que es
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Post a circuit diagram so I can see how you've got it wired.  I had a similar problem with my hall switch before and realized it was wired incorrectly.

Also, have you made sure you have the south pole of the magnet facing the switch, and not the north?
Logged

United Kingdom
Offline Offline
Newbie
*
Karma: 1
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is the best representation I could come up with on "Fritzing"
Imagine that the 3 pin component is the Hall switch



And with regards to the magnet polarity question, I have tried positioning the magnet in every orientation possible.
« Last Edit: January 30, 2011, 10:54:45 am by davidbrowne » Logged

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

Ok I think you have two problems:

1. 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?

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.

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.

Lefty
« Last Edit: January 30, 2011, 12:48:06 pm by retrolefty » Logged

United Kingdom
Offline Offline
Newbie
*
Karma: 1
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
http://www.arduino.cc/en/Tutorial/Pushbutton
Here they describe a pull-up resistor being placed between the Vsource and Vin of the button.

1) 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
2) With the pull-up resistor in the correct location (and I used a higher resistance of 10kohms this time as suggested here):
http://www.arduino.cc/playground/Main/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.

Logged

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

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.

Lefty
« Last Edit: January 30, 2011, 01:26:32 pm by retrolefty » Logged

United Kingdom
Offline Offline
Newbie
*
Karma: 1
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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

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.

Quote
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.

Lefty
 
« Last Edit: January 30, 2011, 01:48:50 pm by retrolefty » Logged

United Kingdom
Offline Offline
Newbie
*
Karma: 1
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

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

Quote
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


Lefty         
Logged

Texas
Offline Offline
Jr. Member
**
Karma: 1
Posts: 97
Eso es lo que es
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1294620858/15

Check out the 6th post down by pwillard.

I don't have time to read all the posts right now or check your datasheet, maybe you've already tried this.
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 64
Posts: 6889
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


United Kingdom
Offline Offline
Newbie
*
Karma: 1
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 508
Posts: 31397
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Glad you got it working, in over 30 years I have never known Farnell to send a wrong part.

Quote
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.
Logged

Cumming, GA
Offline Offline
Edison Member
*
Karma: 18
Posts: 1627
Ultimate DIY: Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Just to be a little helpful here, I have attached the drawing for future reference.



* hall.jpg (15.82 KB, 577x273 - viewed 46 times.)
Logged

Pages: [1]   Go Up
Jump to: