Introduction: Arduino Starter Kit 1: First Circuit and Program to Control an LED

About: I want to build my moon base with remote controlled robots and solar sintering.

In this tutorial, you will learn to build your first circuit using jumpers, bread board and resistors, and program to control an LED with Arduino.

With this knowledge you will be able to control many other kinds of electronics. It is the first step on your voyage of global domin - I mean, making things!

Step 1: Things You Need

We assume you are already familiar with a few of our other tutorials.

Arduino Starter Kit 0: Introduction to Arduino UNO

You will need the following electronic components to complete this tutorial.

  • Arduino
  • LED
  • 220 Ohm resistor
  • Jumper wires
  • Breadboard
  • A to B USB cable

You can find all the above things you need from Marginally Clever Arduino Starter Kit


Step 2: Bread Board

Bread board is easy to use for prototyping and experiments. The way the holes are connected is shown in the figure. I only highlighted some of them, but you get that idea.

Step 3: Light Up an LED With Wrong Way

This is a demonstration of the wrong way of hooking up the LED to the power source.

The long pin of the LED connected to the 5V pin and the short pin connected to the GND pin. According to Ohm's Law,

The current through a conductor between two points is directly proportional to the voltage across the two points. Introducing the constant of proportionality, the resistance, one arrives at the usual mathematical equation that describes this relationship: I = V/R where I is the current through the conductor in units of amperes, V is the voltage measured across the conductor in units of volts, and R is the resistance of the conductor in units of ohms.

I = V/R.

The resistance of an LED is extremely small, effectively 0. The voltage flowing through the LED is 5v.

I = 5 / 0 = infinity!

So this will cook your LED almost instantly. If you plug in this circuit and turn on the power the LED might blink very briefly and die forever.

Step 4: Light Up an LED With Correct Way

The typical maximum current the LED can work with is roughly 25mA, which means the total resistance of the resistor we need to add and the LED should be

R = 5V / 25mA

which is

R = 5000mV / 25mA

which 200 Ohm. The resistance of the LED would be extremely small in this direction as we mentioned in the previous step, thus the resistance of the resistor would be larger than 200 Ohm.

For safety we can use a 220 Ohm resistor. Resistors are widely used in electronic projects. According to Wikipedia:
A resistor is a passive two-terminal electrical component that implements electrical resistance as a circuit element. In electronic circuits, resistors are used to reduce current flow, adjust signal levels, to divide voltages, bias active elements, and terminate transmission lines, among other uses.

The colored bars on a resistor are a code that describe the resistance level. You can find resistor color code calculators and charts on Google, and I've linked my favorite for convenience.

Step 5: Program to Control the LED

Modify your circuit a little bit. Instead of using the 5V port on the Arduino, make the jumper wire connect to the pin 9 on the Arduino, which is a digital pin.

Start a new Arduino sketch.

Every Arduino program has two essential parts: setup() and loop(). They are called methods: blocks of code that describe the method to complete a task.

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 9 as an output.
  pinMode(9, OUTPUT);
}

The code in the setup() function runs once when you press reset or power the board. For here, we set digital pin 9 as an OUTPUT port so that we can use it to control the LED. (The other option would be INPUT for sensors.)

Next is the loop() method, which runs after setup() again and again until something stops it.

void loop() {
  digitalWrite(9, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(9, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second 
}

HIGH means send 5V and LOW is 0V. Since the code in this loop function will run again and again until you turn off the power of the Arduino, the effect is to make the LED blink.

If you unplug the USB cable or any power source you use to power the Arduino, and then the plug the power back, the board will do the same thing again: set pin 9 as output, and continuously turn the LED on and off.

Step 6: Final Thoughts

Yay, you did it! Please share with us a pic or video of your success so we know we did good.

Now that you can light an LED, you can do lots more. As we write tutorials that build on this skill, they will appear here.

Marginally Clever Robots is dedicated to teaching robotics, electronics, and eventually putting robots on the moon. Check out our website for all kinds of great stuff.

Thanks for reading!