-2
def fan_on():
    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BCM)
    FAN_PIN = 23
    GPIO.setup(FAN_PIN,GPIO.OUT)
    GPIO.output(FAN_PIN,True)

This is my code to run a fan on my rpi via GPIO

How can i run the fan in 5 scs long?

  • 2
    Perhaps switch it on, wait for 5 seconds, switch it off. What search terms have you used? – joan Nov 25 '18 at 7:47
0

since you already configured the gpio pins in the fan_on function you would just run, GPIO.output(FAN_PIN,False). you would also need the library time and more specifically the sleep function. in the end your python3 code would look something like this,

import RPI.GPIO
from time import sleep

def fan_on():
    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BCM)
    FAN_PIN = 23
    GPIO.setup(FAN_PIN,GPIO.OUT)
    GPIO.output(FAN_PIN,True)

while True:
    fan_on()
    sleep(5)
    GPIO.output(FAN_PIN,False)
    sleep(5)
  • Sir is it possible to run the sleep on different threas because it makes the whole script sleep TIA – eastwind Nov 25 '18 at 9:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.