Relays stay on - clicking on and off

hi i just created an auto reel stop for a japan slot machine using an aurdino r3 along with a 4 channel relay, the problem i am having is that the relays click on and off even when the reel spin knob is not touched, can anyone help here with this if needed i can provide you my software program, thanks marcUse code tags to format code for the forum//japanese pachislot autostop mod:
//mcrowell75 and Atlanticom 2021:
//This code was written for an arduino nano and a 4 channel relay module:
//It has been tested on an IGT "Popper King" pachislo:

int button_1 = 2;
int button_2 = 3;
int button_3 = 4;
int spin_in = 5;
int spin_out = 6;

void setup() {
pinMode (spin_in, INPUT);
pinMode (button_1, INPUT);
pinMode (button_2, INPUT);
pinMode (button_3, INPUT);
pinMode (spin_out, OUTPUT);

digitalWrite (spin_out, HIGH);
digitalWrite (spin_in, HIGH);

}

void loop() {
if (digitalRead (spin_in) == LOW) {

digitalWrite (spin_out, LOW);
digitalWrite (spin_out, HIGH);
delay (random (1000,3000));
pinMode (button_1, OUTPUT);
delay (100);
pinMode (button_1, INPUT);

delay (random (500,1500));
pinMode (button_2, OUTPUT);
delay (100);
pinMode (button_2, INPUT);

delay (random (500,1500));
pinMode (button_3, OUTPUT);
delay (100);
pinMode (button_3, INPUT);

}

}

In order for us to help you, we need to understand your project.

Post your code and wiring diagram.

To post your code, do the following:

Hi, @rodneyfreilich

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Thanks.. Tom.... :smiley: :+1: :coffee: :australia:

Quite likely you don't have any pullups on your buttons.
You should use INPUT_PULLUP instead. (buttons wired to GND).

What's the purpose of this?

And this?

//japanese pachislot autostop mod:
//mcrowell75 and Atlanticom 2021:
//This code was written for an arduino nano and a 4 channel relay module:
//It has been tested on an IGT "Popper King" pachislo:

int button_1 = 2;
int button_2 = 3;
int button_3 = 4;
int spin_in = 5;
int spin_out = 6;

void setup() {
pinMode (spin_in, INPUT);
pinMode (button_1, INPUT);
pinMode (button_2, INPUT);
pinMode (button_3, INPUT);
pinMode (spin_out, OUTPUT);

digitalWrite (spin_out, HIGH);
digitalWrite (spin_in, HIGH);

}

void loop() {
if (digitalRead (spin_in) == LOW) {

digitalWrite (spin_out, LOW);
digitalWrite (spin_out, HIGH);
delay (random (1000,3000));
pinMode (button_1, OUTPUT);
delay (100);
pinMode (button_1, INPUT);

delay (random (500,1500));
pinMode (button_2, OUTPUT);
delay (100);
pinMode (button_2, INPUT);

delay (random (500,1500));
pinMode (button_3, OUTPUT);
delay (100);
pinMode (button_3, INPUT);

}

}

how then should the software program be? rodney

Hello @rodneyfreilich ,

I'm not in a position to give you more than a quick answer but I believe you can find your solution here:

In short I suspect you don't have pull up resistors and you need to understand the difference between detecting when a button is pressed and detecting when it becomes pressed.

1 Like

i want each reel in the slot machine to stop from left to right

hi tom did you receive my emails ? rodney

Please, STOP POSTING THE CODE AS PLAIN TEXT!
Now edit your posts, select the code and use the button shown on post #2 from @ruilviana and save it. Don't add new posts until you did that.
Thank you.

1 Like

hello, are you still with me??

are you suggesting i re write my sofware set up here?? please explain?

@rodneyfreilich Until you post your code as outlined in post #2, we have no faith you're comprehending anything else being asked of you. It's that simple. If you post as requested, people can then copy your code to their IDE and test/modify in order to help you.

As it is, it seems you're in such a hurry to get a solution, you can't be bothered to provide the necessary information for anyone to begin to provide you with a solution.

2 Likes

please explain what will this INPUT_PULLUP would actually do?? please keep in mind this is all new to me and i am not a software genious!

I've linked you to a tutorial that explains what input pullup does, see post #9. When you've read it, if you come back with questions that show you've read it then I or someone will clarify. As it is, others have commented about you not doing as they ask or providing basic information so until that happens I will leave you to your project.

1 Like

TOM did you receive the information i provided you???

So get reading, there are online courses, videos, books, and whatever else you can think of about Arduino.

1 Like

There's no need to be a sofware genius to understand what we're asking you to do, to be compliant with the forum rules and kinda "netiquette", Keep ignoring those requests, and we'll keep ignoring yours. Have a nice day.

2 Likes