Sep-28-2021, 07:56 AM
Noob here.
I've been trying to set up a simple code to operate two relays.
Relay 1 is to turn on a router.
Relay 2 is to turn on a vacuum.
This is a cnc.
The input is from a CNC controller with a 5v dc output.
I am using a 5V dc relay as an interface.
Here is the code I did.
What i would like, is the Relay 1 to start straight away with a 5 second dlay for Relay 2.
when the input stops, the Relay 1 can stop but i would like the Relay 2 to run on for 10 seconds to clear the debri.
I've been trying to set up a simple code to operate two relays.
Relay 1 is to turn on a router.
Relay 2 is to turn on a vacuum.
This is a cnc.
The input is from a CNC controller with a 5v dc output.
I am using a 5V dc relay as an interface.
Here is the code I did.
What i would like, is the Relay 1 to start straight away with a 5 second dlay for Relay 2.
when the input stops, the Relay 1 can stop but i would like the Relay 2 to run on for 10 seconds to clear the debri.
# import GPIO and Time import time import RPi.GPIO as GPIO #set GPIO numbering mode and define outputs GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(23, GPIO.OUT) #router GPIO.setup(25, GPIO.OUT) #LED lighting GPIO.setup(24, GPIO.OUT) #vacuum GPIO.setup(16, GPIO.OUT) #camera GPIO.setup(5, GPIO.IN, pull_up_down=GPIO.PUD_UP) #input from cnc # cycle those relays try: while True: if (GPIO.input(5))== False: # cnc program is started GPIO.output(23,True) # Router is on print("router is on") time.sleep(5) # delay starting the vacuum GPIO.output(24,True) # vacuum is now on print("vacuum is on") elif (GPIO.input(5))== True: # cnc program has stopped GPIO.output(23,False) # stopping router print ("router is off") time.sleep(10) GPIO.output(24,False) # vacuum is now off print ("Vacuum is off") time.sleep(1) finally: # cleanup the GPIO before finishing GPIO.cleanup()I'm having issues with the times being out.