Output comes on when I put jumper wire in input (not connected to anything else)

Hi all,

Noob here, doing my first project and using the "Button" Sketch. I am electrician so understand electrics.

I have relay board set up on Pin 13 and wired correctly. Have bread board with PB on it and 5v to one side of PB.

When I push a jumper into Pin 2 for the input the relay comes on and oscillates. Please note, the other end I jumper is not connected to anything. I can only think of noise. It is like the pin socket is a switch that gets shorted out when pin from jumper.

Any ideas?

TIA

This is called a floating pin. When set to INPUT mode, the pin can easily read either LOW or HIGH due to picking up electrical interference. You might notice it changes if you touch the board or even move your hand close to it. The wire acts as an antenna, which makes it even easier to pick up interference.

This is why the Button sketch instructs you to connect a 10K resistor to ground. That resistor ensures that the pin will be maintained in a LOW state until the button is pressed. When the button is pressed, the direct connection to 5 V overcomes the pull-down resistor and causes the pin to go HIGH.

Conveniently, the microcontroller has internal pull-up resistors, which you can learn about in the File > Examples > 02.Digital > DigitalInputPullup example and its tutorial:

it is called antenna

1 Like

Have a good read of this
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html
What you are seeing is perfectly normal.
Using pinMode( pin, INPUT_PULLUP) will solve this if you then go on to wire the button between input and ground.

Thanks all, I thought must have been something like that, turned monitors and comp off still had it. Wil incorporate resistor.

Appreciate your advice.

LittleAussiebattler:
Thanks all, I thought must have been something like that, turned monitors and comp off still had it. Will incorporate resistor.

No, don't add a resistor!

As explained by Mike, set your pinMode to INPUT_PULLUP and wire the switch between the input pin and ground. This is a much safer way to do things, you do not want any power wires (5 V) going anywhere to switches and such that you do not have to.