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.
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.
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. "...
Does the following turn on and off your relay accordingly?
import RPi.GPIO as GPIO
RELAIS_1_GPIO = 18
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:
print("moisture: " + str(touch))
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:
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:
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 ...