Python Forum
Relay switches On and Off every cylcle...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Relay switches On and Off every cylcle...
#1
import RPi.GPIO as GPIO
import Adafruit_DHT
from time import sleep

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12,GPIO.OUT)
GPIO.setup(16,GPIO.OUT)

###LOW = ON     HIGH = OFF###

sensor = Adafruit_DHT.AM2302
pin = 2
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)



def switch():
    humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
    GPIO.setup(12,GPIO.IN)
    if temperature > 30 and GPIO.input(12) == True:            #MAX TEMP
        GPIO.setup(12,GPIO.OUT)
        GPIO.output(12, GPIO.LOW)
        print('ACF ON')
    elif temperature < 29 and GPIO.input(12) == False:          #MIN TEMP
        GPIO.setup(12,GPIO.OUT)
        GPIO.output(12, GPIO.HIGH)
        print('ACF OFF')
    


while True:
    switch()
    sleep(0.1)
when i run this code, my Relay switches Off (because it is colder than 30°C) but when the script runs another cycle, it rill turn off for a short duration and turns off immediatly after...
my aim is to have a switch that turns the relay on, when the temperature is over 30°C and off when its colder than 29°C...
Reply


Messages In This Thread
Relay switches On and Off every cylcle... - by hotwalk - Nov-28-2017, 05:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Convert looping home security to a one time scan of switches and sensors duckredbeard 0 1,788 Dec-08-2020, 04:31 AM
Last Post: duckredbeard
  Problem connecting to 2 switches, HELP! Netcode 0 1,243 Nov-15-2019, 10:30 PM
Last Post: Netcode

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020