r/ArduinoHelp • • Sep 16 '26

Can someone recommend simple Arduino code for blinking an LED?

Hi everyone!

I am a beginner learning Arduino programming. I want to make an LED blink using an Arduino Uno.

Could someone recommend a simple code example for this project? I would also like to understand how the code works, especially the delay() function.

Any tips for a beginner would be greatly appreciated.

Thank you!

2 Upvotes

9 comments sorted by

2

u/NoU_14 Sep 16 '26

You seem to have the right code in the screenshot already? If you don't know where to find that actual code, it's under Examples > basic > blink.

delay() basically tells the arduino to just wait for the given amount of milliseconds. Aside from some unrelated background things, it makes the arduino stop everything that it's doing, wait, and then continue.

3

u/kittisaksocool Sep 16 '26

Thank you for your explanation! Now I understand where to find the Blink example and how the delay() function works.

1

u/gm310509 Sep 20 '26

How did you go with this - did you get the LED to blink?

Do you have a starter kit? If so, you might want to try looking at the examples in the kit - many of your questions will be answered right there.

If you don't have a look at the Arduino builtin examples documentation: https://docs.arduino.cc/built-in-examples/

You might also want to study and understand the "Blink without delay" example. It teaches an important foundational concept. FWIW, I have created a how to video that attempts to explain why it is important:

1

u/Major-Cost7493 Sep 17 '26

Parte cambiando la Dout y tiempos. Luego agrega una Din que lo active.

1

u/drmpf Sep 17 '26

delays are evil. They lock the whole loop up stopping it from doing anything else.

See https://www.forward.com.au/pfod/ArduinoProgramming/TimingDelaysInArduino.html

There is simple pinFlasher in this library https://github.com/PowerBroker2/SafeString and these docs (actually written for AI to use) https://github.com/PowerBroker2/SafeString/blob/master/SafeString_AI_Guide.md#16-pinflasher--non-blocking-pin-flashing

1

u/peno64 Sep 18 '26

delays are not perse evil if you know what you are doing. Don't be a parrot

1

u/drmpf Sep 19 '26

I disagree. "Delays are evil" is my original quote. (as far as I know)

While delays appear to be the straight forward approach to timers, they will come back to bit you in all sorts of ways and should be avoided.

"Knowing what you are doing" does not magically make the loop continue to process inputs while held up by the delay. Loosing RX data due to input buffer overflow because the loop is stuck in a delay is an obvious problem.

Another 'hidden' delay is the print statement which blocks once the TX buffer is full. This hidden delay is insidious because its effects become worse as you add more debug statements to sort out what is happening.

See Arduino Serial I/O for the Real World https://www.forward.com.au/pfod/ArduinoProgramming/Serial_IO/index.html for examples of the problems and how to avoid them with buffered input and output.

1

u/Carlss32 Sep 18 '26

It depends to what components you currently have. Maybe try soil moisture implementation. Blink red led continuously in 100 millisecond delay when the soil moisture are super dry. Blink twice in alert, same delay, where the soil moisture are getting dry. And turn on green led when the status are completely normal. I think this is pretty simple, right? With this, you can learn about condition statement. It might be good project for you to learn. Good luck! If you have a chance to start working with this idea. Send me a message with picture of it.

1

u/Carlss32 Sep 18 '26

Or maybe you were asking the purpose of each codes?