This is my first Arduino project. I have a sketch to control a pump based on the water level in a tank. when the tank runs out of water, the pump is turned off, and when the tank fills with water, the pump is turned back on. There is a pump enable, if that is set to LO the pump is disabled completely.
I've attached a circuit diagram. The two outputs are pump run and pump stop, which are simply the inverse of each other.
I hooked this up on a breadboard with the relay disconnected - so only the two LEDs connected to the outputs. Everything works fine. When the pump is 'enabled' it works fine - ie the pump run output only goes high when there is enough water in the tank (I should say the two water level inputs are configured with internal pullup).
However - when I add the relay to the system such that there is some 'real' load on the system the system stops working - even if the two water level inputs go open circuit (pulled high), the pump run stays HI and the pump stop stays LO. If I remove the relay from the system, everything starts working again as expected.
I'm very much a newbie to this and can't understand at all how this can be the case.
When the pump run output is enabled the voltage on the output pin is +5V, current into the base is 4.3/330 which is 12 or 13mA which seems ok.
One more thing. I have just connected the pump enable input to +5V directly and now everything works as expected again. So this problem only seems to occur when I am using a shelly (basically a wifi enabled switch) to control the input (voltage). The pump enable is configured as an interrupt as so:
Is the Shelly powered from the 12V line as well, or is the 12V line connected to just the switch (I/O) with the resistors forming a divider to derive a 5V input?
Do you have a DMM to measure the voltage on the 12V line?
I suspect that your 12V supply does not provide enough current to power all 3 devices and drive the pump and Shelly switch relay simultaneously so the voltage on the 12V rail sags, the relays don't operate and you don't get the correct signal to your pump enable pin.
If you want the transistor to last, then add a kickback diode across the relay coil.
If you want the relay contacts to last, then add a kickback diode across the pump.
Leo..
BitSeeker, Voltage was still > 12V even with the coil in the circuit. I had a spare beefy 12V supply knocking around and switched that in as a test. Even with the bigger power supply I saw the same issue. I forget to mention that the pump is a 240VAC pump, so in fact the 12V was not powering the pump itself. I have updated this on the diagram.
Wawa thanks, I was not aware of the kickback generated by inductors. I read up on this a little and understand what is happening now. I added a kickback diode IN4007 across the coil - success! I'm not sure I fully understand how the kickback on the output side could affect something on the input side but no doubt there is a lot going on here that is not obvious.
Apologies had not mentioned the pump was in fact 240VAC previously. Am I correct in thinking that a kickback diode would only be required for a DC motor?
johnerrington thanks, yes, I am uploading an additional diagram with further info including the solution and part numbers etc. I am using the Arduino Uno - I have marked the pin numbers in use on the diagram.
Which Shelly device are you using please? I am assuming Shelly1, but could you please confirm? What are the values for those resistors between Shelly and ground? Could you show all the connections to the Shelly please?
There are hundreds of posts here asking for solutions for misbehaving or resetting processors and relays stuck in the 'on' position (welded contacts). For mains AC motors you might have to add a snubber circuit and/or MOV across the contacts.
Leo..
Kickback appears usually as a spike in current and voltage, this spike can be INDUCED into adjacent wiring or across PCB tracks to produce a spike in associated wiring,
This spike can be big enough to cause the controller to reset.