I am having trouble with this school project. I am running some pumps and motorized ball valves with the Arduino Uno and a 4-Channel Relay. For some reason Pump_1 starts up on its own and completes its cycles. Any ideas on why it is doing this?
Also new to coding so hope this code makes sense. TIA
Probably not related to your issue, but if you've tested the result of a digitalRead to see if it is LOW (and it isn't), you don't have to test it again to see if it is HIGH
I really can't make head or tail of that picture - too many wires the same colour and, for fun, changing to a different one along the way.
I'd do some simpler experiments with code that just turns one relay on & off & prove that the wiring for each is right. And to be clear, I'd have a sketch that runs only one relay and adjust the pin numbers it uses between tests.
Actually pretty neat code!
Can still be improved, but seems to code for what you want it to do...
What kind of buttons do you use?
Does it have 3 contacts?
Are they identical?
So I have been playing around with the wiring to see if everything is connected and I have found two things:
(1) The momentary switch will activate by touching the non-ground wire (so wires from pin 6 and 7). Im curious, why is this the case?
(2) I attempted to organize the wires with zip-ties. I had them very tightly bound together. Once I cut the ties off my problem seems to have been fixed. The program is not running until the button is pressed. Thoughts on this?
Single "Dupont" wires wandering from point to point in a spider web are probably not reliable and completely inappropriate for a fully working system. Chinese-made ones as commonly sold, require full testing.
One thing I've done and seen recommended, is to solder a Nano to a proto board. Then either short wires point to point flat to the board, or a custom PCB with traces and wire/plug connectors of your choice. All wires should be shielded if they are not already in some shielded conductive enclosure.
The Uno doesn't have any good connection options for a permanent installation. The closest thing is a proto shield with your choice of connectors custom soldered to it, or as above, a custom shield PCB.
Well, that would provide more reliable connections, but is seriously "over the top".
Really, the UNO is a very poor choice. With a Nano, you can either solder directly to the board, or solder pins and mount into a(n inexpensive) "screw shield" or solder it to stripboard to facilitate multiple connections.
It seems for the relay board you would still have to use the "Dupont" connectors but you can get multi-way "shells" that hold the pins together and prevent them individually dislodging.
I note you have powered it correctly, but have something plugged into the "barrel jack" of the UNO. This is not a good way of powering it; there are complications.