Blinking LED using Arduino
How to Make an LED Blink with Arduino
Let’s start from the beginning, you’ve just bought your first Arduino board, you don’t know where to start… The blinking LED has been the first project for many young engineers, and for good reason. This circuit is simple enough for beginners to understand but still allows us to learn the basic functions of the Arduino IDE and microprocessors. If you’re struggling with the theory see our theory posts for help!
What you’ll need:
1x Breadboard
1x 330R Resistor
1x LED (Any colour)
2x Jumper Wires
How do I start?
The first thing to do is to take a look at our photos above to see how the circuit is constructed, and then have a go building it yourself! Hint: Use the circuit diagram when building it, it’s there for a reason.
The LED is connected to Digital Pin 8 of the Arduino via a resistor. A quick summary of the circuit can be seen below:
Pin 8 > 330 Ohm resistor > LED > Ground
Let’s run through what the code is doing
The following code is used to activate an LED using the Arduino Microcontroller. This part of the circuit is inside ‘void loop()’ therefore the steps mentioned above repeat forever or until told not to.
The pin 8 is set to ‘HIGH’ which allows the LED to be activated, ‘delay(2000)’ ensures the LED stays on for 2 seconds.
After 2 seconds the LED pin goes ‘LOW’, ‘delay(1000)’ ensures the LED is kept off for 1 second.
Keep in mind the delay function, will stop all operations for the length of time specified in milliseconds. delay(2000) is halting all processes for 2000 milliseconds or 2 seconds.
Check out the information given on Arduino documentation to learn more.
Now open the Arduino IDE and copy the code below
If you don’t know how to do this, check out our Arduino Sketch set up tutorials and youtube videos.
// This code will blink an LED, on for 2 seconds and off for 1 second, attached to pin 8 on the arduino. int LED = 8; // Sets the pin the LED is attached to, this can be any of the digital outputs void setup() { pinMode(LED, OUTPUT); // Sets the LED to an output } void loop() { digitalWrite(LED,HIGH); // Turns the LED to High delay(2000); // 2 second delay digitalWrite(LED,LOW); // Turns the LED to low delay(1000); // 1 second delay } /* created 02/2020 by Jamie Buick graycode.ie */