Arduino – LED




What we do
What we need
How we do (Hardware)
How we do (Software)
Still shots Outcome
What we do

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. 🙂

What we need

 

 

 

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. 🙂

How we do (Hardware)

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 (+)

How we do (Software)

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.

 

HowTo Upload Sketch

 


  • 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

}
Still shots Outcome

From this course, we've learned how to set pin for LED output, how to turn it ON/OFF and how to give it a delay.

Please look at some still shots and compare what you have done! 🙂

 

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *