Switch that I cannot connect to ground

hi, this is my first post so sorry if its in the wrong place

I am doing a school project that is to make a flight sim controller for my friend, everything is working fine apart from 3 specific buttons. they are the type of button that stays down when on until pushed again and it comes up (don't know technical term :slight_smile: )

I have basic written code that just prints the current state of the switch (high or low) into the serial monitor.

my problem is that when the switch is depressed, everything is fine and I get a steady positive signal, but when it is unpressed then the signal is floating between 1 and 0 because it is not connected to anything.

it is not connected to anything because the button only has 2 pins for the button part of it and no way to connect it to ground, which is how I plan to set it to low

is there a way I can get my Arduino to 'default' this pin to ground whenever it is not connected to anything (I tried just sticking the ground pin in the same part of the breadboard - didn't have high hopes - didn't work :frowning: )

Thankyou for reading,

Use a pull-down resistor. 10K is a good value. Connect between the Arduino pin and ground.

Alternatively, wire the switch between the Arduino pin and ground and use pinMode(pin, INPUT_PULLUP);

thank-you for answering so quickly, so if I have the + coming from the switch and a 10k ish resistor pulling it to ground on the same 'lane' of the breadboard, it will stop floating between 0 and 1?

Ill admit I've only ever tried it without a resistor, but when I did, the Arduino turned off, ill try adding a resistor.

Study this pic:

Pin 1 of the inverter can be replaced with your Arduino input pin.

Here are ways to connect a switch (credit to larryd for the diagram).

thank you very much everyone, will give this a try tonight, when I'm back at home

thanks again for the quick, helpful responses!

(you will be added as sources in my bibliography :slight_smile: )