@Serimner Some time ago, when I was making my mirrors, I’d tried some PIR modules, and I could not make it work any of them. So, I’d write this python script and works perfect. Hope it helps:
#!/usr/bin/python3
# PACKAGES NEEDED TO WORK: sudo apt install python3 python3-rpi.gpio
# My screen has an USB port, that turns on when screen is on, and off when screen is off.
# So, I made a voltage divider with a few resistors to get 3 volts, to activate pin 6 (BCM)
# on the raspberry Pi. In this way, the script can 'know' if Screen is ON or OFF.
import RPi.GPIO as GPIO
import time
import subprocess
from subprocess import call
GPIO.setmode(GPIO.BCM)
GPIO.setup(22, GPIO.IN) # PIR's output
GPIO.setup(6, GPIO.IN) # Screen power detector
GPIO.setup(25, GPIO.OUT) # Relay Input
GPIO.setwarnings(False)
while (GPIO.input(6) == 0): # IF SCREEN IS ON
if (GPIO.input(22) == 1): # PIR DETECTS MOTION
call(('/opt/vc/bin/vcgencmd', ' display_power', '1'))
GPIO.output(25, GPIO.HIGH) # RELAY ACTIVATION
time.sleep(3)
GPIO.output(25, GPIO.LOW)
time.sleep(60) # THE TIME WE WANT THE SCREEN TO STAY ON
if (GPIO.input(22) == 1): # IF PIR DETECTS A NEW MOVEMENT,
time.sleep(60) # ACTIVATES THE MIRROR ANOTHER AMOUNT OF SECONDS
else:
GPIO.output(25, GPIO.HIGH) # WITH THIS LINE, THE SCREEN POWERS OFF TO SAVE ENERGY
time.sleep(3)
GPIO.output(25, GPIO.LOW)
else:
GPIO.output(25, GPIO.LOW)
while (GPIO.input(6) == 1): # IF SCREEN IS OFF
if (GPIO.input(22) == 1): # PIR DETECTS MOTION
call(('/opt/vc/bin/vcgencmd', ' display_power', '1'))
GPIO.output(25, GPIO.LOW) # SAME AS ABOVE, BUT THIS TIME DON'T ACTIVATE THE RELAY
time.sleep(60)
if (GPIO.input(22) == 1):
time.sleep(60)
else:
GPIO.output(25, GPIO.HIGH) # WITH THIS LINE, THE SCREEN POWERS OFF TO SAVE ENERGY, AGAIN
time.sleep(3)
GPIO.output(25, GPIO.LOW)
else:
GPIO.output(25, GPIO.LOW)
call(('/usr/bin/python3', '/home/pi/SCRIPTS/pir.py'))
Here you can take a look at one of my projects:
https://forum.magicmirror.builders/topic/7263/my-first-smart-mirror-in-a-frame-of-40-x-30-cm-with-raspberry-pi-zero-w/2