Trying to get diffrent serial prints from 2 buttons [SOLVED]

Hey, im getting weird results trying to get serial prints from 2 buttons the two buttons are on my breadboard, one is left and one is right (the problem isnt in build) my code:

const int buttonPin = 11; //set pin for button 1 const int buttonPin2 = 12; // set pin for button 2 int buttonState = 0; //set the state of the button to anything which isnt HIGH int buttonState2 = 0; void setup (){ * pinMode (buttonPin, INPUT); //SET BOTH BUTTONS IS INPUT* * pinMode (buttonPin2, INPUT);* * Serial.begin(9600); // add serial commands* } void loop (){ * buttonState=digitalRead (buttonPin); // WRITE DOWN THE STATE OF EACH BUTTON* * buttonState2=digitalRead (buttonPin2);* * if (buttonState==LOW){ // CHECK BUTTON 1* * //button 1 is pressed!* * Serial.println("Right");*

  • }* else if (buttonState2==LOW){ //CHECK BUTTON 2
  • //button 2 is pressed!*
  • Serial.println("Left");*
  • }* }

what im receiving is an incredible amount of "right" and "left" and the same time , even thought im not clicking the buttons. rewrote the code several times but nothing helped

again, im tring to get a serial messege "right" when the right button is clicked and "left" when the left one is clicked.

can someone tell me what am i doing wrong?

any help will be totally appreciated, Amit.

can someone tell me what am i doing wrong?

Not using the state-change example in the IDE

Do you have external pullup resistors? If not, change the pin modes to INPUT_PULLUP.

Hey, tried changing INPUT to INPUT_PULLUP, now I only get signal from left button (only when I click it). Is there any other problem in the code or shall I re-check my schematics?

thanks for the help, Amit.

Hey, I found my mistake, turns out that the + and - parts of the breadboard are divided in the middle of the breadboard to right and left, I didn't know that but now I know, that was my problem.