Blinking LEDs With Delay Function
Our goal in this project is to blink the default Arduino LED and to also toggle a predefined output pin. We will be using the “delay” function for this example.
In order to blink an LED we will first need to set the pin as an output. This can be achieved by using the pinMode() function.
The following code snippet sets pins 0 (D0) & 13 (built-in LED) as output pins.
Next, we need to set the outputs to logic high (turn them ON) and then set them to logic low (turn them OFF). We also need to add a delay after setting each of the logic states in order for us to view the state. If we do not add this delay, then the Arduino will repeatedly toggle the pin state and we will not be able to see this as the code is executed code much faster than our eyes and brain can process information.
The complete Arduino project is available for download using the following link. Downloads are restricted to registered users. Registration is and will always be 100% FREE.
Project Source: P1_Arduino_Blinking_LEDs_With_Delay.zip
This project uses standard Arduino libraries and is thus compatible with all Arduino boards that contain the built-in LED (on pin 13) and digital pin 0. Make sure the correct board is selected in the Arduino IDE.