Arduino, need help with crazy interference

void setup() {
    pinMode(7, INPUT);
    pinMode(13, OUTPUT);
    Serial.begin(9600);
}

void loop() {
    Serial.println(digitalRead(7));
        digitalWrite(13, digitalRead(7));
    
}

This is it my code, one wire in pin 7. Touching the wire sets pin 7 to read high. Sometimes just waving my hands around is enough. And simply having my extension cord next to the arduino in a 30cm radius is enough to make it go off (with the wire plugged in). No matter which wire i put, even a short one it still does this. Plugging the arduino in a laptop does not help. Is my arduino busted or is there something bigger at play here? Could I somehow ground the arduino better? It is extremely difficult to test anything at all while this is happening.
Using a leonardo board.

EDIT: putting in a resistor does not change behavior

That's perfectly correct. The way You declared pin 7 it acts as a radio antenna.

Any ideas on how I could fix this? I can't even use the arduino with a protoboard like this

Connect something useful to pin 7, like a sensor, a resistor to Vcc or GND.
For example:

pinMode(7, INPUT_PULLUP); //activate internal pullup resistor

It is extremely difficult to test anything at all

What are you "testing"?

1 Like

How do You intend to use pin 7? What will be connected to it?

1 Like

In place of chasing the back side of the problem post an annotated schematic. You might post your code as well.

1 Like

Unfortunately, this information isn't useful, since we can't know where you "put it in".

I fixed it, I was just confused about the pinout of the component I was trying to connect. I understand now it's important to get the ground right.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.