Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8621

Beginners • pir sensor value never goes to 0

$
0
0
I'm trying to read a pir sensor (chinese am312) with a pico 2 but it always outputs 1 and never gets to 0, but if I try to read the same pin number as a analogue value it works properly. I tried adding external resistors to ground, changing the input pin used but nothing worked.

the code I'm using to test normal pin behavior that always detects the val as being 1

Code:

from machine import Pinimport timepir = Pin (28, Pin.IN, machine.Pin.PULL_DOWN)led0 = Pin ("LED", Pin.OUT)while True:  val = pir.value ()  print (f"val is {val}")  time.sleep (1)
vs analogue version that works and outputs either 500~1000 when movement isn't detected or >65000 when there is movement

Code:

from machine import Pin,ADCimport timepin = ADC (Pin (28))led0 = Pin ("LED", Pin.OUT)while True:    val = pin.read_u16 ()    print (f"{val}")    if (val > 30000):        led0.on ()    else:        led0.off ()    time.sleep (0.1)
any help would be appreciated

Statistics: Posted by tiotags — Fri Jan 02, 2026 11:05 am



Viewing all articles
Browse latest Browse all 8621

Trending Articles