The problem is little weird…but after some tests I got the cause of it,however didnt figure out a solution for it.
In my Hydroponic system I’m using arduino MEGA with a big AC pump,three small DC pumps and the Light System.
I am implementing two external interrupts (two buttons) in my code that stops the operation and return back to Menu when they get pressed.
In those two ISRs, I’m just setting a global flag(no other way to set the flag except through the ISRs).
Now the problem is (may be one of the problems) when the AC Pump is switched from ON to OFF position while the Light System is ON, the whole System stops (giving me a Stop Screen) it’s neither hanging nor restarting.
This scenario cannot be happened unless the global flags are set (Stop_Flag=1) and the global flags are set only in the two ISRs (external buttons).
In a nutshell, the cause of the problem is due to some sort of electrical noise that makes the arduino execute the two ISRs without pressing the buttons OR may be i miss the right implementation of the External Interrupt driver.
I’m driving both the AC Pump(220v) and the Light System(220v) using two relays controlled by arduino MEGA
and here’s the code for the external intterrupts:
DDRE &= ~(1<<5);
EICRB |= (1<<ISC51);
EIMSK |= (1<<INT5);
DDRE &= ~(1<<4);
EICRB |= (1<<ISC41);
EIMSK |= (1<<INT4);
Menu_Flag = 1;
Stop_Flag = 1;