My arduino is doing really weird things

So, this is my code :

void setup()
{
  pinMode(7, OUTPUT);
  pinMode(12, INPUT_PULLUP);
}

void loop()
{
  if (digitalRead(12)) 
  {
    digitalWrite(7, 1);
  } else {
    digitalWrite(7,0);
  }
}

Really simple right ?

I plugged GND to a resistor to a led to pin 7 and 5V to a button to pin 12,
So if I press the button it should light the led right ? Well yes it does, but it also light the led when I'm just touching the cable from 5V to the button, it lights the led at random moments and just when my hand is close to the cables IT LIGHTS !!
My table is not made out of metal, and I don't understand, pls help

I have a Eelegoo Uno R3.

Pilot error. The button must be connected between pin 12 to GND. The INPUT_PULLUP makes the input high, when the button is not pressed.

If you use input pullup the button should go from the pin to ground, not to 5V.

Your user name is quite inappropriate.

Wire switches similar to S3 below:

I tried, it doesn't change anything, also my led is plugged in a digital pin and sometimes I get different intensity !! WTF ?!!

Show us a good schematic of your proposed circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.

I didn't think it would, since I couldn't imagine the described incorrect wiring causing those symptoms. But it was wrong, all the same.

Time for a schematic, as LarryD says.

Here, for example, I moved my leg, and the led lighted up.

Can we get a closeup of this:

image

Wire your switch as S3 in the schematic offered you.

Here it is, even why I remove the button, it does some weird things, like lighting up randomly, well it only does that, lighting the led, randomly

Your switch is not wired correctly.

LED turning on when you're merely touching the switch, right? It's due to debouncing problem. It can be vanished by adding a small delay.

Wiring using internal pullup.

Correct, the comment was to the OP

So you tell me to remove the resistor right ?

One terminal of the switch goes to the input pin, the other terminal of the switch goes to GND (0v).

Edit


if (digitalRead(12)) 

Suggest you be specific:


if (digitalRead(12) == LOW) 

Ok so I did that and the led doesn't light up anymore ! Even when I press the button xD [
¯\(ツ)

Oops, my mistake. That was meant to be a reply to OP, not to you. Sorry.

Show us a good image of the switch wiring again.

There might be a bad wire, you can try replacing them with others.