Arduino – LED
We’re going to learn how to turn On/Off LEDs.
There is a built-in LED in Arduino Uno. Its pin number is #13.
We can also use another pin for turn ON LEDs and even use breadboard or not.
so we'll cover all these situations. 🙂
Please note that this kit also includes 'Breadboard' which was not mentioned in this post.
However you should need it in the next Arduino LED2 post.
With using breadboard, we can set up circuit quite easily and efficiently. You will get to know it soon. 🙂
Please see the following diagram carefully and make your own system just like it!
please note LED has two legs. (long and short)
Long lead is '+' and short one is '-'.
- Another example using breadboard
Arduino pin 3 - Ohm
Arduino pin GND - LED (-)
Ohm - LED (+)
Now, we're all ready to go in Hardware side.
Let's take a look at Software side then.
First of all, we need to know How to upload our sketch to Arduino.
- Blink LED without Breadboard
Step 1) Define the pin number that LED is connected to. 'int' means 'Integer' value.
int ledPin = 13;
Here, we're setting it as '13' pin.
Step 2) Configure 13 pin as an output. this means LED's output (ON/OFF).
void setup()
{
pinMode(ledPin, OUTPUT);
}
Step 3) Make LED ON/OFF with sketch's loop function.
it's going into loop function again and again just like its name.
digitalWrite function is to give HIGH or LOW to turn LED ON/OFF.
HIGH means ON and LOW means OFF here.
Also we should give them some delay by using delay function.
1000 means 1000 milliseconds, which is 1 second.
void loop()
{
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
}
- Blink LED with Breadboard
Now, we can use other pins rather than built-in #13 pin.
Take a look at 'How to do (Hardware)' tab and another example using breadboard.
and then type this code into your Arduino IDE.
int ledPin = 3;
void setup() {
//Initialize the digital pin as an output with pinMode()
pinMode(ledPin, OUTPUT);
}
void loop() {
digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(3000); // wait for 3 seconds
digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW
delay(3000); // wait for 3 seconds
}
Leave a Reply
Want to join the discussion?Feel free to contribute!