loading

In this Instructable, I'll show you how to connect an LED to an Arduino and turn it on using the code uploaded from the Arduino Application. This is very simple and easy to understand. Although I'll show only how to flash an led on, and how to blink an led, you can make changes in the code and make your own version.

Step 1: Get the Things That You Will Need:

You will not need a breadboard and jumper cables. A resistor of 330 Ohms is recommended but this is optional and I did not use a resistor.

But you will need some basic things to make this work:

- 1X An Arduino Board: I'll demonstrate using the basic Arduino Uno.

- 1X An LED:any colour will do.I'm using a red one.

-1XA USB type-B cable(not mentioned in the picture):any type-B cable.

- A Computer:One that can run the Arduino IDE and has a USB port.

- Enthusiasm:¯\_(ツ)_/¯.

Step 2: Understand the LED:

(Click the Orange links to get more info about those words.You can skip this step if you already know what an LED is.)

'LED' stands for Light Emmiting Diode. An LED(click Here to get more info) is a semiconductor diode which glows when a voltage is applied.

An LED has two metal legs, to which a voltage is applied. Usually, the shorter leg is identified as the Negative terminal or a Cathode and the other longer leg is identified as theAnode. The top curved part is the lens. It is usually made ofEpoxy and helps in intensifying the Light that is emitted. LEDs are available in many colours, like RED, GREEN, BLUE, WHITE, YELLOW, etc.

Here, in this project, we will call the Cathode or the positive terminal, as the Ground(GND) pin.

For this tutorial I'm using a RED LED, but you can use any colour you have.

Step 3: Connect Your LED to the Arduino:

As I described in Step 2, LEDs have two terminals. Now, to connect your LED, follow these steps:

- Identify your Negative pin, the shorter one, and insert it into the Digital PIN 13 of the Arduino.

-Identify your Positive Pin of the LED and insert it in the Ground(labelled as GND, beside the Digital PIN 13.)

(you can connect the Positive pin to any of the given GND pins, but that would require a jumper cable. So, it's up to you).

That's It! You have successfully connected your LED to The Arduino Board :)

Step 4: The Coding Part I (To Just Turn the LED On):

Now after connecting your LED, you need to get it to work, your board, if new MIGHT have the blink code pre-written, like my board did, but if it does not, you can upload the code, from the file that I have uploaded. Although in this Step, I'll show you the LED-ONLY-ON code,I'll demonstrate the Blink code in the next one.

You will need the Arduino IDE application to run this code, which you can find by clicking HERE

You can learn more about the Code used to program the Arduino by clicking HERE.

Open the OnLED_EverythingEasy.ino file that I uploaded and click the upload button(marked in the picture).

Now here's the code, Explained.

LINE 1: The word 'void' can be replaced with any datatype, like int, bye, float, etc(find out more about Datatypes HERE[From tutoorialspoint]) which tells the compiler beforehand that the function will return a value after performing a calculation. But her we don't need that because we don't have any calculations to perform.

the word setup is the name of the function. you can replace that with a name of your choice, like LED, blink, etc.

LINE 2: here the function pinMode configures PIN 13 as the output PIN.

LINE 3: the funtion digitalWrite sets the voltage level of PIN 13 to HIGH.(turns it ON).

TO RUN THIS CODE, OPEN THE FILE THAT I UPLOADED.

LINE 0 //this is a basic program to turn an LED on.
LINE 1 void setup() //functions

LINE 2 { pinMode(13,OUTPUT); //configures pin 13 as the OUTPUT pin

LINE 3 digitalWrite(13, HIGH); //switches on pin 13, connected to the LED

LINE 4 }

LINE 5 //written by EverythingEasy

Step 5: Turning the LED on With the Arduino: DONE!

You Have successfully Turned an LED on with the Arduino and the Code

Step 6: The Coding Part II(To Blink an LED):

It follows the same programming proceedure, but I've added a few more lines of code to turn it on and off.

Open the BlinkLED_EverythingEasy.ino file that I uploaded and click the upload button(marked in the picture).

Code, With Explaination:

Here, in LINE 4, the program instructs the board to turn the LED on.

In LINE 5, the program pauses for a second, keeping the LED on for a Second.

In LINE 6, the digitalWrite function, turns the LED off.

In LINE 7, the program pauses again, for a second, keeping the LED off for a second.

this keeps repeating forever, until the board is disconnected, or new code is uploaded, and flashes the LED on and off.

//this is a simple program to blink an LED repeatedly.
LINE 1 void setup() { // configure digital pin 13 as an output. pinMode(13, OUTPUT); }

LINE 2 // the loop function keeps running forever void loop()

LINE 3 {

LINE 4 digitalWrite(13, HIGH); // set the voltage level of PIN LINE 313 to HIGH, Turning It ON.

LINE 5 delay(1000); // Pauses the Program for a Second.

LINE 6 digitalWrite(13, LOW); // set the Voltage level of PIN 13 to LOW, turning it OFF.

LINE 7 delay(1000); // Pauses the Program for a Second.

LINE 8} //written by EverythingEasy

Step 7: Blinking an LED With the Arduino: DONE!

You have sucessfully Blinked an LED with the Arduino and the Code.

Step 8: Now You Can Try Your Variations!

Now with the help of the basics that you learnt, you can alter values of the code to make your own variations!!

Few examples:

- Change the number of milliseconds in the delay() function, to change the rate of blinking.

- Use the random(int,int) function to give a random delay time and make your LED flash at random intervals.

- Use a buzzer in the place of an LED.

- use a DC motor instead of an LED.

Now as long as the arduino is powered with a suitable power supply, the code you have uploaded will continue to work, even if you have unplugged and plugged in the board again.

Hoping this tutorial was helpful, from,

EverythingEasy!

<p>Very cool! Thanks for sharing and welcome to the community! </p>
<p>Thanks! @tomatoskins</p>

About This Instructable

390views

3favorites

License:

More by EverythingEasy:Arduino Basics : Connecting LEDs 
Add instructable to: