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 ?

  • Couldn't you copy the edited version of your question from stackexchange instead? – jDo Apr 22 '16 at 15:47
  • Are you sure your solenoid is active high and not low? Does it click when you run your code? – Steve Robillard Apr 22 '16 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 '16 at 15:56
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, privacy policy and cookie policy

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