 # Arduino 01: Digital Outputs

The Ultimate Getting Started Guide

Continuing from my first tutorial (Introduction to Arduino), today I will be going over digital outputs. Furthermore, I’ll be discussing Ohms Law and Kirschoffs Law to introduce you to the world of electronics! If you haven’t read the first tutorial , I highly recommend doing so to ensure you have everything set up correctly. Let’s get started!

## What is a Digital Output?

A digital output on the Arduino Uno makes use of one of the 14 digital pins to output current. A pin can be set as a digital (binary) output with two possible states, HIGH (5V, binary 1) or LOW (0V, binary 0). Using a digital pin we can send to a device or circuit. A digital output allows us to turn something on (HIGH) or off (LOW). Each of the 14 pins on the Arduino can act as an output pin, providing us with 40mA of current at 5 volts. As such we must be careful not to draw more than 40mA of current, or we risk damaging our Arduino. ## Ohm’s Law

Ohm’s law concerns the relationship between voltage (V), current (I) and resistance (R). The law states that the voltage of a circuit is proportional to the current that passes through it.

V=I*R

V is voltage, measured in Volts.

I is current, measured in Amperes.

R is resistance, measured in Ohms.

Ohm’s law is important in the context of this tutorial as we will be using it to calculate the required resistance of a resistor that we will use in an LED circuit. If you feel you need additional help understanding Ohm’s Law along with voltage, current and resistance, I will soon be releasing a more in-depth article on basic electronics on my blog.

### Ohms Law Example:

We have a 1.8V rated red LED. It is rated at 25mA (milliamperes) or 0.025 Amperes. Our Arduino outputs 5 volts. If we simply attach an LED rated at 1.8V to a 5V source we will burn it out almost instantly (think infamous “blue smoke”). We must thus calculate an appropriate resistance value (for our resistor) to ensure the LED draws no more than 25mA of current.

Here’s the math:

Vs(source voltage)= 5V

Vf(forward voltage of LED)= 1.8V

A(LED Current)= 0.025A = 25mA

R (resistance of resistor) = ?

V=I*R

thus,

R=V/I

R=(5-1.8)/0.025

R=128 Ohms

In order to ensure the LED draws 25mA we need to add a 128 Ohm resistor to our circuit in series. We can also use resistor values higher than 128 if we want the LED to be dimmer or draw less current. In this tutorial I used a 220 Ohm resistor in this tutorial.

## Parts List

Computer (PC/Mac/Linux)

Arduino Uno (or alternative)

USB Cable

1x 3mm or 5mm LED (any kind)

Jumper cables

1x Assorted set of resistors ## The Circuit

Assemble your circuit following the interactive diagram below. I recommend watching the video for exact instructions and electrical calculations.

## The Code

Arduino is an open source electronics platform that allows makers to create electronics projects using C and a plethora of available libraries. Arduino makes electronics prototyping simple and allows anyone to quickly (relatively speaking) bring their projects to life. It’s also fairly inexpensive and offers a wide range of customizability. Whether you are building a simple circuit to blink an LED or assembling a robot, Arduino is a great choice.

int ledpin=13; //create and define a variable, ledpin, and set it to 13, our pin

void setup() {
pinMode(ledpin, OUTPUT); //set the ledpin, pin 13, as an output
}

void loop() {
digitalWrite(ledpin, HIGH); //set the ledpin (pin 13) to HIGH, turning it on
delay(1000); //wait for one second (1000 miliseconds)
digitalWrite(ledpin, LOW); //set the ledpin (pin 13) to LOW, turning it off
delay(1000); //wait for one second
}

## Tutorial / Build Guide

Check out the video for a step by step introduction to Arduino and installation tutorial. It is important to have everything set up correctly as the following tutorials will build on this one.

The tutorial consists of three parts:

1. A basic introduction to Arduino

2. Installing and configuring the Arduino IDE