Hi, I've a code for automatic irrigation system. It uses RTC module for time, ESP8266 module for remote control and communication, flowmeter to measure the amount of water used, DHT module for temp/humidity preview, 16*2 LCD, several buttons etc.
So when system is powered Arduino starts with menu=1, so it loops in function displayDateAndTime() until any alarm starts or any button is pressed. During this it displays date and time on the screen and checks serial input for any command. If it gets any command, it process it. The serial is connected to ESP8266 which is connected to Blynk.
I generally do not do anything after I start up the arduino, just let it work itself.
There are 8 different alarm times to activate pump. 1 timer for screen light out, 1 timer for alarm duration, 1 extra alarm for RTC/Arduino time synchronization. When one of 8 alarms is activated it pulls pin 6 high which runs a pump and creates an timer for 1:45minutes. Pin 6 should be pulled down when timer expires.
In 20%-30% of the times it works ok without any problems. But 70%-80% of the times, I see problems. How it happens is, first alarm is working correctly, pump runs, time is counting on lcd correctly, after 20 to 80seconds, I see that time on LCD is frozen and alarm is not deactivated if time is up.
As a precaution, I've added a watchdog timer. In all my menus/loops, I've watchdog reset. If arduino freezes and does not loop within 8 seconds, watchdog is not resetted so it triggers arduino reset. So at least it does not cause pump run for hours, but I need to find out the reason.
I was suspected that code causes constant increase in RAM usage which causes it to freeze after some time. For this purpose, I send available RAM amount from serial to Blynk every time alarm started. I see that Arduino has around 1050bytes of RAM available. I can trigger arduino to print RAM amount manually, and in any part of the code I see that RAM is between 1040-1070bytes. So it shouldnt be RAM problem.
I was suspected that loose jumper cables might cause this, however when everything works ok, I moved cables a lot manually and it does not create any problems.
One more thing, this hardware is working correctly when I'm using an older code. So it should be a coding issue.
Please find Arduino code, ESP8266 code, circuit drawing and circuit photo attached. Note that cables are put on pump driver on purpose to show from where to where they go, normally they are hanged from sides.
Edit: Thanks for everybody who helped me to find out the cause of this problem, specially to cattledog who was the one pointing out the main reason.
It happened to be that the main reason of this problem was the code below:
transferVolume = flowPulses * 1,5;
I should have used full stop instead of comma. After this fix system works fine without any freezing for last 48 hours.
Additionally I've learned that IDE is hiding warnings during compile process, shows only errors. When you enable all warnings you see any problem in your code. After enabling all warnings I've seen that this problem was also pointed out by IDE as well. Just open IDE, go to File-Preferences, and enable ALL warnings and thats it.
Irrigation_Flowmeter_Blynk.ino (20.3 KB)
Huzzah_Print_Irrigation_Volume.ino (1.05 KB)

