# ===================================================================================
# Projet créé par :
# Nom : Moujoud Mustapha
# Encadré par : Mr. Pr. ABDELKADER MEZOUARI
# Titre du projet :Éclairage automatique intelligent
# Plateforme utilisée : Wokwi
# ====================================================================================
from machine import Pin, ADC
from time import sleep, ticks_ms, ticks_diff
pir = Pin(16, Pin.IN)
led = Pin(15, Pin.OUT)
ldr = ADC(26)
# Seuil de luminosité
SEUIL_OBSCURITE = 30000
# Temporisation (10 secondes)
TEMPS_MAINTIEN = 10000
temps_derniere_detection = 0
while True:
valeur_lumiere = ldr.read_u16()
presence = pir.value()
print("Luminosité :", valeur_lumiere)
print("Présence :", presence)
# Présence + obscurité
if presence == 1 and valeur_lumiere > SEUIL_OBSCURITE :
led.value(1)
temps_derniere_detection = ticks_ms()
# Extinction après temporisation
if ticks_diff(ticks_ms(), temps_derniere_detection) > TEMPS_MAINTIEN:
led.value(0)
sleep(0.2)