Wrong digital input read (Pullup buttons, long wire)

Hello everyone !

I'm dying with a small bug that appears on my Arduino project.

I made a Simon Say's game exactly like on the Sparkfun's project (same wiring, same code, no change).

The only thing I did : I have 4 button that I put in a room of 16 square meters in each corner.
I have two wire (single thin wire) going from each buttons :
One is directly connected to the Arduino, and another one (GND) is connected to the next one, then to the next one, ... until being connected to the Arduino.

Well. Now the setup is done, when I press any button, I get the game to start.
And then, sometimes it works perfectly, and sometimes one or more buttons are giving the wrong input (for example, I push the Green button, and Arduino thinks I pushed the Blue button).

I tried to change the buttons, to check my connections, to put single GND wires for each button, adding a resistor before the connection to the Arduino.
But... nothing changes, I still got some input errors.
I do think it's because of the wire length. The longest on is approximatively 16 meters (52 feet, 630 inches), and each other is 4 meter less long.

Do you think that might be the problem ?
If no, do you have an idea of what it could be ?
If yes, is there a simple solution to solve that issue ?

Thanks a lot for anyone reading it and/or helping me !

Here is the link with the code and wiring :
https://learn.sparkfun.com/tutorials/sik-experiment-guide-for-arduino---v32/experiment-16-simon-says

Sixteen meters wires are long and the Sparkfun circuit is only for a very short wires.

The Sparkfun circuit uses the internal 50k pullup resistor to keep the signal HIGH when a button is not pressed. When you add a wire of 16 meters to that, anything can happen.

Use seperate cables from the Arduino to every button. A cable with a GND and the signal.
Do not connect a GND wire of one button to the GND wire of another button, because then you would have one big antenna and ground currents.
Add a pullup resistor of 470 ohm or 1k from the button signal to 5V for every button.
That should solve most trouble. Give it a try.

With 16 meter wires, perhaps you have to protect the Arduino against voltage spikes. For example with a resistor of 4k7 or 10k to every input.
The best solution to read the buttons is using opto-couplers.
To avoid trouble with voltage spikes and bouncing buttons, you could add a software filter.

A simple quick and dirty filter could be this:

byte checkButton(void)
{
  int red = 0;
  int green = 0;
  int blue = 0;
  int yellow = 0;

  for( i=0; i<10; i++)
  {
    if ( digitalRead(BUTTON_RED) == HIGH) red++;
    if ( digitalRead(BUTTON_GREEN) == HIGH) green++;
    if ( digitalRead(BUTTON_BLUE) == HIGH) blue++;
    if ( digitalRead(BUTTON_YELLOW) == HIGH) yellow++;
    delayMicroseconds(200);
  }

  if (red > 5) return(CHOICE_RED); 
  else if (green > 5) return(CHOICE_GREEN); 
  else if (blue > 5) return(CHOICE_BLUE); 
  else if (yellow > 5) return(CHOICE_YELLOW);

  return(CHOICE_NONE); // If no button is pressed, return none
}

Hello Koepel !

Thanks so much for your answer.
I'll try all this, starting by the software solution (that is the easiest to setup for a first try).

I only have one question, I did not understood why I can't wire all the ground of my buttons together ?
Because if I don't do so I'll not have enough ground connections on the Arudino. Do you mean having a single ground wire from each buttons ? I thought about that but my mind did not gave me a valuable explanation of why it could make a difference.

I'll keep you updated with those solutions you gave me !

guigro:
I only have one question, I did not understood why I can't wire all the ground of my buttons together ?
Because if I don't do so I'll not have enough ground connections on the Arudino. Do you mean having a single ground wire from each buttons ? I thought about that but my mind did not gave me a valuable explanation of why it could make a difference.

To minimise interference, have twisted pairs of wire from each button to your Arduino. However I'm not at all sure the issue is caused by interference.

Keopel's advice to use pull-up resistors of about 470Ω is good.

If they could get signals across the Atlantic in 1858, getting signals from your buttons should not be a problem!

guigro:
I only have one question, I did not understood why I can't wire all the ground of my buttons together ?
Because if I don't do so I'll not have enough ground connections on the Arudino.

You can tie more than one wire to a ground pin. But when you go button to button and make a big circle like that you've basically created an antennae and instead of reading your button you're picking up radio static.

I feel such a noob -_-
I felt proud until yesterday with that story :stuck_out_tongue:

