LED Basics (1)

Now, we start our first circuit.

Control an LED, switch it on and off.

The circuit:


For this tutorial, wee need only two components:

  • LED (i.e. 2V, maximum 20 mA)
  • resistor

The LED ist a standard component. We use here an LED with 2V and a maximum amperage of 20 mA. We need this informations to calculate the resistor:

We get 5V from the Arduino Pin – so we can calculate:     5V (Arduino) – 2V (LED) = 3V (resistor)

You know the formula:


We use the following:


Well, we need a resistor with 150 Ohm or higher. It’s ok to use 180 Ohm or 220 Ohm.

Look at the picture, you see our circuit. We use GND (Ground) from the Arduino and Pin 9.
Pin 9 is connected with one row on the breadboard. In this row is the resistor connected too. The other Pin of the resistor is in the same row like the LED (anode!). We connect the second part of the LED with GND.

Here is the wiring diagram:


We start our Arduino software to create the first sketch.

LED switch on / off

int pinled = 9; // PinPort LED (we use Pin 9)

void setup() {
   pinMode(pinled, OUTPUT); // declare pin 9 to be an output:

void loop() {
   digitalWrite(pinled, HIGH);    // set pin 9 to HIGH -> LED on
   delay(1000);                   // 1.000 ms delay
   digitalWrite(pinled, LOW);     // set pin 9 to LOW -> LED off
   delay(1000);                   // 1.000 ms delay

The first 4 lines (/* … */) declare a comment.

int pinled = 9;
We define a variable with the name “pinled“. The type is integer, and we assign the value 8. You remember, we use Pin 9 to communicate with the Arduino.

void setup() { … }
Commands in this block will perform on start (or reset) of our sketch. Once only.

pinMode(pinled, OUTPUT);
We define the direction – we want to use Pin 9 as an output Pin.

void loop() { … }
Commands in this block will perform endless.

digitalWrite(pinled, HIGH);
We send a “HIGH” to Pin 9. This means, Pin 8 has 5V in this moment. Current flows, and we see the LED is on!

We wait one second to “see” that the LED is on

digitalWrite(pinled, LOW);
We send a “LOW” to Pin 9. The LED is powered off.

We wait one second to “see” that the LED is off.

And now, we are in the LOOP. We start from the front!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s