I’m working on a little project to help my dog find the stairs up to the bed at night. I have a Pimoroni Plasma2040 to drive the LEDs, a VCNL4020 proximity/ambient sensor so the lights only are turned on when it’s dark in the room, and an Adafruit passive infrared motion sensor to detect motion. I’m using circuitpython / Mu as the IDE, as that has easy-to-use libraries for the VCNL4020.
The code to check for lights on/off is easy. I’m stuck, though, in reading the PIR sensor via the Plasma2040. The VCC for the sensor is connected to the 5V out line, ground to ground, and the sensor out line is connected to the SWD pin on the Plasma2040. I think I should be able to use this bit of code to see if the sensor is triggered:
import board
import adafruit_rgbled
import time
import digitalio
led = adafruit_rgbled.RGBLED(board.LED_R, board.LED_G, board.LED_B, invert_pwm=True)
pir = digitalio.DigitalInOut(board.DATA)
pir.direction = digitalio.Direction.INPUT
pir.pull = digitalio.Pull.DOWN
led.color = (05,07,07) # make sure we're talking to board
time.sleep(3)
while True:
if pir.value == True:
print("LED On", pir.value)
led.color = (255, 0, 255)
time.sleep(5)
else:
print("Waiting for movement", pir.value)
led.color = (0,0,0)
time.sleep(1)
However, the sensor never changes state. I’ve tried two different sensors in case one is bad and my DVM tells me there’s voltage across the sensor.
Am I reading this pin incorrectly, or should I be using a different pin on the Plasma2040?