Beginning of July I had 0 knowledge in electronic, just a few basic coding skills.
From that month I started making it. So far I realized a basic password machine, a triple RFID connected to led stripes, a system that plays music only when a door is closed, a prop bomb controlled through Ethernet and that Simmon says game !

But that button story seemed so basic it killed my growing proudness. That’s not so bad it reminds you not to go to fast.

The problem seems to be solved. I had to make two changes :

  • I tried the software hook, unfortunately it made the game act like a psycho robot making everything except letting me playing.
  • I added 10M resistor connected directly to the Arduino and to my buttons (made that as testing, so no soldering, I’ll have to do that). Seemed to work but some buttons where still acting like crazy !
  • And I made one change that no one could have adviced me because I forgot to mention it : my buttons are big ones like for arcade games with a led inside. To avoid wiring all the LED with separate connection, I wired the LED system directly to the button pins (VERY DIRTY SYSTEM). That caused a wrong behavior that added to the wire length : even when the button was not pushed, the LED let the power going through and closes the circuit, which means the button seemed to be pushed. And that simultaneously on 4 buttons…

So, I added those resistors AND took off those LEDs and now it seems to work !!
I have a big testing this week-end so I’ll tell you if it worked or not !

Thanks a lot, I’ll make that topic in my favorite in case I get some other errors with it !

guigro:

  • I added 10M resistor connected directly to the Arduino and to my buttons . . . .

Where is the 10MΩ resistor connected between? Do you have four 10MΩ resistors, one for each of the four inputs you are using? What is it supposed to do? Why choose 10MΩ value?

Are you using pinMode(INPUT_PULLUP)?

The 10M resistor is connected directly between the Arduino Digital Pin and the button wire.
As I'm not an expert, I tried with a 10M resistor and it seems to work.

And yes I'm using the INPUT_PULLUP pinMode :slight_smile:

guigro:
The 10M resistor is connected directly between the Arduino Digital Pin and the button wire.
As I'm not an expert, I tried with a 10M resistor and it seems to work.

And yes I'm using the INPUT_PULLUP pinMode :slight_smile:

If you are saying that the 10MΩ resistor is in series with the signal wire from the button then it shouldn't work at all. Why not connect the signal wire from each button directly to an Arduino input?

Here is how it looks like. Except the serie GNB wire is connected to a dedicated GND slot on the Arduino.

guigro:
Here is how it looks like. Except the serie GNB wire is connected to a dedicated GND slot on the Arduino.

Button presses would not be detected if those resistors really are 10MΩ (or even if they are 1MΩ as your Fritzing drawing shows).

Resistors in series with the inputs are not necessary. In some situations they could give some protection against the possibility of signals being outside the rated -0.5V to +5.5V range.

Why do you have resistors in series with the inputs?

I guess your LED resistors are 220Ω, not 220kΩ as shown in your Fritzing drawing.

Yes sorry, my Fritzing drawing is not very accurate regarding the resistors.

I put them as I thought that was what Keopel adviced me to do.
And I can't explain why it's working almost fine now

That was not what I had in mind.
I think you better start all over again, regardless if this is working or not.

Use two wire cable to every button. Tie the all the GNDs at the Arduino together. Do not use a GND wire from button to button as you have now.

Remove the 10M resistors. Connect the button wire directly to an Arduino pin.
Add 1k (or 470 ohm, or 2k2 or 4k7) resistors from the button signal lines to the 5V.

For example pin 2. Connect pin 2 directly to the button, and connect pin 2 also to a 1k resistor that is connected to the 5V.
For example pin 9, also towards the button and to a resistor that is connected to 5V.
And so on.

Like this: http://waihung.net/arduino-tip-built-in-pull-up-resistors/
Note that when the button is pressed, the digitalRead() returns LOW. When the button is not activated, the digitalRead() retuns HIGH.

Well so I did this. Wired a single GND for each button, then all button wire to my proto board, going to the Arudino Pin, and then through a 4k7 resistor to the 5V.

I also took the time to clean my setup.

AND...... It's working perfectly !!
I have the same result as with the previous solution I had, but I feel much better knowing it's better made. Like when you get a fake version of something and then you buy the genuine :stuck_out_tongue:

Thanks a lot !

If you want to help me I got some other issues with other setup ! :wink:

Reopened at the request of @slattynan

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.