User avatar
RubenC
Posts: 12
Joined: Fri Dec 08, 2017 10:13 am
Location: Barcelona, Spain

Problem with relay and resistive load

Fri Dec 08, 2017 11:16 am

Hi there,

I have a strange problem with a relay and a resistive load. The load is an aquarium heater.

To be a little more precise.. Big picture, the project is comprised of an aquarium, 2 water deposits, an osmosis water filtering system, 3 relays, 4 water level sensors, 2 temperature sensors, 2 16x2 LCD displays.. and the pi. The relays control a) a water pump motor b) a solenoid valve conected to a tap c) a heater. The aquarium has a water level sensor to automatically make a refill when needed from one of the water deposits, that deposit has a level sensor so when it comes below a defined level activates the tap valve and puts the osmosis system to work filling that deposit, with the waste water generated by the osmosis filtering goes to another deposit. A temperature sensor measures the temperature in the water deposit feeding the aquarium, turning the heater on if drops below certain level, and turning the heater of if goes above certain level, and not allowing the aquarium being refilled it the temperature in the water deposit is below a defined level. The other level/temperature sensors are not relevant here.

Everything works fine. At the beginning (this past summer), I had the typical lcd garbling problem, and after some research I got to fix it using rc snubbers in parallel to the relays connectors. Also made the setup for the heater's relay, but never got activated (not beyond just checking that it worked) because the water filtering/filling system was put in the outside, and it was hot enough to be above the 27 degrees (celsius, 80.6F) the aquarium needs. Once temperatures started dropping, the heater started to get activated, and problems came.

It's not just that the heater's load garbles heavily the LCD displays (which by itself alone doesn't matter a lot since I'll replace the LCDs with a hdmi screen and a control interface in PyQT). The LCD contents literally dance with garbage, as if there were some kind of "current" flowing and altering every bit of the screens. The real problem is that the heater load often makes the relay itself to switch on/off by itself (you can hear often the "click" sounds of the relay), and makes the pi load averages go crazy. It's not triggered by some glitches in the python code for sure, because all relay actions and sensors readings get logged (and there's only 1 line switching that relay on, and it's not happening there). Even ssh'ing into the pi makes that relay dance, or just a ps makes it switch 3-4 times, and, in general, any action causing the slightest increase of load, network interrupts included.

So there must be some kind of parasite current coming back from that heater (which is just a resistive load), bypassing the rc snubber, and flooding the pi. I know I have the option of just setting the heater's thermostat to the desired temperature, taking that part out of the equation and forget about that relay, but I'd like to understand what's going on before taking that (cowards!) train.

Any tip/advice would be great :)

Thanks,

Rubén

User avatar
Jednorozec
Posts: 809
Joined: Sun Nov 24, 2013 2:17 pm
Location: Deposit, NY

Re: Problem with relay and resistive load

Fri Dec 08, 2017 12:01 pm

What power supply are you using for the RPi?
The most important leg of a three legged stool is the one that's missing.
It's called thinking. Why don't you try it sometime?

User avatar
RubenC
Posts: 12
Joined: Fri Dec 08, 2017 10:13 am
Location: Barcelona, Spain

Re: Problem with relay and resistive load

Fri Dec 08, 2017 12:05 pm

