odd problem . led turns on when hand is near

o I took the code from the DigitalRead reference entry and tried to use it to turn on an LED using a switch (just wanted to try DigitalRead, I know I don't need to do it to use the switch). I got an LED connected to pin 12 and a switch connected to pin 7. The only time the LED turns on is when the switch is on AND my hand is nearby (not even touching, just nearby, regardless if i'm grounded with the wriststrap or not). The circuit with the switch doesn't even have to be completed; I can have one wire in pin 7 and the other in the air not touching anything; I put my hand nearby and the LED turns on.

When using a code that does not contain a digitalread value
I do not have the problem
But when I use the digitalread code, the problem occurs and when my hand is near it, it turns on the hand
What's the solution because my hand affects digitalread

remind
I have used more than 10 codes

rinoum123456:
a switch connected to pin 7.

The switch should be from the pin to ground, and you should pinMode() the pin as INPUT_PULLUP.

Then the pin will be high when the switch is open, and low when closed. So look for it to be low in your digitalRead() as acrive.