2

Yes, as long as the signal is 3V3 compatible. You could use the Pi's UART RX pin (pin 10, GPIO 15) and the standard Linux serial software. That will handle standard baud rates (say up to 1 Mbps). Alternatively you can use a general GPIO (any other GPIO on the extension header) and software serial. That should be good up to 19k2 bps or so.


1

Answer: Yes. There are several ways this can be done. The method used will depend upon the characteristics of the load connected to the relay's contacts. Background: As @OyaMist has stated, "the actual relay state may differ from its nominal state". From a distance, when the relay state must be known, we are reduced to making a simple assumption; i.e. "...


1

Thank you all for your help in diagnosing this. Relay was faulty, swapped for one of the same make and model and now its working with the test provided by Coder Mike, as well as my original script.


1

Does the following turn on and off your relay accordingly? import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) RELAIS_1_GPIO = 18 GPIO.setup(RELAIS_1_GPIO, GPIO.OUT) while True: print('on') GPIO.output(RELAIS_1_GPIO, GPIO.LOW) time.sleep(2) print('off') GPIO.output(RELAIS_1_GPIO, GPIO.HIGH) time.sleep(2)


1

Setting a GPIO pin has a latching behavior. That is when you set it, it stays that same value until you tell it otherwise. So in your if statement, just add an else clause to reset it low if the value read is <=600: if touch > 600: GPIO.output(RELAIS_1_GPIO, GPIO.HIGH) print("moisture: " + str(touch)) else: GPIO.output(RELAIS_1_GPIO, GPIO....


1

OBSERVATION: I do not see a line of code / instruction to pull the GPIO back to low. If the observation is correct and this instruction is executed: GPIO.output(RELAIS_1_GPIO, GPIO.HIGH) How would the line GPIO return to a low state? Under what condition do you expect the GPIO to return to the low state? What happens if the instructions is changed to: ...


1

It's possible that this might mirror something I was doing a couple of years ago and I preface this with the observation that I don't believe that it was good practice, but I didn't find a way around it, so I welcome any correction. The issue (in my case) was that running a python program that accessed the GPIO pins required root access. If you are going to ...


Only top voted, non community-wiki answers of a minimum length are eligible