A 2A usb one. And the mains plug is the same one for all the devices (I know it's far from ideal, but I have no other plugs there).

User avatar
Jednorozec
Posts: 809
Joined: Sun Nov 24, 2013 2:17 pm
Location: Deposit, NY

Re: Problem with relay and resistive load

Fri Dec 08, 2017 12:19 pm

Is the power supply made for the RPi or is it made for charging a cell phone?
How are you driving the relay?
The most important leg of a three legged stool is the one that's missing.
It's called thinking. Why don't you try it sometime?

User avatar
RubenC
Posts: 12
Joined: Fri Dec 08, 2017 10:13 am
Location: Barcelona, Spain

Re: Problem with relay and resistive load

Fri Dec 08, 2017 12:33 pm

The RPi power supply is this one: https://www.amazon.es/gp/product/B00EZ5 ... UTF8&psc=1 (this is, not a cell phone charger one).

The relay is this one https://www.amazon.es/gp/product/B00PQC ... UTF8&psc=1 and I'm not using it without the jumper because, when I was mounting the system, saw it made no difference when it came to lcd garbling until I put the rc snubbers, so I left the jumper in place. Is this what you mean when you say how am I driving the relay? The setup is as "normally open" (the three of them are like that).

pcmanbob
Posts: 5888
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Problem with relay and resistive load

Fri Dec 08, 2017 1:02 pm

I suspect your relay board and the LCD display being powered from the pi gpio 5v pin is what's causing your problem, either the relay switching is causing a volt drop on the power supply or noise is being put back into the 5v supply by the relay board.

try powering the relay board from its own 5v power supply , you will need to remove the jumper to do this, connecting the new power supply to JD-VCC and Gnd. check JD-VCC with a meter once you have removed the jumper and make sure there is no 5v on it before connecting your new power supply.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
RubenC
Posts: 12
Joined: Fri Dec 08, 2017 10:13 am
Location: Barcelona, Spain

Re: Problem with relay and resistive load

Fri Dec 08, 2017 3:00 pm

pcmanbob wrote:
Fri Dec 08, 2017 1:02 pm
I suspect your relay board and the LCD display being powered from the pi gpio 5v pin is what's causing your problem, either the relay switching is causing a volt drop on the power supply or noise is being put back into the 5v supply by the relay board.

try powering the relay board from its own 5v power supply , you will need to remove the jumper to do this, connecting the new power supply to JD-VCC and Gnd. check JD-VCC with a meter once you have removed the jumper and make sure there is no 5v on it before connecting your new power supply.
Could be, but I can't get to understand how that, in time, translates to:

Code: Select all

root       523 81.6  2.3 1586840 10448 pts/1   Ssl+ Dec07 707:34  \_ /usr/bin/python /root/deposito_v4.py
# w
 10:55:10 up 14:27,  1 user,  load average: 133.95, 135.62, 133.84
when under normal working conditions the situation (or without using that relay) is:

Code: Select all

root       513  7.2  1.6 152212  7492 pts/1    Ssl+ 13:34  10:08  \_ /usr/bin/python /root/deposito_v4.py
# w
 15:54:38 up  2:20,  1 user,  load average: 0.20, 0.19, 0.18
(notice the CPU usage of the python process and system's load).

Anyway, I'll find a chance to disassemble the entire thing (it's into a box, with lots of cabling, etc) and power the relay via the JD-VCC pinout.

Thanks & regards,

Rubén.

pcmanbob
Posts: 5888
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Problem with relay and resistive load

Fri Dec 08, 2017 4:54 pm

There is no way the relay board can affect CPU load it after all just connected to the GPIO and it makes no difference to the CPU if the relay board is connected or not the GPIO will still be driven just the same by what ever program is controlling it.

Assuming you had the same programs running in both of the above cases, was one after the pi had been running for some time and one just after a reboot by ant chance.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
RubenC
Posts: 12
Joined: Fri Dec 08, 2017 10:13 am
Location: Barcelona, Spain

Re: Problem with relay and resistive load

Fri Dec 08, 2017 5:15 pm

pcmanbob wrote:
Fri Dec 08, 2017 4:54 pm
There is no way the relay board can affect CPU load it after all just connected to the GPIO and it makes no difference to the CPU if the relay board is connected or not the GPIO will still be driven just the same by what ever program is controlling it.

Assuming you had the same programs running in both of the above cases, was one after the pi had been running for some time and one just after a reboot by ant chance.
That's the weirdness in all of this. There's nothing running but the python program, and nginx to serve a simple static website showing some graphs updated every 5 minutes with gnuplot from the application log. The pi gets rebooted by a cron job daily at early morning (to avoid potential stuff like that; despite having other pi systems running for months, I prefer this one to be "daily fresh").

raspdroid
Posts: 1580
Joined: Thu Nov 06, 2014 9:15 am
Location: Gran Canaria :: España

Re: Problem with relay and resistive load

Fri Dec 08, 2017 5:45 pm

Yours relays has optocoupler?

User avatar
RubenC
Posts: 12
Joined: Fri Dec 08, 2017 10:13 am
Location: Barcelona, Spain

Re: Problem with relay and resistive load

Fri Dec 08, 2017 5:50 pm

raspdroid wrote:
Fri Dec 08, 2017 5:45 pm
Yours relays has optocoupler?
Yup.

raspdroid
Posts: 1580
Joined: Thu Nov 06, 2014 9:15 am
Location: Gran Canaria :: España

Re: Problem with relay and resistive load

Fri Dec 08, 2017 6:16 pm

You know the forward current for each optocoupler to 3V3 ?

Are the relays powered from an external source or from the Raspberry Pi?

User avatar
RubenC
Posts: 12
Joined: Fri Dec 08, 2017 10:13 am
Location: Barcelona, Spain

Re: Problem with relay and resistive load

Fri Dec 08, 2017 8:47 pm

raspdroid wrote:
Fri Dec 08, 2017 6:16 pm
You know the forward current for each optocoupler to 3V3 ?

Are the relays powered from an external source or from the Raspberry Pi?
They're using te RPi's 5V output not an external 5V power source (yet). As I said a few posts ago, tried that setup in the beginning to see if it were avoiding me the LCD's garbling but it did not, so I took the rc snubber way and kept RPi's power source for the relays hence simplifying the design without a 2nd power source (not space/resources limit/problem, just that it didn't seem necessary at the time).. I'm not entirely sure about what you mean with the "the forward current for each optocoupler"... The optocouplers are integrated in the relay board design, basically, theres's not much you can do about that (afaik).

pcmanbob
Posts: 5888
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Problem with relay and resistive load

Fri Dec 08, 2017 8:55 pm

Having had a look at your relay board it looks like it's using 5v to power the opto-isolators and using the gpio as the ground which would mean you are connecting 5v to the gpio which is not 5v tolerant.

Am I correct about the relay board being active low ?
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
RubenC
Posts: 12
Joined: Fri Dec 08, 2017 10:13 am
Location: Barcelona, Spain

Re: Problem with relay and resistive load

Fri Dec 08, 2017 9:07 pm

pcmanbob wrote:
Fri Dec 08, 2017 8:55 pm
Having had a look at your relay board it looks like it's using 5v to power the opto-isolators and using the gpio as the ground which would mean you are connecting 5v to the gpio which is not 5v tolerant.

Am I correct about the relay board being active low ?
Yes, those relay boards are active low. I'm using a 2803 between the relay and the RPi also.

pcmanbob
Posts: 5888
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Problem with relay and resistive load

Fri Dec 08, 2017 9:34 pm

That's good then, so you can rule out the board causing any damage to the pi gpio, so that just leaves you to try a separate power supply to power relay board.
That will prove or dis-prove the relay board being the cause of you problem.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

raspdroid
Posts: 1580
Joined: Thu Nov 06, 2014 9:15 am
Location: Gran Canaria :: España

Re: Problem with relay and resistive load

Sat Dec 09, 2017 8:32 am

I would try an external power supply (battery or mobile charger) , I think that's your problem. The Songle relay consumes 60 mA each. 180 mA and maximum for the gpio bank is 50mA.

And the optocouplers, if they are not low consumption (as this), they should consume 20mA each. 60mA in total.

Relays + Optos = 220mA total

Best Regards.

PD: It is not necessary to use another source, use the same one that feeds the Raspberry Pi. Grab a cable before the usb micro-b connector and feed the relays from there.

User avatar
davidcoton
Posts: 3697
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Problem with relay and resistive load

Sat Dec 09, 2017 9:50 am

raspdroid wrote:
Sat Dec 09, 2017 8:32 am
The Songle relay consumes 60 mA each. 180 mA and maximum for the gpio bank is 50mA.
That is not the issue. The supply fior the relays is not coming throught the GPIO pins, but from the 5V rail. This could possibly overload the supply (which is why it's worth trying a separate one), but it's not related to the 50mA per GPIO bank limit.

And if the opto-isolators take 20mA each, there is a serious design fault. Opto-isolators used as GPIO interfaces will be using not more than a few mA, or they are not fit for purpose.
Signature retired

raspdroid
Posts: 1580
Joined: Thu Nov 06, 2014 9:15 am
Location: Gran Canaria :: España

Re: Problem with relay and resistive load

Sat Dec 09, 2017 10:02 am

Ok, thank you davidcoton. I am also with something similar to these days and your answer is useful to me.

Return to “General discussion”