Reading In Values

I have a HC-SR501 PIR MOTION DETECTOR that states the motion trigger will send out High 3.3 V /Low 0V, however, when I read the value in (A3) the value I get back ranges from 253 to 266. I can get it to jump up to over 2000 when it detects motion. I was expecting more of a low or high type reading.
I assume that high/low type reading would be a digital (D7) type value, so I changed to that, but found that without movement, the low to high value would change on without movement. I tried two different PIR sensor modules and they both behave in the same manner. I’m just wondering if I’m expecting the wrong values or using the wrong input pin for this sort of task.

Hi @jdugat

I think your module needs a pull-up resistor, such as 4.7 k ohm to +3.3V, on the output. A lot of these inexpensive modules have an open-collector style output.

You should be using digitalRead(D7) to get the value–there is no point in using an analogRead and all the analog inputs are also digital inputs.

Also, how are you powering the sensor? The data sheet says in one place 4.5-20VDC and 5-20VDC in another. If you’re powering a Photon with USB, VIN can be used as a power output and is around 4.8VDC. That might work. 3V3 is definitely too low of a voltage.

1 Like

I have it powered separately with a 5 VDC source. Not using the Electron as a power source.

So, I need a 4.7 K resistor between the +3.3 v signal output pin on the PIR and the D7 pin on the Electron?

Hi @jdugat

Make the grounds are connected between the separate +5V supply and the Photon first.

If that doesn’t work, try a 4.7k ohm from your input (D7) to +3.3V.

What about the built-in pull-up resistor?