Introduction to Arduino – “Blink”

Tutorial Series Introduction

Have you always wanted to do amazing projects combining the flexibility of software with potential of hardware the  but never knew where to start? This tutorial series will provide an introduction to hardware projects from the perspective of a complete beginner. I will document every meticulous detail and when it is applicable, list multiple methods to accomplish the same task yielding a complete understand of the project. In addition to documentation I will make all source code available and post a video walk through of each tutorial. Video tutorials can be found at the One Stop Programming YouTube channel. The link for this video is listed below. As the tutorial series progresses I will incorporate special topics for specific projects and provide the same level of detail and resources for more advanced topics. Words that appear in Italics with an asterisk(*) are terms that are defined at the bottom of the page.

Advertisement:

Overview

In this first tutorial we will do what I consider the “Hello World” of the Arduino world: Blink. The Blink sketch* is provided within the Arduino IDE and does not strictly require any external circuitry and we will use it to verify that the board is working correctly and is programmable. We will expect to see an LED* on the board blink in sync with the LED that we wire in externally.

Required Hardware/Materials

      • (1) Arduino UNO R3 or Compatible Alternative (A compatible alternative is recommended as they are just as functional/reliable, however, they do not carry the Arduino brand)
      • (1) Breadboard and Jumper Wire Kit
      • (1) LED (Any Color)
      • (1) 200Ω – 300Ω Resistor (This is a recommend range but any resistor above 100Ω should be sufficient)
      • (1) Tactile Button

LEDs and compatible resistors can be purchased as a kit here. All items required for this tutorial can be purchased on Amazon through kjdElectronics. The kjdElectronics Starter Kit for Arduino provides the necessary hardware for this tutorial in one convenient hassle free package. Note that the Arduino/Arduino Compatible board is sold separately. Special Offer: When you purchase the Starter Kit and a Funduino (A Funduino is a low cost Arduino Compatible Board) from kjdElectronics use promo code LRWZNU35 to get $5 off your purchase.

Part 1 – Testing Your Board

For the first part of the test no circuit is required. If you have not yet downloaded the Arduino IDE then do that now. It can be downloaded from the Arduino Website. Download and install the most recent version of the IDE. After installing (or if you had the Arduino IDE previously installed) launch the IDE. Then connect your Arduino (or other compatible board) to the computer. After being connected you should see the power LED and other LEDs light up. If this does not happen you are experiencing some issues. Post on the forum and someone will try to assist you. Next, from the Arduino IDE click the “Sketches” and under basic select “Blink.” The blink sketch will now load in a new code window. Click the “Upload” button and begin uploading the sketch to the Arduino. If necessary select the correct COM port that the Arduino is on. For more information on this process review the You Tube video (Coming Soon) that compliments this tutorial. Verify that the LED labeled as L is blinking on the Arduino. Blink Test

Part 2 - Building the Blink Circuit

Now that we have verified that board is working and have practiced uploading a sketch lets add on by building our first circuit. In this section you will need to get out your breadboard, jumper wires, an LED and a resistor. I would recommend that you first read the diagram below and build the circuit. After you have built the circuit continue reading for a description of the purpose of each component. While understanding the function of each component is very important, the ability to read schematics and diagrams is critical and should be developed early.

Diagrams made with Fritzing 0.8.7.

Blink circuit with external LED.

Above you see that we have made several connections. First, connect the 5V terminal on the Arduino to the red rail on the breadboard. Note that red and blue rails are for power (+5V and 0V GND (Ground)). Each point on the breadboard on these rails is connected horizontally in the image above, however, they are not connected across the board. That is why it is necessary to connect to connect these across the board. The other points on the breadboard are connected in vertical columns broken in the middle. In the picture above the 5 points in the top left (excluding the power and rails) are connected in a vertical column. This allows you to make multiple connections that are electrically at the same node (or point). Next, we insert the LED into the breadboard. Note that the longer leg of the LED is the positive terminal and the shorter leg is the negative (GND). When current flows through the positive terminal of the LED to ground light is produced by the LED. However, it is necessary to limit the amount of current through the LED as to much current will destroy it. This is where the resistor comes in: recall ohms law Voltage=Current * Resistance (V=IR). If we are using 5V and a 200Ω resistor the current through the LED is equal to V/R=I => I=V/R. Therefore I=5/200=0.025A which is safe for our LED. If no current limiting resistor is used the equation becomes I=5/0…which equates to an extremely high current that burns out the LED.  With this in mind we don’t forget to connect the negative terminal of our LED through a resistor to GND. The positive terminal of the LED is connected to pin 13 on the Arduino. Why pin 13? Because in the blink code pin 13 is defined as the default led variable. With that subtle transition let’s move onto the code.

Code

/* Blink Turns on an LED on for one second, then off for one second, repeatedly. This example code is in the public domain. */
 
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
} What happens when the code is executed? First, you a variable named “led” is defined and given the value of 13. Next, the setup() function runs one time at the beginning of each Arduino sketch. The setup function sets the pin defined by the led variable to “OUTPUT” mode. This pin setup is required before using any Arduino pin. After the setup function completes the loop() function begins executing. The loop function will loop forever until the Arduino is reset or looses power. Within the loop function we make a digitalWrite to out led variable and specify a value of “HIGH.” HIGH connects the pin specified by the led variable to +5V. HIGH can be thought of as “on,” powered, or +5V. Next the program will sleep for 1000 milliseconds (1 second). Then, another digitalWrite is performed setting the led to “LOW” followed by another delay. Similarly, LOW is “off.” GND, or 0V. The digitalWrite command simply either sets the specified pin high or low. Digital values can only be 0 or 1. In this case 0 is off and 1 is on. When the output is set HIGH the led will be provided with 5V and current will through the LED producing light. When the output is LOW the voltage on the positive terminal of the LED will be zero and the LED will be off. Congratulations! You implemented the blink sketch. This is just the first step in an entire new world of possibilities. To continue play with the length of the delays and move the led to different pins. In the next tutorial we manually control the LED with a button.

Advertisement:

Defined Terms

Sketch: A sketch is an Arduino program/file that contains all of the code necessary to function. This is the “code” portion of the project. LED: Light emitting diode

Newsletter: Updates and New Features

One Stop Programming has some exciting news to share with you. In the past few months I have worked on updating the website and I have created the One Stop Programming Blog. I believe the blog will greatly enhance the usefulness of One Stop Programming as a teaching tool by providing additional resources. In the next several months I plan to create additional C++ and Python tutorials as well as create a brand new Arduino tutorial series. See below for details.

Blog

As some of you may have noticed, I created the One Stop Programming blog several months ago. The blog is home to a growing number of supporting materials for both the C++ and Python video tutorials. My hope is that the blog can grow along side the forum and that they both can be used as a programming resource. Blog Home Page

Recommended Reading

The blog is also home to the brand new Recommended Reading guide where I have compiled a list recommended programming texts, guides, and references. I highly recommend taking a look at this guide. I particularly recommend the C++ and Python Pocket References. These are cheap guides (under $10 each) that are extremely beneficial. They highlight the overarching structure of each language and provide definitions/examples of all keywords and syntax.

Arduino

I am also in the process of introducing Arduino to One Stop Programming. Arduino is a hardware/microcontroller solution that serves as an excellent bridge into hardware development. Arduino is easy to learn platform and will allow us to create some extremely cool projects in a short amount of time. I am currently planning several tutorials/projects to kick off this new tutorial series, however, I am certainly open to suggestions. Check out the new Arduino Section on the forum and submit your project ideas.

I look forward to seeing all of your over on the forums, and blog. Thank you for supporting One Stop Programming.

Sincerely,
Kevin J Dolan
Founder of One Stop Programming

Arduino Coming to One Stop Programming

Up until this point One Stop Programming has primarily focussed on C++ and Python tutorials and as I am looking to expand I wanted to introduce a completely new topic: hardware. After some consideration on different hardware options I decided on Arduino for several reasons.

  1. Arduino is open source, relatively cheap and easy to obtain.
  2. It does not require advanced programming knowledge to make something really cool.
  3. It works out of the box and does not require any special setup.

With this in mind I want to create powerful yet concise Arduino tutorials in order to contribute to the community.

Check out the new Arduino Page on the Blog!

Advertisement:

Welcome to One Stop Programming

Hello everyone and welcome to the One Stop Programming blog. Stay on the lookout here for updates on the tutorial series and other information.

This site will also link to each of my YouTube tutorials as well as provide video summaries and supporting content.

Advertisement: