Relay board control issue

Hi all.

I’ve built a 4 channel irrigation controller using:

Basic operation for now is:

  • Each day run a schedule where the 4 channels run consecutively for x minutes with a 10s delay between channels.
  • Each channel has a PB override.
  • Channel ON enunciated via the LED in the PB.
  • Press a PB outside of the schedule starts that channel. Press again stops it.
  • Logic allows only 1 channel to run at a time.

This works well on the bench with the PBs, LEDs and relays operating correctly.

In the field I have issues. When the 24vac is switched by the relay to energise the solenoid I get random switching. Sometimes the channel (LED and relay) will switch off immediately. Other times that channel switches off and other channel switches on. I can see the status LEDs on the Freenove board switching so it is the Pi’s GPIO doing this.

Thinking I have a dodgy relay board I tested one channel with a Gravity: Digital Relay Module (Arduino and Raspberry Pi Compatible) | Buy in Australia | DFR0473 | DFRobot | Core Electronics . Same issue.

I have tried wiring and testing with the 24 VAC floating, grounded to house LV earth, and the Pi gnd. I have replaced the 24 VAC PS. Thinking I may have some weird noise/emf/whatever from the 24VAC PS I tried powering it from a different circuit. I put the Pi’s PS and then the solenoid PS on a power rail that has suppression. None of these changes made any difference.

I’ve check AC and DC voltages, and AC loads. All as expected.

To be clear, with the solenoid PS switch off everything works fine. Turn it on and the madness starts.

There is NO link between the 24VAC supply to the solenoids and the PI GPIO wiring.

My so so schematic come layout drawing below FYI.

What have I done wrong?

Currently the 5v for the relay coils (JD-VCC) is supplied from the Pi. I have read conflicting advice on whether is is good or bad. Perhaps this is the issue?
This implies (I assume) some back EMF or some such from the relay coils under load, upsetting the Pi?

I will try a separate 5DC PS tomorrow.

Hey there, @Mark285907,

Since two different relay boards do the same thing, I doubt the relay is the problem. It sounds more like electrical noise from the 24 VAC solenoid is getting into the pushbutton GPIO wiring.

As a quick test, disconnect the pushbutton signal wires from the Pi and run a timed cycle. If the problem disappears than its highly likely that the issue is down to electrical interference. It may also be worthwhile keeping the solenoid physically distance from the logic components, which would further reduce the risk of interference.

1 Like

Hi Mark
I can see one error straight away.


You have the 24VAC active connected to the NC (Normally Closed) contacts of the relays while the connection to the solenoid is to the NO contact.

This active common should go to the Relay Common terminal. This is the connection one position DOWN in your diagram.

In the present position the solenoid should not have operated at all as it would be connected to nothing.

Why this would have upsetter the logic is another matter as the 24VAC should be still isolated.

But as an official schematic is still not forthcoming what actually happens on this board is still up in the air. I think the only schematic available is one that has been produced by a contributor who reversed engineered one of these units.

This is a bit of a pity one has to resort to this to obtain enough useful information when ascertaining whether this it fit for purpose or not. The main reason I would personally not purchase it.
Cheers Bob

PS: The 24VAC wire to the solenoid should be left on the Relay NO connection

1 Like

Run a quick check that your logic is never left floating.
i.e. when the button is not pressed, it should be either Vcc or Gnd (based on your design), then when pressed should be the other.
i.e. make sure its not Vcc when pressed and “nothing/floating” when not pressed.

1 Like

Hi Mark

According to the reverse engineered (???) schematic below


There is a flywheel diode fitted across the relay coil designated D1.
This is depicted as 2 diodes back to back. If this is the case this will do absolutely nothing in the way of swamping reverse voltage flyback pulses.

Please Core. Provide an official schematic so these issues can be put to bed.
Cheers Bob

Also the on that “schematic” the designated pins on the terminal block according to the screen printing on the PCB are incorrect. Pin 1 is OK, Pins 2 and 3 are reversed. Pin numbers left to right as seen from the front of the terminal block. You have wired as per this schematic. This is a point you should check before making any changes I suggested above.

In other words this schematic does not agree with the screen print as seen in the product pics.

An add on about your statement quoted above. In theory any interference from this source should be evident without the 24VAC being connected or not.

Hi Michael

Referring to the only schematic I have above.
The GPIO should be returned to VCC via D2, the opto LED and R1.
BUT, it would be interesting to measure the actual voltage at the GPIO or relay board input.
By the time you factor in the drop across D1 and the opto you might not have enough of the 3.3V left to convince the GPIO that it is in a HIGH state. It might work better if the D1 was not there. I don’t know what it does unless it is supposed to be an indicator LED. In which case the drop would be significantly higher than the usual o.6V or 0.7V.

If Mark is going to continue with a VCC of 3.3V he might be advised to fit about 5k1 resistor between the inputs and VCC. This would ensure that the GPIO is pulled HIGH and also ensure the opto LED is OFF when it is meant to be OFF and not be subject to any funnies
Cheers Bob

Progress of sorts. Elimination anyway!

I removed the Gravity single relay module and put the 4 relay board back in circuit.

Made sure the solenoid 24vac is floating. Relay board JD-VCC still connected to Pi 5v.

Confirmed I have the solenoid wiring on the relays correct, being across common and N/O.

Being a new day blah blah I tested the PBs again. Same issue.

Ran the schedule. Issue occurs on channels 1 and 2 that have solenoids. Not on 3 and 4 that do not.

Installed a separate 5v PS to the relay board’s JD-VCC and Pi GND. Same issue. Again, only occurs on the 2 channels with load.

Disconnected the PB wiring at the Pi. Separate 5v to JD-VCC. Ran the schedule. Worked ok! Tested this twice.

Reconnected JD-VCC to Pi 5v. Repeated the above. Worked OK!

Separate from all of the above, I noticed that switching the solenoid PS on/off at the power point can (not always) cause the issue, this chattering/switching of GPIO outputs.

Also (I’m not sure if I’ve said this), the channel status LEDs in the PBs are controlled by separate GPIO than the relays. When the chattering happens, both the relays and corresponding LEDs chatter.

So there’s some feedback/noise/whatever from the relays that are switching a load (as opposed to those that are not) to the Pi that causes the PB GPIO to trigger, causeing the relays/LEDs to chatter.

Me thinks I need to go back to my PB input wiring and check that. If that wiring is correct, I need some suppression of some sort in circuit?

Hope the above makes some sense!

Im having trouble working out how the Push Buttons work.
Based on what I am reading, I kinda think they are like this… a bit of guess work, so it needs testing and confirmation BEFORE making making any changes I may comment on below.

So the +/- is the flow of power to turn on the led (with the needed resistor inline)
Then the PB, is normal open. So when pressed is simply connecting the left pin to the right pin.

Assuming that is correct, then you still need a pull up/pull down on the Pi Side.
If we assume you use the Pi internal Pull up on the “input pin”. then that should hold the pin High, then when the button is pressed, it should then “short to ground” pulling down the power on the GPIO on the Pi.

(you can also do the reverse). Use the Pi pull down, which will hold the pin low when not pressed. then when you press the button it should then connect to Vcc of the pi to pull it up.

Please confirm how the button actually works first.

Michael, what you’ve shown is correct. The small pins +/- is the LED. The larger pins are a N/O PB.

Hi Mark, Core and all concerned
Please accept my humble apologies.
The schematic (reverse engineered one) and the screen print on the relay module relay contacts DO agree. And Mark you DO have the 24VAC active looped through the relay common terminals.

How in hell I made THAT mistake I do not know. I realised the error when I had a closer look at the screen print on the PCB pic.

I can only apologise again and put it down to plain carelessness in old age. Will just have to be consciously somewhat more careful in the future and triple check before commenting.
Cheers Bob

1 Like

I have the PBs programmed as pull up.

