I am new to the forum and I hope I am not writing in the wrong place!
I am writing to you because I have a simple code that does not seem to work in the correct way, I will explain what it should do.
I have an Arduino UNO R3 (powered via 9-12V PIN from an external power supply) to which is connected a 5V relay that activates a pump (powered at 12V from an external power supply).
My intention is that 4 times the pump will turn on for 5 minutes and stop for 1 minute after which it will turn on for 5 minutes and stop for 5 minutes. Then start again from the beginning.
Example:
5 min ON - 1 min OFF
5 min ON - 1 min OFF
5 min ON - 1 min OFF
5 min ON - 1 min OFF
5 min ON - 5 min OFF
back to the beginning
Then there is a second 5V relay that activates a fan also powered at 12V from the same external power supply as the pump.
I don't understand where the error is, but sometimes the pump keeps going without stopping anymore, sometimes it stops without activating anymore.
Sometimes I seem to experience a very brief interruption of 1 or 2 seconds and then it restarts immediately.
could it be a power glitch because you're powering the pumps, relays and arduino with the same supply?
could disconnect the pumps from the relay and see if you have the same problem. if so, try replacing the relay with an LED (use LED_BUILTIN) and see if the problem clears.
if either case, may need a (8V) regulator with a large capacitor on it's output to supply the Arduino and/or a 5V regulator supply power to the relay (presumably instead of powering the relay thru the Arduino, don't know)
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, component names and pin labels.
In particular your relay and a link to its specs/data.
What are you using as your power supplies?
in your setup() function, open the serial monitor window and make sure it is set to 115200 to match the sketch, and you will see (maybe) that a power problem is happening.
You can use Serial.print strategic like to see where your program has flown.
Syntax
delay(ms);
Parameters
ms: the number of milliseconds to pause. Allowed data types: unsigned long
delay() takes an unsigned long as an argument. For constants larger than 32767, you should use the UL specifier like