[HELP] LCD 20*4 shows wierd characters when relay state changes (Arduino)

Thread Starter

farzad latifeh

Joined Oct 3, 2017
82
Hi everybody
hope the post is in the right place, sorry if it's wrong.

I made a DIY project to water my garden automatically from this post: (the garden is 90 Km away from my house).
https://www.instructables.com/id/WATERING-SYSTEM-INTRODUCTION/

almost everything is OK but one thing, sometimes when the relay state changes, the LCD shows weird characters and sometimes it just got stuck 1 in two attempts and sometimes continuously,

I did some modifications which I found from the web: like:
A) putting flyback diode (1N4002) and capacitor (100 nF) in to the water pump leads to control the back current and brushes noises,
B) one 2L1C filter from this post (https://forum.allaboutcircuits.com/...-surge-and-interference-of-uc-5v-and-gnd.659/) for the Arduino,
C) two 50 uH inductors for the water pump supply one for vcc and one for gnd,
D) three 33 uH inductors for VCC and gnd and SCL leads of display,
E) start the water pump in 2 state switch with 2 channel relay to make sure the inrush current (stall or locked rotor current) is avoided, first in a way with 10 ohm resistance for 1 s and then start the primary circuit.

after these modifications the problem just happens 1 in 10 times, but for watering planets automatically in case of 90 Km far away, it is necessary to work very precisely without any problem.
I do not have any scope meter or something, I cannot afford any solid state relay, please help and save the project. TNX.
 

ericgibbs

Joined Jan 29, 2010
18,845
hi farzad,
When it locks up and you press the Arduino Reset push button does the system work OK.?
If yes,
I had a similar problem with a datalogger, so I added 'watch dog' monitoring circuit.
If the logger fails to carry out a particular task for approx 60 seconds, the watch dog Resets the Arduino.

E

EDIT:
This DS1232 datasheet is a commercial watch dog IC.
 

Attachments

Last edited:

Picbuster

Joined Dec 2, 2013
1,047
Please supply drawings (power circuit and mpu).
in most of the cases is a power glitz debit.
To avoid this feed your mpu via diode and two cap parallel 100nF and 100uF and place a small cap 100nF plus diode over coil.
When the glitz goes down mpu is fed from 100uF.
Measure the glitz and look at data sheet Caps to identify impedance @ frequency and take the lowest impedance for measured frequency.
( measured frequency I mean edge rise / fall time.)
When it goes up the two caps (low ESR) will do that job.

Picbuster
 

Thread Starter

farzad latifeh

Joined Oct 3, 2017
82
hi farzad,
When it locks up and you press the Arduino Reset push button does the system work OK.?
If yes,
I had a similar problem with a datalogger, so I added 'watch dog' monitoring circuit.
If the logger fails to carry out a particular task for approx 60 seconds, the watch dog Resets the Arduino.

E

EDIT:
This DS1232 datasheet is a commercial watch dog IC.
Thank you very much
 

Thread Starter

farzad latifeh

Joined Oct 3, 2017
82
Please supply drawings (power circuit and mpu).
in most of the cases is a power glitz debit.
To avoid this feed your mpu via diode and two cap parallel 100nF and 100uF and place a small cap 100nF plus diode over coil.
When the glitz goes down mpu is fed from 100uF.
Measure the glitz and look at data sheet Caps to identify impedance @ frequency and take the lowest impedance for measured frequency.
( measured frequency I mean edge rise / fall time.)
When it goes up the two caps (low ESR) will do that job.

Picbuster
thanks for response, I should add diode and cap for the screen I guess as you mentioned.
 

JohnInTX

Joined Jun 26, 2012
4,787
The Arduino library has a watchdog function that uses the internal watchdog timer of the Atmel processor. Apparently there are some things to watch out for but it could be an easy software, no additional hardware solution depending on your particular setup.
https://forum.arduino.cc/index.php?topic=63651.0
That said, I agree with the others that it is just as important to fix the lockup problem first, then use the watchdog as a last resort.

Good luck!
 

joeyd999

Joined Jun 6, 2011
5,283
That said, I agree with the others that it is just as important to fix the lockup problem first, then use the watchdog as a last resort.
In fact, the WDT can hide serious problems in the code, and make the problem worse -- unbeknownst to the programmer.

It's far better to write code that doesn't lock up.

Use a modular approach to programming. Thoroughly debug each module with test code and hardware inputs that exercise 100% of the code and all conditionals and branches. Make a checklist if you have to, and check off each block of code as it's tested.

Finally, use non-blocking hardware drivers that fail sanely when the hardware doesn't respond as expected. Report the fact that the hardware failed to respond through messages, blinking leds, or beep codes. This gives you the ability to quickly determine and fix the underlying problem -- as opposed to just masking it.
 

ericgibbs

Joined Jan 29, 2010
18,845
hi,
I agree, it is essential that any inherent hardware and software problems should be checked for and corrected before using a watch dog timer reset.

However, I have never seen a MCU that would not lock up, even when running the best written software, where the MCU and its peripherals are subjected to high levels of external electrical noise.
ie: the high level of electrical noise which appears to be happening on this project.

