Hello, I'm new to the world of Arduino and I'm hitting a bit of a wall on something I'm trying to do. My setup right now is an Arduino Nano with an ATmega328 and a 4-relay board.
I want two relays to switch on and of randomly, and each of the other two relays to switch when one of two buttons is pressed (independently) which would connect the input to ground. I have some simple code that seems to work with a single button press (although I'm trying to use the internal pullup and for some reason it seems to be working backwards). That code is attached as "Button_Test.ino".
On the other side, I have some code that randomly switches two outputs for random amounts of time. It works fine on its own, so I tried adding that to a loop where I update the random outputs, then read both input pins to see if I should trigger one of the other two relays, then I have two "IF" statements to do something else if either of the inputs is LOW. But this code just seems to do all sorts of random stuff, including randomly triggering the two relays that are only supposed to be triggered from the buttons. That code is attached as "sketch_4_Relays.ino".
I would appreciate any pointers on this. I'm trying to get better but its been quite some time since I've done any sort of programming. Thanks!
Button_test.ino (255 Bytes)
sketch_4_Relays.ino (802 Bytes)