import Adafruit_DHT
import time
DHT_PIN = 2
DHT_SENSOR = Adafruit_DHT.DHT22
while True:
humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)
if humidity is not None and temperature is not None:
print(f"Temperature: {temperature:.2f}°C, Humidity: {humidity:.2f}%")
else:
print("Failed to retrieve data from DHT22 sensor")
time.sleep(2)
import RPi.GPIO as GPIO
import time
RELAY_PIN = 3
GPIO.setmode(GPIO.BCM)
GPIO.setup(RELAY_PIN, GPIO.OUT)
try:
while True:
GPIO.output(RELAY_PIN, GPIO.HIGH)
print("Lamp is ON")
time.sleep(2)
GPIO.output(RELAY_PIN, GPIO.LOW)
print("Lamp is OFF")
time.sleep(2)
except KeyboardInterrupt:
GPIO.cleanup()