Raspberry Pi, A2302 sensor, 5v fan
QN How can I request that my fan connected to GPIO 18 activates and stays active, until the temperature from my sensor at pin 5 reads either a temperature of less than 26 celcius, or a humidity of less than 60%?
#!/usr/bin/python
import time
import Adafruit_DHT
import RPi.GPIO as GPIO
sensor = Adafruit_DHT.AM2302
pin = 5
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
if humidity is not None and temperature is not None:
print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity))
else:
print('Failed to get reading. Try again!')
GPIO.setmode(GPIO.BCM)
GPIO.setup(18,GPIO.OUT)
GPIO.output(18, 1)
time.sleep(5)
GPIO.output(18, 0)
GPIO.cleanup()