Weird signal coming from a digital pin

I have noticed something strange happening in my simple circuit: a pushbutton with a 10kohm pull down resistor that turns on an LED when it’s pressed.
My Arduino loop cycles at 100Hz more or less.
Yellow probe connected through the yellow cable to the 10 kOhm pulldown resistor.
Green probe connected through the green cable to the dgt output pin 4. this output signal has a freq of 50Hz. I had this pin toggling just to understand how fast my loop is.
10X probes
Trigger on the yellow signal.
The 50Hz yellow signal disappears when I disconnect the green probe or I cancel the last two instructions in the code loop.
I can’t understand what’s going on.

Cheers

Hello,

It is beyond my understanding why anyone would think it's a good idea to post an image of text!!!

Before you do anything else please take a moment to read General guidance
And
How to use this forum
Especially item #7 on posting code.

I suspect that if you put your oscilloscope probe pretty much anywhere on the Arduino you'll get the same or similar. I also suspect that if you move the ground connection for the 'scope probe to the ground on the Arduino it will go away or be substantially reduced. Make sure you connect only one ground to the 'scope.

What you are seeing is ringing. This is a brief oscillation in the parasitic inductance and capacitance that exists in all circuits. It will be being triggered by a sudden change in current somewhere in the circuit in response to what the code is doing. I suspect it is associated with the power connections, which is why I said to try moving the 'scope ground connection to the Arduino.

I attached a photo because it's a super simple sketch and the problem is hardware not software.

Btw here is the code:

// Turn on the LED while the button is pressed

const int LED=2;  // LED connected to digital pin 2
const int BUTTON=3;  // button connected to digital pin 3
int buttonState=0;  // buttonState stores the value of the button state

const int LOOP=4; // Needed to check the loop speed
int loopIndicator=0;  // Needed to check the loop speed

void setup() {
  pinMode(LED,OUTPUT);  //Set the digital pin as output
  pinMode(BUTTON,INPUT);  //Set the digital pin as input
  
  pinMode(LOOP,OUTPUT);  // Needed to check the loop speed
}

void loop() {
  buttonState=digitalRead(BUTTON);  // read input value and store it

  // Check whether the input is HIGH
  if(buttonState==HIGH){
    digitalWrite(LED,HIGH); // Turns the LED on
  }
  else{
  digitalWrite(LED,LOW);  // turns the LED off
  }
  delay(10);
  
  digitalWrite(LOOP,loopIndicator);  // Needed to check the loop speed
  loopIndicator=!loopIndicator;  // Needed to check the loop speed
}

The ringing becomes slightly smaller if I use the board ground for the scope probes but it doesn't disappear.
It disappear if I disconnect the green probe or if I don't write the last two lines of code

Thank you for posting your code, now I can try it.

I get a nice, clean square wave on pin 4, with a change of state every 9ms or so (shows how inaccurate timing with delay() is!). I don't have any of the other stuff connected that you have.

On your video you seem to have channel 1, yellow, connected and displayed, but as asking about channel 4, green, so that doesn't make sense. I hadn't noticed that when I first read your post. Which are you asking about? Ch4 or Ch1?

For timing loop, you can also run the loop a known number of times, with millis() saved at start and end of run, or have it print millis() out every however-many runs - just need to make sure you're not printing stuff faster than serial can output the characters (hence why not printing it out every run).

eg
static byte i=0;
if (i++==0){
Serial.println(millis());
}

will print out millis on the first pass, and every 256th pass after that. Assuming the number of characters being printed doesn't take longer than running your loop 256 times does, this will be pretty close - there's some overhead to sending the characters in the background, but as long as the time for 256 loops is long compared to the time it takes to output the string, probably not much. The test slows the loop down, but only by a very small amount, a couple of instructions; there might be slight changes to the test that would save an instruction or two, but when your loop has delay()s in it, the magnitude of that error is small.