Go Down

Topic: Multiple Button Circuit (Read 2 times) previous topic - next topic

PaulS

It does not appear that the serial communication has anything to do with whether you press a button, or not.

If there is serial output before you press a button, and the serial output stops, and the exception is thrown, when you press a button, then you have a hardware problem.

How do you have the switches wired?

Grumpy_Mike

#6
Jul 22, 2010, 01:41 pm Last Edit: Jul 22, 2010, 01:42 pm by Grumpy_Mike Reason: 1
Quote
I connected every button to an own digital pin and connected it with a 10k resistor to the ground.

I don't think you have. I think this is wrong and you are shorting out the supply when you press a button and that is giving you the error.
The diagram you are using is easy to get wrong if the button is rotated by 90 degrees.

Also there is no need to go through the conversion from state[] to val[] these are the same things.

nullvoid

Thanks Mike. That was the problem! i connected the button, the resistor and the ground on a "straight line", thus overriding the resistor and producing a short curcuit.

nullvoid

Ok guys. Now everything is compiling nicely.

But the Arduino sends awkward values.

Again i just mutliplied this solution to get signals from 6 buttons:
http://arduino.cc/en/Tutorial/Button

This time i used this code:
Code: [Select]

const int button1 = 2;
const int button2 = 3;
const int button3 = 4;
const int button4 = 5;
const int button5 = 6;
const int button6 = 7;

int buttonState1 = 0;    
int buttonState2 = 0;  
int buttonState3 = 0;  
int buttonState4 = 0;  
int buttonState5 = 0;  
int buttonState6 = 0;  

void setup() {

Serial.begin(9600);

pinMode(button1, INPUT);
pinMode(button2, INPUT);  
pinMode(button3, INPUT);  
pinMode(button4, INPUT);  
pinMode(button5, INPUT);  
pinMode(button6, INPUT);  
}

void loop(){

 buttonState1 = digitalRead(button1);
 buttonState2 = digitalRead(button2);
 buttonState3 = digitalRead(button3);
 buttonState4 = digitalRead(button4);
 buttonState5 = digitalRead(button5);
 buttonState6 = digitalRead(button6);

 Serial.print("!");
 Serial.print(buttonState1);
 Serial.print(buttonState2);
 Serial.print(buttonState3);
 Serial.print(buttonState4);
 Serial.print(buttonState5);
 Serial.print(buttonState6);
}


It randomly produces values of 1 and 0 even if i dont press any button. And when i press a button its all the same: random values all over the place.

Is the code wrong? Basically its also just a multiplication of the code provided in this tutorial: http://arduino.cc/en/Tutorial/Button

Or is something wrong with the circuit? Maybe there are different voltages when i try to press and operate six buttons with one energy source?

Erika86

Sorry for the ignorance..I'm trying to duplicate the circuit of this page http://www.arduino.cc/en/Tutorial/Button but I don't know how to connect the wires in the right way. Anyone has an image?? :'(

Go Up