Arduino: How to turn on an LED

Click to see full image

LED

An LED stands for Light-Emitting Diode. This is an electronic device that emits a light  when electricity flows through it in a certain direction.

LED vs. Bulb

An LED is a more dull light than a Bulb. An LED uses about three volts of electricity. A bulb uses about fifty volts of electricity. This is why LEDs are found everywhere where a small light is emitted. For example, they are found on the keyboard of a computer.

Materials Needed for this Program.

  • Arduino Board
  • LED
  • Computer to program LED

The Setup

On an LED, there are two metal pieces that the electricity can go through. Put the longer side into pin 13 on the Arduino board. If you put it the other way around, it will not light up

The Code

In order for the LED to light up, you need to program it to light up.

 

 

const int LED=13; //In this statement, we are giving the variable (LED) a value(13);

 

void setup( ) {

pinMode(LED,OUTPUT); // We are telling the board that LED or pin 13 is an output

}

 

void loop( )    {   // This is where the action takes place.  

   //The void loop tells the IDE to do something, whether it is turn on an LED or do an action when a sensor goes off.

   // In the void loop, you will tell the board to light up the LED

digitalWrite(LED,HIGH);//digitalWrite is telling when the LED is HIGH or on. If you write(LED, LOW) the LED will stay off always.

}

 

 

Const int

const int means that the output is connected to a certain pin. If you put the output on a different pin than the pin you gave the variable, the LED will not light up.

We write LED because it is the variable we are going to use in this program. We can write anything for the variable(s) as long as we change wherever we wrote the variable to the new variable.

Void setup

This is the setup of the program. It includes the pinMode

pinMode

This is inside the void setup. pinMode states that the variable LED is an output or input. It is still not doing anything. It is only storing the pinMode in its memory.

Void loop

This is where we are telling the board what to do. It is in a loop, which means it will keep going.

digitalWrite

This is inside the void loop. It tells the board to either turn on or off the output. HIGH turns it on LOW turns it off.

 

Capitalization

Make sure that all the letters are capitalized how I capitalized them. If they are not, it will give an error message.

Comments

Every line that begins with // means that it is a comment. The Arduino board will ignore this. It is for your benefit and understanding. I suggest making many comments that will help you so that if you have forgotten the meanings of the code the comments will explain what they do.

Semicolons

Notice that every line that is telling the board to do something ends with a semicolon. This tells the board that the statement you are trying to make is made. If you do not put the semicolons, it will give you and error message.

 

When you finished typing in the code, plug in the arduino board to your computer. Make sure to attach an LED to pin 13 on the arduino board. The longer side should connect to pin 13, and the shorter side should connect to GND (which stands for ground)

Press the check button above the code. When you press this button, the arduino software scans the code for any mistakes.

Then press the button next to the check button. This uploads the procedure into the board, and the LED should blink.

1 Comment on Arduino: How to turn on an LED

  1. I got what you intend, thanks for putting up.Woh I am thankful to find this website through google.

Leave a comment