two pole buttions

… ok so i bought some buttions from ebay they happen to be two pole buttions they accept power from either side and output it if pressed … im having trobble using this with my arduino because either there is some magnetic interferance or i messed up some how.
ok so i have a wire conected from 3.3 volts to a 10k resistor then to the buttion and back to pin 9… when i run my program i made which toggles a lcd screens back light i get the screen flashing if i do so much as bump the wires conected to the bread board. (due to the fact im making an os for arduino i have cut the small sample out that has the code needed, because im sure you dont want to read 112 lines)

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

void setup() {
pinMode(9,INPUT);
int lcdst= 1; // change pin 9 to input mode and prepare lcdst variable.
}

void loop {

if (digitalRead(9) == 1) { // check if buttion is pressed if so then run the following
if (lcdst == 1) {
lcdst = 0;
goto Quit;}
// flip the number from off to on or vis versa
if (lcdst == 0) {
lcdst = 1;
goto Quit;}

}
Quit:
if (lcdst == 0) {lcd.noBacklight();}
if (lcdst == 1) {lcd.backlight();} // power on or off the screen depending on if the variable is low or high
}

i have a wire conected from 3.3 volts to a 10k resistor then to the buttion and back to pin 9.

No, connect the resistor from pin 9 to ground and the button from pin 9 to 3.3 volt. This is called a pull down resistor.

you don't really need the resistor tho. The arduino has a built-in pull-up resistor so you can just connect the button to pin 9 and ground. then in the code you use pinMode (9,INPUT_PULLUP); to enable the internal pull up resistor.

the button will now read LOW(0) when pressed and HIGH(1) when not pressed.

Oh and it is not a 2 pole button just each side of the button has 2 pins.

I think that, when you touch one of the wires the contact inside the breadboard is breaking momentarily, which sends a signal to pin 9. Thats assuming your switch is NC, not NO. Rewire as kutkikz suggests.

Also consider debouncing the circuit in code if you have problems with erratic behaviour.

(also, being pedantic, I suggest you can eliminate gotos by using switch-case statement).

Goto is terrible programming and completely unnecessary here.
I cleaned it up for you, plus you’ve been here long enough to know how to use code tags (</>)PLEASE do so.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int lcdst = 1; // declare your variables here, NOT in setup

void setup() {
  pinMode(9, INPUT_PULLUP);
}

void loop {

  if (digitalRead(9) == 0) {  // check if buttion is pressed if so then run the following
    if   (lcdst == 1) {
      lcdst = 0;
    }
    // flip the number from off to on or vis versa
    else {
      lcdst = 1;
    }

  }

  if (lcdst == 0) {
    lcd.noBacklight();
  }
  else {
    lcd.backlight(); // power on or off the screen depending on if the variable is low or high
  }
}

I think that, when you touch one of the wires the contact inside the breadboard is breaking momentarily

No the pin is floating because it is not connected to anything when the button is not pressed, this is why a pull up or down resistor is needed, or better yet use INPUT_PULLUP.

There is more work to be done here but I’ll let you discover that for yourself. it’s a learning process

thank you for your help .... and sorry for my use of goto i started programming on old computers even tough im part of the younger generation... force of habit

Glad to have helped.

@yendis just noticed your sig, As my avatar suggests I'm playing with stuff for classic cars also.:)

@hutkikz i notiiced its alot esayer for wire management if i use the build in pullup feature… thank you again