Controls the throttle of a steam engine via a feedback from a hall effect sensor. The hall effect sensor can work from 5VDC to 30VDC. I have it wired for 5VDC.
The throttle is raised and lowered via a stepper motor.
When activated via a button, an output goes on activating a solenoid valve to activate a clutch and another valve to pneumatically close a water valve. Lastly, the throttle is raised prior to the solenoid valves closing.
With the clutch engaged, a piston water pump will pump for 10 seconds then stop and release the clutch. The throttle is then lowered back to idle speed.
Pressing another button opens the water valve putting the system back to initial conditions.
Note that the 12VDC stepper is powered through a L298N Dual Bridge. The 12VDC solenoid valves are activated through a relay board.
My issue is at step four. About half the time my arduino locks up. I'm at a loss as to what's up. It doesn't matter if I power the Arduino through my USB or through a 12VDC power supply. The lockup seems to occur after the clutch releases, but before the stepper throttles down the engine. The solenoid valves have indicator diodes on them. Sometimes the water valve will open, sometimes it will not. Sometimes the buttons are partially responsive, usually not.
I'll take any suggestions you may have.
I have a grainy video of of system before I added the code (lines 211 through 221) to quickly close the throttle after the pumping. You can see it here.
A schematic or wiring diagram would help. It is usually a bad idea to power motors or solenoids from the Arduino. Activate, yes; power, no. I am not saying that this is what happened, but powering motors and/or solenoids from an Arduino can lead to intermittent results, including unexpected resets, jumps, and lockups.
Some things to think about ... opto-isolation configure relay board, separate power supply for the relay board and solenoids, fly-back diode connected across each solenoid coil, star-point grounding to avoid ground loops, ferrite core on power rails if isolation cannot be achieved.
What Coding Badly is pointing out is that interrupt service routines (ISR) must execute quickly. There should be nothing to slow them down, they should do a minimal amount of work and then exit. Furthermore, nothing that depends upon interrupts (such as Serial I/O and delay(...)) should be used in an ISR.
Steam engines, motors, and solenoid valves rarely require the speed and challenges encountered with interrupts. Are you certain that you want to go this way?
vaj4088:
What Coding Badly is pointing out is that interrupt service routines (ISR) must execute quickly. There should be nothing to slow them down, they should do a minimal amount of work and then exit. Furthermore, nothing that depends upon interrupts (such as Serial I/O and delay(...)) should be used in an ISR.
no, that isn't what he is pointing out at all it isn't about the speed of the ISR.
delay() doesn't work within an ISR because of its reliance on interrupts.
delayMicroseconds() does, but for very short delays
Avoid delay() anything unless absolutely needed, and definitely never inside an ISR.
Use a global counter or flag, and modify that within the ISR.
Manage that counter/flag in the fast main loop().
The solenoid valves that run off the relay board were grounded to a point on the Arduino. I moved the ground to the power supply ground stud and that helped immensely.
So I consider the root cause for the issue a "back voltage" and grounding issue.