digitalWrite LED not working?

I am working on a sketch involving a LED. I noticed that at startup, the LED (at digital port 8) is ON and not OFF.
So I added a digitalWrite(8, LOW); to the void_setup, but it does not seem to work. At power up the LED comes on and stays on.

Even if I put a digitalWrite-LOW in the main-loop, the LED stays on.
If I make it a blinking LED with writing HIGH and LOW, then it works as expected.

What am I missing here?

//  Variables
int LED1 = 8;    // Ped-pin for LED
// Basis
void setup() {
  pinMode(LED1, OUTPUT);
  digitalWrite(LED1, LOW);
}
// Main loop
void loop() {
  //digitalWrite(LED1, HIGH);
  //delay(1000);
  //digitalWrite(LED1, LOW);
'  //delay(1000);
}

How is the led connected ? Can you show a photo of it ? Does the led have a resistor ? Which Arduino board do you use ?

The pinMode() function after a power up sets the output default to LOW.

While searching for the problem, keep in mind that something might be broken.

A simple reason could be that you have connected the LED to 5V and the pin... (instead of GND and pin).

Then a HIGH on the pin will switch off the LED and a LOW would switch it on ...

THANK YOU!
That was the problem. The LED was connected the 5V rail on the breadboard instead of to GND.
Very much a beginner's mistake I admit (I confess I have only recently started playing with Arduino stuff).

The sketch I am working on measures distance with an ultrasonic sensor. Am also using a DHT11 to measure temp and humidity to correct the soundspeed for the calculations.
And then display all this info to a .96 OLED screen.

The idea is to have the LED blinker faster as a measured distance get shorter and slower if the distance is large.
That works now. But I still need to figure how to blink the LED slower or faster without slowing down the main-loop. (It's now being done with a adjusted delay-statement which of course simply slows down the loop.

You would use millis(), as demonstrated in the example sketch, BlinkWithoutDelay.

See @anon57585045's suggestion. Designing functions that do things in destinctive time intervals without using blocking functions (like delay()) is one of the essential capabilities...

You should try to get a good understanding of how to work with the millis() function. That will avoid a lot of frustrating hours... :wink:

BTW would you mind to mark this thread as "solved"?

I guess the use of non-blocking delays is a new issue;-)

Thank you everyone for responding so quickly.
The millisec-option is one I am looking into right now but I should be abe to figure that out. Hadn't seen the example before but looks like this is the solution I was looking for.

And do not hesitate to ask again if you encounter problems or need assistance...

Good luck with your projects!

Here is a link that may be quite helpful

https://www.norwegiancreations.com/2017/09/arduino-tutorial-using-millis-instead-of-delay/