Hall effect sensor and floating pin value

I picked up a hall effect sensor from Ebay in one of the 37 sensor packs and I am having problems reading a stable value from it. I have it wired to grnd and +5v and to digtial pin 2. There is a led on pin 13 to show if it is off or on. The sensor has a led on it as well. I do a serial print of the state and have done it with out the delay and with to see if it settles down. With out the delay my state is all over the place, random 0’s and 1’s. With the delay it is a bit more stable but it still changes state. This all happens when the sensor is not near a magnet and the led on the sensor is off. If I put it near a magnet, the sensors led comes on and I see a consistent state of 0.
How can I pull the pin 2 value to 1 all the time while the sensor is not by a magnet. Do I need to add an additional resistor in some where and pull it up or down (grnd or +5v )?

Here is a link to where I got it from on Ebay: Link

Code I am using:

int hallSensorPin = 2;
int ledPin = 13;
int state = 0;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(hallSensorPin, INPUT);
Serial.begin(9600);
}

void loop() {

state = digitalRead(hallSensorPin);
Serial.println(state);
delay (200);

}

I think that is an voltage output (analog) sensor, and not a digital output sensor. Try reading the output with analogRead() on one of the A pins.

Many HESs have NPN open collector outputs that pull LOW when activated and float when not. Try:

pinMode(hallSensorPin, INPUT_PULLUP);

I see two Hall Sensor modules, one called a linear and one module looks to be a hall sensor and nothing else. I agree with JCA4F in that the sensor (not the linear one) is likely an open collector type and should that be correct it will need a pullup resistor. That or set an internal pullup on your Arduino. Can you see any part number on the chip itself?

Ron

The one I have been using has 44E 402 on the sensor. The other one I got, which I think is the analog one but may be wrong, has 49E 689BG on it.

Scott

The one I have been using has 44E 402 on the sensor. The other one I got, which I think is the analog one but may be wrong, has 49E 689BG on it.

I think you are correct, and the 44E 402 has open collector output requiring a pull up resistor on the output. Using the internal pullup resistor enabled with INPUT_PULLUP for pinMode is usually sufficient.

Do you some example code on how to do that? I am pretty new to Arduinos and I get the idea but the code is still new to me.
Thanks
Scott

 pinMode(hallSensorPin, INPUT_PULLUP);

I think i have figured out my problem. A total newbie mess up. I had my + power wire plugged into the 3.3 V pin not the +5 pin. once I did that I get solid 1's or 0's. I did some reading on some data sheets and it talked about a mid voltage range that it is not determinate in and would give erractic results, just like I was seeing. Give it 5 and life is good.
Thanks so much for every ones help on this one. i learned a ton on hall effect sensors. I am on my way.

Scott

Thanks CattleDog. I will keep that pullup code in my back pocket as I think it will come in handy else ware.

Scott

sriddle:
I think i have figured out my problem. A total newbie mess up. I had my + power wire plugged into the 3.3 V pin not the +5 pin. once I did that I get solid 1's or 0's. I did some reading on some data sheets and it talked about a mid voltage range that it is not determinate in and would give erractic results, just like I was seeing. Give it 5 and life is good.
Thanks so much for every ones help on this one. i learned a ton on hall effect sensors. I am on my way.

Scott

Glad it worked out. When you can read a number and get a little lucky Google is a friend. :slight_smile: Mistakes along the way are all part of a learning curve.

Ron