As this project is controlling and monitoring a critical/remote installation, my advice to the TS, after he has cleared any hardware/software problems, is to fit a Reset watch dog timer, using either the MCU internal WD or an external device.

E
 

philba

Joined Aug 17, 2017
959
I don't think this is a programming problem but rather an electrical noise problem. (well, it could be but it feels more like a noise problem). See below for an easy way to test this.

I'm basing my questions and comments on the design from the instructables page (IP).

There are essentially 2 separate "systems": the logic part and the pump part. The pump is electrically isolated from the rest of the circuit because of the relay. I am assuming your implementation is the same as the IP. This means that anything you do to the pump circuit will not make a difference.

The most likely source of the problem is noise on the +5V rail coming from the relay board. I've seen this kind of problem before. Do you have a schematic for the relay board? (I am guessing the answer is no). Which one do you have? The ebay link from instructables had almost zero information except that it takes 5V. Based on that, I assume you are powering it from the Arduino and you are probably introducing a fair amount of noise back into the arduino.

To test this hypothsis, I would power the relay board from a separate supply (but use a common gnd). There are techniques to feed from a single supply via separate regulators but separate supplies is pretty easy to do. By that I mean use another 5V supply that plugs into the mains.

To increase the isolation, I would use an opto isolator between the relay board and the arduino to make for complete isolation. This means no common gnd either. This may not be necessary if the separate supply approach works.

There is one other possible source of noise - the buzzer. But I think it's much less likely than the relay board. To test that, just disconnect it.

All of this presumes you have a (relatively) reliable way to reproduce the problem. If you don't, figure one out.
 

Thread Starter

farzad latifeh

Joined Oct 3, 2017
82
The Arduino library has a watchdog function that uses the internal watchdog timer of the Atmel processor. Apparently there are some things to watch out for but it could be an easy software, no additional hardware solution depending on your particular setup.
https://forum.arduino.cc/index.php?topic=63651.0
That said, I agree with the others that it is just as important to fix the lockup problem first, then use the watchdog as a last resort.

Good luck!
Dear sorry for different posts
the lock current is ok with two state relay switching, first with 10 ohm resistance and then primary circuit turn on, the problem of watch dog is something different, I had this problem with different water pumps with or without lock current.
I am looking for the library you said, thanks, if you have any more information be so kind and let me know.
 
Last edited:

Thread Starter

farzad latifeh

Joined Oct 3, 2017
82
I don't think this is a programming problem but rather an electrical noise problem. (well, it could be but it feels more like a noise problem). See below for an easy way to test this.

I'm basing my questions and comments on the design from the instructables page (IP).

There are essentially 2 separate "systems": the logic part and the pump part. The pump is electrically isolated from the rest of the circuit because of the relay. I am assuming your implementation is the same as the IP. This means that anything you do to the pump circuit will not make a difference.

The most likely source of the problem is noise on the +5V rail coming from the relay board. I've seen this kind of problem before. Do you have a schematic for the relay board? (I am guessing the answer is no). Which one do you have? The ebay link from instructables had almost zero information except that it takes 5V. Based on that, I assume you are powering it from the Arduino and you are probably introducing a fair amount of noise back into the arduino.

To test this hypothsis, I would power the relay board from a separate supply (but use a common gnd). There are techniques to feed from a single supply via separate regulators but separate supplies is pretty easy to do. By that I mean use another 5V supply that plugs into the mains.

To increase the isolation, I would use an opto isolator between the relay board and the arduino to make for complete isolation. This means no common gnd either. This may not be necessary if the separate supply approach works.

There is one other possible source of noise - the buzzer. But I think it's much less likely than the relay board. To test that, just disconnect it.

