Can't read hall sensor output

I ordered these latching hall sensors (did not realize they were latching until I tested them out):

Then, I ordered this non latching sensor:

The latching sensors worked just fine. I was able to print out the output data just as I had expected in the code with a basic Serial.println(digitalRead(2));. I then tried the non latching sensor and I have yet to read anything from that sensor except a LOW signal. I've ordered two of these sensors now and neither one has worked.

I'm coming out of my 5v pin to the 5v (far left) input pin on the switch. Plugging my ground into the the middle pin, and I've plugged the far right 5v output pin into my digial pwm pin # 2. I've used this exact same circuit for both the non latching and latching sensors and I've only been able to get the latching sensor to work. Am I doing something wrong here? Or am I just getting bad sensors?

That sensor seems to have an open drain output, so you need a pull up resistor.

Easiest way is to enable the internal pull up resistor on that Arduino pin in void setup().

pinMode(2, INPUT_PULLUP);

Leo..

Wawa:
That sensor seems to have an open drain output, so you need a pull up resistor.

Easiest way is to enable the internal pull up resistor on that Arduino pin in void setup().

pinMode(2, INPUT_PULLUP);

Leo..

This worked! Thanks!!!!!!!

The first sensor is based on the Allegro Microsystems A1302 and is not described in the datasheet as a latching sensor. It is a magnetic sensor with a linear output.

The second sensor is based on the Melexis US5881 and is a low sensitivity sensor that requires:

  1. Proper positioning of the correct magnetic pole.

  2. A pullup resistor. This could be the pullup resistor internal to the Arduino. There is no code and there is no mention of a pullup resistor so I would guess that this is missing. I hate having to guess.

The sensors may be good.

datasheet