0

I try to build "irrigation controller" , the material which I used are: 1 relay model , raspberry pi model B , solenoid valve 24 VAC and AC-DC adapter (input 100-240v , output +24v ) I don't know which terminal of adapter(power supply) is negative and which is the positive !! It is not written on the wires but there something written on one of them (UL SPT-1 E179665 ... etc) Firstly, I connected valve with the adapter and it works (water passes) Now, I want to control it using my raspberry using python code, I already write it for ON:

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT) 
#This function turns the valve on and off in 10 sec. intervals.
while True:
    GPIO.output(18, GPIO.HIGH)
    print("GPIO HIGH (on)")

GPIO.cleanup()

The same thing for OFF (close solenoid) using GPIO.output(18, GPIO.LOW)

I used this connection like in the picture: enter image description here

But when I put adapter in plug electrical , it will work !!! I don't need it to work else I run the python code which make it ON !!

I thought, the connections not correct, so many times I tried to manipulate the wires and exchange the connection in the relay... But Unfortunately nothing !!

Any way to help ?

4
  • 1
    Couldn't you copy the edited version of your question from stackexchange instead?
    – jDo
    Apr 22, 2016 at 15:47
  • Are you sure your solenoid is active high and not low? Does it click when you run your code? Apr 22, 2016 at 15:53
  • You only need to write a high or a low to the GPIOs once, not constantly like you're doing in while True: GPIO.output(18, GPIO.HIGH). Btw. SPT-1, SPT-2, etc. are just measures of wire and insulation thickness - it tells you how much current the wire can carry; it says nothing about polarities
    – jDo
    Apr 22, 2016 at 15:56
  • It is possible that the relay you are using is a "Low level trigger." This means, it with close when the GPIO pin goes low, which is often what you do NOT want. For example, as soon as you power on the raspberry pi, the GPIO will be low and the valve will turn on, even before your program has gotten a chance to run. Probably not what you need. The other problem is that there does not appear to be any isolation between the relay circuit and the GPIO pins of the pi. There may be a flyback diode to protect the pins, but that's it.
    – dev
    Aug 4, 2021 at 2:49

1 Answer 1

1

I'm assuming you connected the electric pool power supply to common , and the exit to "NO" (Normally Open) ,following BCM pins on this image BCM pins are the number which reads "GPIO 22" GPIO PINS

if the image you posted is your actual connection and your output pin is connected to pin 22, you should change your code to this

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(22, GPIO.OUT) 
#This function turns the valve on and off in 10 sec. intervals.
try:

    while True:
        GPIO.output(22, 1)
        print("GPIO HIGH (on)")
        time.sleep(3)
        GPIO.output(22, 0)
        print("GPIO HIGH (off)")
except KeyboardInterrupt:
    GPIO.cleanup()

After that I would check with a multimeter voltage on the solenoid , to see if it is working , it should switch from 0v to 24v every 3 seconds

hope it helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.