GPIO.setup(pb_eden, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(pb_orch, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(pb_fern, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(pb_veg, GPIO.IN, pull_up_down=GPIO.PUD_UP)

I had them wired as:

gnd---PB---10k---GPIO

I’ve now changed this wiring to:

gnd---PB---GPIO
         |---10k---3.3v

Made no difference.

Thanks mark, good to get more detail.

Yeah the internal pull ups should normally be enough.
My rule is external give you more control (strength etc), internal is often enough.

If you look at the data sheet for the Pi GPIO with pull ups, I think you will find its similar to your send test, just that bits hidden :slight_smile:

So if this is only happening when the relays are connected, then the original question, what’s causing it?
It would be nice to put a scope on an input pin and see it it shows anything. (DMMs are likely to be too slow to see it).

While this is out of my area of expertise, from memory when using coils (like in a relay) you should have the “flyback” (I may have that term wrong), diode in parallel with the coil. @Robert93820 shows on in his diagram above.
The idea here is that a coil gets charged, then when power is cut, the field will collapse and the power want to go somewhere, and fast. the diode allows it to loop back and dissipate rather then trying to go via other bits.
I wonder it there is a temp ground V rise as the relay is turned off ?

So at this point, Im kinda heading into grounding paths so that High current grounding does not need to pass by your LV logic grounding.

All just thoughts.

Note: When something is on, does the relay stay energized the entire time until it need to go off? if it stays on (so the coils would get energized then be held there), but you still see a false trigger, then this hints its not the dumping of the power in the coil.

Also the relays MAY have those diodes in them… I have not checked.

Hi Michael
Regarding that schematic. That is not “mine”. It is the result (I think) of a contributor reverse engineering one of these devices and this is the result. Not exactly official.

That shows 2 diodes back to back across the relay coil. This is the correct position but connected in this manner they will do absolutely nothing about getting rid of the voltage spike when the coil current collapses.

I have not got one of these to see for myself nor am I going to get one. As this seems to be a Core product (according to the product page) I think it is up to them to provide a “proper” schematic or clarify some of these points.

The Relay Data sheet does not indicate an internal diode

Cheers Bob

This is doc I’ve referenced for the relay board.

4 Channel 5V Optical Isolated Relay Module.pdf (256.3 KB)

1 Like

Hi Mark
I had not seen this. This is certainly a lot better source of info. It would appear that the bit of schematic I have is from this document and not the result of reverse engineering I had previously thought. There may be some legal restraints preventing Core from linking this document.

Anyway D1 is depicted as 2 back to back diodes which will do nothing about any flyback voltage generated.

Take particular note of the text at the top of P3 regarding grounds. This refers to Arduino but is equally pertinent to RPi.

In case of insidious ground loops causing problems I would suggest you try.
If you are using Pi 3.3V for VSS remove the Pi ground. It is not required for opto operation, The GPIO being taken to ground completes this circuit.
Use external 5V for relay supply and connect this ground to the relay board. This should isolate any form of interfering signals from your controller due to multiple grounds.

The text in this data sheet you linked explains all this.

Thanks for that link. Clears up a lot of questions and raises some new ones.

Where is the flywheel diode that should be across the relay coil
What is the OpAmp looking thing designated as "IN1’ etc. Could be a green LED but not depicted as one. Looks more like an OpAmp

If that is a green LED you 3.3V might be stretched a bit thin. By the time you add the V drop of 2 LEDs (1 in the opto coupler) there would not be much left of your 3.3V. But this does not explain why you only have problems when 24VAC is connected.

Cheers Bob

Bob, re the data sheet:

D1 - I can see one diode clearly depicted but what the other bit sitting on top of it is, I have no idea. Could be a diode symbol lost in translation.

Top of P3 - I’ve read this a dozen times but its nonsensical Chinglish to me! I removed the GND wire from the relay board but that just induced random switching of PBs vs relays. That while using the Pi 5V and the separate 5V PS.

Michael, I don’t have access to a scope unfortunately. Re the relay state once ON, when the chatter occurs the intended relay/LED come ON for a sec, then go off for a different relay/LED to take its place. This is driven by the PB GPIO chattering.

BUT…

I put an RC snubber (100 ohm resistor in series with 100uf X2 cap) across the common and N/O contacts of relay 1 and 90% fixed the issue. By 90% I mean the issue would occur 1 in 10 PB operations as opposed to always.

I think an interlock in logic to lock the operation of the GPIO outputs for say 1s after the operation of ANY other GPIO output will tidy up that last 10%. Not ideal as I’d like to fix the core issue but it’ll do for now.

Hi Mark

No. You should disconnect the Pi ground from the Board ground. The board ground then has to connect to the relay power supply negative or ground.

The opto coupler finds its ground (Pi Gnd) via the relevant GPIO. The relay circuit finds its own ground via board ground and Relay supply negative.

With no relays active measure the V on the GPIOs. That 5V (Pi 5V) minus the LED drops (there should be not enough current at this point to drop anything across the resistor) will appear here.
Now I believe the Pi GPIO is 3.3V operated. Now I don’t know how tolerant this is to over voltage but it just might be that the GPIO volts are too high.

Now I think some of these Opto LEDs are very sensitive but I think this sort of circuit (especially with an unknown limiting resistor) would be a lot happier with 5V input. But if the Pi GPIO is not very tolerant I am afraid you gets what you got as the saying goes. Unless you can manage to change the value of the limiting resistor R1 to allow a bit more current at 3.3V.
If that thing labeled IN1 is just a green indicator LED which I think it is, shorting it out with a bit of wire would help lift the current a bit at 3.3V and improve reliability

3.3V ??? I think sometimes it is more trouble that what it is worth. Not a lot of headroom to go throwing diodes and the like around all over the place. Particular LEDs where the volts drop could be up to nearly 3V. And here you have 2 (I think) of them in series plus a resistor trying to light up with 3.3V. To be fair these could be a smaller V drop but would still be significant. But as usual no type numbers available to look and find out.

Not my cup of tea I am afraid so if I wanted something like this I would not consider this particular unit until enough information is available to establish fit for purpose.
Cheers Bob

Added a callback event with a 50ms delay which seems to have tidied up the last 10%.

Tested again this morning. No chatter.

Thanks all for the help.

1 Like

Hi Mark.
If you are happy with a few Band Aids all well and good.
But please remember that the underlying problem is still there if you have strange problems down stream.

You previously stated you tried a Gravity single relay board. This is an entirely different circuit to the 4 channel device yet it behaved the same. That would pretty much rule out a problem with the board. The fact that it could be a bit iffy at 3.3V would not seem to be the problem.

I may have confused you with that Page 3 text in the Data sheet. I had not noticed that this starts on Page 2. It might make more sense to you if I had noticed that. That text (P3) made sense to me and I did not bother to look at the previous page. Please look again.

The fact that your system works until 24VAC is turned on is very strange. IF as you suggest this 24V is just a transformer it should be COMPLETELY isolated. The transformer in the plug pack and the relay should make the 24VAC completely divorced from EVERYTHING else. on the other hand if this is an “Electronic” transformer similar to the devices that are used to power halogen lamps then it might be designed to drive a resistive load (Your solenoid load is inductive).

I would carefully check this as I know those halogen “transformers” used to get up to all sorts of tricks when there was no lamp connected. I would also check all the wiring, especially the ground connections. If your Electronics is mains derived and not battery I would really check all this because if the 24VAC IS electronic there would be a path for interference back through the mains supply. These types of “transformers” operate quite a way above the mains 50Hz.

Most DMMs these days measure AC frequency so if you check the frequency of the 24VAC this could be a clue.
Cheers Bob

PS: From all this I would suggest that some sort of disturbance is upsetting the Pi itself and I would try a 24V system you can guarantee is “just a transformer” if this is possible or practical.

1 Like