All of this presumes you have a (relatively) reliable way to reproduce the problem. If you don't, figure one out.
appreciate you for looking at it,
dear, I have one power supply for both the Arduino and water pump therefore any modification can make difference on all system, I put flyback diode (1N4002) and 100nF cap for water pump to reduce electrical noises and back current. also it starts in two state switching circuit firstly it starts with a circuit of 10 ohm resistance for 1 second and then while the first circuit is still open the primary circuit switches on and after 150 ms the first circuit switched off, so with this trick and two channel relay I overcome the problem of lock current.
I guess it is all about the relay, specially after I had to use both channels for lock current, different power source for relay can be very good idea to prove it.
my relay schematic is not available unfortunately (I know it's chines), but it is very similar to those who usually use for Arduino, it has flyback diode and transistor by itself ( something like this: https://www.gearbest.com/power/pp_3...MI6rTW0Ibj1gIVaL7tCh1NBgG5EAQYASABEgIiWvD_BwE)

I think if I put 2L1C filter for LCD it would help a lot because the Arduino after adding this filter never ever got locked up anymore, it is just the LCD which works para-normally sometimes. however watch dog coding is a way to make me sure the system will never lock up.
anyway, it is all about the noises.
 

philba

Joined Aug 17, 2017
959
I think you are describing the use of two relays to power the water pump. Like I tried to say before, the power to the pump is of no concern to the problem because it is isolated from the arduino by the relays. But the way to energize the relays with 2 coils active at once is the primary concern. If the relay board uses the same relays in the link then each draws about 75 mA per coil for a total of 150 mA when both active. You didn't say precisely but your answers implied that you are powering the relay board from the arduino. Is that true?

The flyback diode (also called Back EMF diode) is a good thing but the noise I am talking about is the initial current draw of the relay coil(s). If it was the back-emf causing the hang, you would see the crashes when a relay shut off, not when activated. When you activate the relay, the current draw will try to pull the voltage down. Your 100 uF capacitor will help supply some of the draw and minimize voltage drop (the cap on the arduino will too a little). But they aren't going to prevent it totally. Microcontrollers don't like to see fluctuations on their supply voltage. By sharing the 5V rail with the arduino and the relays, you are asking for trouble. The relay coils should be fed from a separate supply or at least a separate regulator. This is an example of why projects from places like Instructables, while good for teaching, often times are poorly thought out for reliability and ruggedness.

I think you will find that you don't need all those filters if you power the relay board from a separate supply. I'd attack the source of the problem, not the symptoms.

From an RC low pass filter perspective, the voltage slump is a signal traveling back into the arduino from the relay board. Assuming there is a 47uF cap in the arduino (from the Uno reference design) and the supply line has resistance of .01 ohm, then the cutoff frequency is 338kHz. Way too high to block even a 10 microsecond droop. I'm not motivated enough to do a 2 stage filter analysis on it but I'd bet that a 100 uF at the relay board doesn't help anywhere nearly enough either.
 
Last edited:

Thread Starter

farzad latifeh

Joined Oct 3, 2017
82
.... Like I tried to say before, the power to the pump is of no concern to the problem because it is isolated from the arduino by the relays...
dear I understood what you said but when the watering motor is disconnected I have less problem so I guess there is something about watering pump which makes the problem worst. also I red somewhere in the web which using inductive loads with relay is the worst choice but it was too late and I had bought all parts!

.... You didn't say precisely but your answers implied that you are powering the relay board from the arduino. Is that true?...
yes exactly, the VCC for the RELAY and RTC and LCD are same and came from Arduino which is not a clear power supply and is the main reason I have faced with this problem but it is urgent to use one power supply in this system for me so the last option is changing the power supply of relay not first.

....If it was the back-emf causing the hang, you would see the crashes when a relay shut off...
yes again, I am starting to believe you can read my mind, haha, after relay turned off, the system goes crazy, therefore, it is the back EMF.

....From an RC low pass filter perspective, the voltage slump is a signal traveling back into the arduino from the relay board. Assuming there is a 47uF cap in the arduino (from the Uno reference design) and the supply line has resistance of .01 ohm, then the cutoff frequency is 338kHz. Way too high to block even a 10 microsecond droop. I'm not motivated enough to do a 2 stage filter analysis on it but I'd bet that a 100 uF at the relay board doesn't help anywhere nearly enough either....
dear you are damn right. I am happy to learn from you, thanks for reply, I used 2L1C filter with 220uF Cap. coupling with 100nF Cap. after this the Arduino never hanged anymore but still the LCD has problem.
would you mind telling me please how you calculated the frequency you mentioned? 338kHz! how to calculate the appropriate Cap. for this Frequency to filter it???

thanks anyway you are the real hero.
 

ericgibbs

Joined Jan 29, 2010
18,845
hi,
Is your relay module the same as this image.?
If yes then
removing that Blue jumper link enables the Relay coils and driver transistors to be powered from a isolated different 5Vsupply pin [JD-VCC] that is supplying the Opto Input drivers, 5V.[VCC]

This may help 'philba' to work out a suitable solution.

E
EDIT:
Cautionary Note to other users of this module:
Removing the +Vdd jumper link, does NOT effect the 0V line connection.
The modules 0v/Gnd line to the Opto Input and Opto Output, is always connected, so this Relay module cannot be used as a fully isolated Input/Output Opto Isolator in projects.
 

Attachments

Last edited:

Thread Starter

farzad latifeh

Joined Oct 3, 2017
82
anybody can help me to calculate the cutoff frequency for the low pass filter here?
for such system how can I calculate the cutoff frequency?
 

ericgibbs

Joined Jan 29, 2010
18,845
hi farzad.
Is it possible that you could post a photograph of the project, showing the Arduino, Relay module etc, so that we can check the wiring layout.
Then we can advise on the filtering required.

The 'Indestructibles' layout image is unhelpful.

Eric
 

Thread Starter

farzad latifeh

Joined Oct 3, 2017
82
hi farzad.
Is it possible that you could post a photograph of the project, showing the Arduino, Relay module etc, so that we can check the wiring layout.
Then we can advise on the filtering required.

The 'Indestructibles' layout image is unhelpful.

Eric
Dear Eric
Hi, :D
the problem has been solved by putting 2L1C filter for both Arduino and LCD,
but the question is how can I calculate the back emf to manage it scientifically and not with chance
I am not really happy to solve a problem without understanding the basic cause and reason
you know, I am looking for a logical way instead of trial and fail so I can manage it in the future more scientifically.
if there is anything you can help to understand back emf calculation I would be really appreciate of you.
 
Top