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 IDE (click to download)

Arduino Uno (or alternative)

USB Cable

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

1x Breadboard

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

3. Uploading a Blink Sketch to the Arduino

Conclusion

Congratulations! You now know how to build basic circuits using the Arduino’s Digital Output pins and functions.

In our next tutorial, I’ll be covering Digital Inputs and how we can add buttons and switches to our circuits and programs.

Downloadable Resources

Download Sketch and Schematics

More Great Arduino Tutorials

Arduino 02: Digital Inputs

Arduino 02: Digital Inputs

Last time we looked at how to use Digital Outputs in our projects, today I will be going over digital inputs. At a basic level, digital inputs allow us to add buttons and switches to our projects. I'll also cover "if" statements and button debouncing. Let's get...

Rapid Prototyping with 3D Printers

Rapid Prototyping with 3D Printers

  With the advent of 3D printers anyone can create parts or products from the comfort of their home. In my latest electronics project, WOOF IOT, I used Fusion 360 and my Ender 3 Pro printer to design a case for my Internet of Things Device. What is Rapid...

Introduction to Arduino

Introduction to Arduino

When I first started with Arduino back in early high school I was amazed by the versatility and power of the platform. Although there are many electronics platforms available today, Arduino is one of the best and a great place to start learning. In my article I will...

Hello World! Introducing myself

Hello World! Introducing myself

Hello World! Thank you for visiting my little corner of the internet. As the name suggests, I’m Filip, an International Business Administration bachelor student at the Rotterdam School of Management. Restless and curious, I enjoy...