I have a project with a nano setup where pin2 (INT0) is pulled high using its internal resistor and listening for interrupts on a falling edge. On an output pin the nano is also controlling one of THESE relays to switch 12v dc. Within the project spec when an interrupt is fired it switches the relay off.
With a 12v led strip connected to the relay the project performs as expected; it switches the relay on, the led strip is lit for the specified time and the relay is switched off early if an interrupt is fired. Likewise if nothing is actually connected to the relay, it clicks on as it should for the specified time again performing as I would expect. If I however connect a 12v solenoid valve to the relay, when the relay switches on it appears to somehow pull pin2 low; an interrupt is fired which (in accordance with the sketch) in turn switches the relay off - the result is the relay is only activated for a split second.
For power I'm using a desktop ATX psu, 5v going to the nano and 12v going to the relay.
I am confused why/how the solenoid valve is causing the interrupt to fire, can someone explain why this is happening and what I can do to prevent it?
Do you have pull-ups enabled on D2?
Help us, help you, show us your sketch.
Yes, as mentioned I'm using the internal pull up resistor and pulling the pin to ground to fire an interrupt.
(Edited for clarity).
If the solenoid, relay and nano all use the same master power source, it could be that the solenoid coil is triggering a spike via the power source that is triggering your pin. I would start here De-coupling and try to see if this is in fact the case and maybe some creative application of decoupling capacitors can help. (or consider using a stronger external pullup resistor)
Nicely written blurb from the MBED manual...
Switching high current inductive loads and motor arcing can put noise spikes or voltage surges on power supply lines and it is possible that they can become large enough or that the supply voltage could momentarily drop low enough when turning on a large inductive load to cause a microprocessor to crash and even reset when using the same power supply as the load, so additional power supply decoupling capacitors may need to be added near the high current load, or a separate power supply can be used for the high current load.
That looks like you might have hit the nail on the head pwillard. Will test as best as I can tonight. Thanks.
So after a bit more debugging given pwillards suggestion I've isolated the issue down to the inductive load (the solenoid valve) and the fact there's a common ground between the 5v powering the arduino and the 12v powering the rest of the components. A more accurate representation of my circuit is this...
The rgb leds are a 12v strip and switched using transistors hence the need for the common ground; the valve is powered from the same 12v which means the relay isn't technically isolated from the arduino. If I separate the solenoid valve out so it's powered by another discrete 12v supply the circuit functions fine. However I'd rather not have to dedicate a second supply just to power the valve when the one supply is powerful enough.
I've read the linked article on de-coupling but still a little confused how I would apply it to my circuit. Can someone suggest how best to solve this? Would it be as simple as placing a cap in parallel with the solenoid valve?