# Hall effect sensor and floating pin value

**URL:** <https://forum.arduino.cc/t/hall-effect-sensor-and-floating-pin-value/660255>\
**Category:** Sensors\
**Created:** [June 12, 2020, 2:33am UTC](https://forum.arduino.cc/t/hall-effect-sensor-and-floating-pin-value/660255 "2020-06-12T02:33:26Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![sriddle](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@sriddle](https://forum.arduino.cc/u/sriddle)\
**Post date:** [June 12, 2020, 2:33am UTC](https://forum.arduino.cc/t/hall-effect-sensor-and-floating-pin-value/660255/1 "2020-06-12T02:33:26Z")

</div>

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](https://www.ebay.com/itm/Ultimate-37-in-1-Sensor-Modules-Kit-for-Arduino-MCU-Education-User-Free-case/191743211102?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2057872.m2749.l2649)

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

}

 ![Hall Sensor.jpg](https://europe1.discourse-cdn.com/arduino/original/4X/4/0/6/406b3b2c8e852163369b32a77a3b2ce1f76f4012.jpeg)

---

<div class="post-metadata">

**Author:** ![cattledog](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cattledog/32/217816_2.png) [@cattledog](https://forum.arduino.cc/u/cattledog)\
**Post date:** [June 12, 2020, 2:49am UTC](https://forum.arduino.cc/t/hall-effect-sensor-and-floating-pin-value/660255/2 "2020-06-12T02:49:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![JCA34F](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jca34f/32/340148_2.png) [@JCA34F](https://forum.arduino.cc/u/JCA34F)\
**Post date:** [June 12, 2020, 10:23am UTC](https://forum.arduino.cc/t/hall-effect-sensor-and-floating-pin-value/660255/3 "2020-06-12T10:23:53Z")

</div>

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

```cpp
pinMode(hallSensorPin, INPUT_PULLUP);

```

---

<div class="post-metadata">

**Author:** ![Ron\_Blain](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ron_blain/32/1126393_2.png) [@Ron\_Blain](https://forum.arduino.cc/u/Ron_Blain)\
**Post date:** [June 12, 2020, 12:15pm UTC](https://forum.arduino.cc/t/hall-effect-sensor-and-floating-pin-value/660255/4 "2020-06-12T12:15:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sriddle](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@sriddle](https://forum.arduino.cc/u/sriddle)\
**Post date:** [June 12, 2020, 8:29pm UTC](https://forum.arduino.cc/t/hall-effect-sensor-and-floating-pin-value/660255/5 "2020-06-12T20:29:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cattledog](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cattledog/32/217816_2.png) [@cattledog](https://forum.arduino.cc/u/cattledog)\
**Post date:** [June 12, 2020, 9:11pm UTC](https://forum.arduino.cc/t/hall-effect-sensor-and-floating-pin-value/660255/6 "2020-06-12T21:11:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sriddle](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@sriddle](https://forum.arduino.cc/u/sriddle)\
**Post date:** [June 12, 2020, 9:24pm UTC](https://forum.arduino.cc/t/hall-effect-sensor-and-floating-pin-value/660255/7 "2020-06-12T21:24:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cattledog](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cattledog/32/217816_2.png) [@cattledog](https://forum.arduino.cc/u/cattledog)\
**Post date:** [June 12, 2020, 9:46pm UTC](https://forum.arduino.cc/t/hall-effect-sensor-and-floating-pin-value/660255/8 "2020-06-12T21:46:49Z")

</div>

```cpp
 pinMode(hallSensorPin, INPUT_PULLUP);

```

---

<div class="post-metadata">

**Author:** ![sriddle](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@sriddle](https://forum.arduino.cc/u/sriddle)\
**Post date:** [June 12, 2020, 9:49pm UTC](https://forum.arduino.cc/t/hall-effect-sensor-and-floating-pin-value/660255/9 "2020-06-12T21:49:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sriddle](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@sriddle](https://forum.arduino.cc/u/sriddle)\
**Post date:** [June 12, 2020, 10:05pm UTC](https://forum.arduino.cc/t/hall-effect-sensor-and-floating-pin-value/660255/10 "2020-06-12T22:05:54Z")

</div>

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

Scott

---

<div class="post-metadata">

**Author:** ![Ron\_Blain](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ron_blain/32/1126393_2.png) [@Ron\_Blain](https://forum.arduino.cc/u/Ron_Blain)\
**Post date:** [June 12, 2020, 10:59pm UTC](https://forum.arduino.cc/t/hall-effect-sensor-and-floating-pin-value/660255/11 "2020-06-12T22:59:53Z")

</div>

> 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. 🙂 Mistakes along the way are all part of a learning curve.

Ron

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 10:29am UTC](https://forum.arduino.cc/t/hall-effect-sensor-and-floating-pin-value/660255/12 "2021-05-06T10:29:39Z")

</div>


