Weird occurance happening....

So I've been working on a project involving a simple button. The button has a wire connected to one of the output pin slots. When ever I put my finger near the wire, not even touching it, the tx light flickers and the code executes for when the button is pressed. Why is this happening?

You have not tied the pin to 5v or ground with a 10k resistor.

If you are switching to gnd connect R to 5v, if you are switching to 5v, connect R to gnd. The R to 5v is preferred.

Weedpharma

well im following this setup...

Read my previous and the problem will disappear.

10k to 5v.

Weedpharma

Your problem is due to the IO pin "floating", it does not know what it should be. Your hand induces a voltage into the wire and the arduino reads it.

By tying to to 5v, it reads high until tou pull it low with the switch.

Weedpharma

Or use:
pinMode(12,INPUT_PULLUP);

Forum rule
When ever any one mentions something is acting weird it is always a floating input.

I second this rule...

Just like when you were a kid and the TV wouldn't get a good signal till you grabbed the antenna ("Dad, do I have to stand here and hold this antenna for the -=whole=- Superbowl?") wires pick up signals from all over the place. We count on this behavior with antennas... (in a way, an antenna is a floating input, catching signals that the tv or radio then interprets). That's why the pullup or pulldown resistors.

The truth is that no weird occurrence is happening. The titles of all these topics are wrong. Nothing weird about it. Floating inputs behave -=exactly=- as described by the OP, nothing weird going on, just science at work.

Another rule (?) appears to be

Once you have the answer to your question, leave the forum and not acknowledge the support or result.

This is not aimed at this post as it has only been a day!

Weedpharma

Well that rule is followed by only about 40% of users. After all it is old fashioned to say thank you.

weedpharma:
Another rule (?) appears to be

Once you have the answer to your question, leave the forum and not acknowledge the support or result.

This is not aimed at this post as it has only been a day!

Weedpharma

Well I'm with you 100% on this one! At times it just seems a waste of time and effort, a thankless job!! But we do it because we enjoy it and can. I can do the electronics and not too bad with the mechanics, but "C" that is my weakest point, so I struggle at times, play around with the code till it works...

Grumpy_Mike:
Well that rule is followed by only about 40% of users. After all it is old fashioned to say thank you.

Regards

Mel.

Grumpy_Mike:
Forum rule
When ever any one mentions something is acting weird it is always a floating input.

Unless the "something" is a servo, then it's powered from the Arduino 5V.