final try for today as I will go to sleep
import RPi.GPIO as GPIO from twilio.rest import Client from datetime import datetime def send_sms(client, sms_text="Hello from Python!"): client.messages.create(to="+19732644152", from_="+12023351278", body=sms_text) twilio_client = Client("ACxxxxxxxxxxxxxx", "zzzzzzzzzzzzz") GPIO.setmode(GPIO.BOARD) GPIO.setwarnings(False) GPIO.setup(7,GPIO.IN) #LDR (Light Dependent Resistor) GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #top switch GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # bottom switch GPIO.setup(15,GPIO.OUT) # Door Open GPIO.setup(13,GPIO.OUT) # Door Close # add events detection GPIO.add_event_detect(7, GPIO.BOTH, bouncetime=50) GPIO.add_event_detect(11, GPIO.RISING, bouncetime=50) GPIO.add_event_detect(12, GPIO.RISING, bouncetime=50) while True: if GPIO.event_detected(7) # change in light sensor if not GPIO.input(7) and not GPIO.input(11): # it's day and door is not open print ("Day. Open door") print ("Start motor. Time is {}".format(datetime.now().strftime('%d %b %Y %H:%M:%S.%f')) GPIO.output(15,True) elif GPIO.input(7) and not GPIO.input(12): # it's night and door is not closed print ("Night. Close door") print ("Start motor. Time is {}".format(datetime.now().strftime('%d %b %Y %H:%M:%S.%f')) GPIO.output(13,True) if GPIO.event_detected(11) and GPIO.input(11): # top switch change to HIGH GPIO.output(15,False) print ("STOP. Door open. Time is {}".format(datetime.now().strftime('%d %b %Y %H:%M:%S.%f')) #send_sms(client=twilio_client, sms_text='Door open') if GPIO.event_detected(12) and GPIO.input(12): # bottom switch change to HIGH GPIO.output(13,False) print ("STOP. Door closed. Time is {}".format(datetime.now().strftime('%d %b %Y %H:%M:%S.%f')) #send_sms(client=twilio_client, sms_text='Door closed')
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs