Arduino UNO Tutorial for Beginners

This Arduino tutorial starts from scratch and works through the basics, so you can follow along without previous experience. I’ll guide you through setting up your computer and writing your very first program for the Arduino Uno board. We will begin with the setup and build from there.
The Arduino Uno board is a good place to begin learning the Arduino platform. PLC programmers can also benefit from learning about microcontrollers. The two have much in common, and understanding microcontrollers can help you understand how a PLC works.
In Europe, Arduino has recently changed its name to Genuino.
The Arduino Uno, also called Genuino Uno, is an open-source board for learning electronics and programming. It uses the Atmel ATmega328P microcontroller, which gives you a starting point for learning embedded programming.
The Arduino Uno suits beginners for several reasons:
- Simple connection to a computer
The USB port on the Arduino Uno board makes connecting it to a computer straightforward. All the required drivers come with the Arduino IDE, so installing the IDE gives you the software you need for that connection. - Easy wiring
Headers along the sides connect to all the pins on the ATmega328P microcontroller. These headers make it easy to wire the board to a breadboard. - Simplified programming language
To program the Arduino Uno, you use a simplified version of the C programming language. - Lots of support
The Arduino platform is popular and has millions of users. That means there is plenty of help available if you run into problems while learning. You can search Google for many of the problems you encounter and find solutions that other users have shared.
To begin this Arduino Uno tutorial, let’s set up your computer. If you don’t have an Arduino Uno, you can buy one here (affiliate link) or choose a good beginner’s Arduino starter kit.
Arduino Uno Software
Begin by installing software for the Arduino Uno.
You can choose from several IDEs (integrated development editors) for programming Arduino boards. We will use the Arduino IDE for this tutorial. It is a free, open-source IDE made by Arduino for working with the boards.
The Arduino IDE is straightforward software for programming Arduino boards. Downloading and installing it takes only a few steps.
Download the Arduino IDE here.
Once the IDE has downloaded, you need to install it on your computer. The installation is straightforward and does not require much input from you beyond accepting the terms and conditions and choosing the components to install.
Use the installation instructions for your operating system:
Once installation is complete, open the Arduino IDE.
Most of the IDE window is a white area where you write code. Menus sit at the top of the window, with a terminal at the bottom.
Next, connect the Arduino Uno to your computer.
Connecting the Arduino Uno
Before making the first connection to the board, close the Arduino IDE on your computer.
You need a USB 2.0 A/B cable to connect the board to your computer.
Look for the USB type B plug on the side of the Arduino Uno. Connect the cable to that plug, then connect its other end to a USB port on your computer. The USB connection automatically powers the board, and you will see the ON LED light up green.
The first time you connect the Arduino on Windows, you need to locate its drivers. The pop-up window gives you an option to search for the drivers on your computer. Choose that option and click browse. Go to the folder where you installed Arduino, then select the folder named Drivers.
You can then open the Arduino IDE.
Check that your Arduino Uno is connected:
Go to the menu Sketch -> Upload or press Ctrl+U.
This begins uploading the code in the white box to your Arduino. At this point the code does not do anything and has no functions. We are uploading it simply to check that the computer can connect to the board.
A successful upload shows “Done uploading.” in a blue bar above the black terminal window at the bottom of the IDE.
If the bar is orange, you might see the message “An error occurred when uploading the sketch.” instead.
The most likely cause is that the selected port is incorrect.
Go to the menu Tools -> Port and select the COM port with (Arduino/Genuino Uno) in its name.
Try uploading the code again (Sketch -> Upload or Ctrl+U). It should now work.
You are ready to begin programming the Arduino Uno.
Your First Arduino Uno Program
Before we move on, you need to know one new word. The Arduino IDE uses sketch as its name for the code, in place of program. You will see that term while working in the IDE.
I will use sketch for our code throughout this tutorial, so the wording matches what you see in the Arduino IDE.
Let’s write the first sketch.
For this first sketch, you only need the Arduino Uno board and USB cable. We will use the built-in LED (light emitting diode) already on the board. It connects to one of the digital inputs/outputs.
Arduino Uno Digital Pins
If you look at a pinout diagram for the Arduino Uno board, you can see how its connectors are wired. The header connectors along the sides of the board all connect to the microcontroller.
Some pins supply power or handle communication with the Arduino. For now, we will focus on the digital inputs/outputs.
At the top of the Arduino Uno board, the headers run from 0 to 13, followed by GND. The numbered pins are digital inputs or outputs; the last pin is ground. The board labels these pins “DIGITAL”.
To understand these digital pins, we need to look at how the same pin can work as an input or an output.
Digital Inputs or Outputs
Each digital pin from 0 to 13 can work as either an input or an output. You choose which role a pin has by configuring it in your code.
The pins are called ‘digital’ because they switch between two states. You can use those states to control electronics.
HIGH and LOW.
HIGH and LOW describe the voltage level of a pin. When you configure a digital pin as an output, as we will do shortly, you can control its state from the code. The output can then be set to either HIGH or LOW.
An output set to LOW has a voltage of 0 volts. Setting it to HIGH changes the voltage to 5 volts.
This change in voltage is useful when you want to control things. If you know a little electronics, you can see how changing a pin between 0 and 5 volts gives us a way to do that.
Let’s return to the code and configure the digital pins.
Arduino Minimum Code
When you open the Arduino IDE, you will usually see code like this:
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
This is the minimum code needed for your Arduino Uno.
Setup and loop are both functions in C, the programming language Arduino uses. Arduino uses a simplified version of C, but the syntax remains the same. When programming microcontrollers with C, the work can quickly become complicated because you need to deal with memory and similar details. One of the main advantages of the Arduino platform is that you do not have to manage those details yourself.
If you are new to C or want to improve your C programming skills, I recommend The C Programming Language (affiliate link) by K&R. The first chapter of this C tutorial is another helpful resource.
First, look inside the setup function. There is one line in it, but that line is a comment rather than code the Arduino executes. Two slashes mark the start of a comment. Everything after them on that line is ignored by the Arduino.
Arduino Setup Function
The comment explains when this function runs: it runs once, when the Arduino powers up. Pressing the reset button also causes the function to run once.
That makes this function useful for preparing your program. You can set variables and do similar setup work here, which is why the function is called setup. Arduino runs this code one time and then moves on to the main function.
The digital pins can be configured as inputs or outputs. We only need to configure them once, so the setup function is a suitable place to define how we want to use each pin.
Defining Output with pinMode()
Another standard Arduino function defines whether a digital pin on the Arduino Uno board is an input or an output. This function is called pinMode().
Arduino uses simplified C and includes many built-in functions to make configuring and programming the board easier. For configuring digital pins, the standard function is pinMode().
The reference for the pinMode() function shows the following syntax:
pinMode(pin, mode)
The function syntax has 2 parameters: pin and mode.
pin: The number of the pin to configure
mode: The mode to assign to the pin (e.g. INPUT or OUTPUT)
Let’s apply this to our first program.
The LED built into the Arduino Uno board connects to pin # 13. Since we want to control that LED, we need to configure this pin as an output. We can make that configuration in our first program with the following code:
void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
}
The pinMode() call sits inside the setup() function. We placed it there because we only need to configure the pin once when the program begins.
Arduino digital pins default to input. If you plan to use a pin as an input, you do not need to configure it with pinMode().
Built in LED and Constants
There is another way to specify pin number 13. This pin has the built-in LED connected to it, so we can replace the number 13 in our function with a constant.
Arduino has predefined constants as well as predefined functions.
A constant is a predefined expression. The reference site for constants from Arduino lists examples, including pin levels (HIGH and LOW) and pin modes (INPUT, OUTPUT and INPUT_PULLUP). Further down the page is a constant called LED_BUILTIN.
This constant identifies the pin connected to the built-in LED. Most Arduino boards connect that LED to pin # 13. In the pinMode() function, we can therefore replace the number 13 with LED_BUILTIN, as shown below:
void setup() {
// put your setup code here, to run once:
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
}
Using the constant makes the code more generic, so you can use it on any Arduino board, including the Arduino Uno.
Arduino Loop Function
Now that the pin is configured, we need to make it do something. The next part of our program is the loop() function, where we will use that pin.
After running setup(), Arduino moves on to loop() and runs its code. The behaviour differs from setup(), though: loop() repeats continuously. As its name suggests, the function forms an infinite loop.
Write the behaviour you want your program to repeat inside the loop.
We have already configured pin # 13 (LED_BUILTIN) as an output, so we can begin by turning it on. This will light the LED built into the Arduino board. To do that, we set the output state to HIGH. As explained earlier, HIGH sets the voltage level at the pin to 5V.
Setting Output with digitalWrite()
How do we change the state of an output?
Arduino provides another predefined function to change an output state. Like pinMode(), this function takes parameters that tell it what to do. You can see the syntax in the official reference from Arduino:
digitalWrite(pin, value)
This function takes two parameters, pin and value.
pin: The number of the pin to write to
value: The value to assign to this pin
We will use HIGH and LOW as the values. These predefined constants set the voltage level of the pin.
To turn the LED on, we use HIGH. Applying 5 volts lights the LED, so the function call inside the loop looks like this:
void setup() {
// put your setup code here, to run once:
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
}
I used the constant LED_BUILTIN in place of the number 13. You can use this constant each time you work with that pin. The name makes the code easier to read and understand: whenever you see it, you know that the code is working with the pin connected to the built-in LED.
There is also a comment after the line of code explaining what it does. Adding comments makes your code easier to read and understand later. Comments are particularly helpful while you are learning, because you can use them to describe the purpose of the code.
Now put the code on the Arduino and run it.
Compiling and Uploading the Sketch
You have already seen how to upload a sketch (program) to the Arduino board. There is another step to take before every upload: verify the code. We have written several lines and need to check that they work. If code contains errors, uploading it to the board can cause problems.
Verify the Arduino Code
With the code above in the editor, choose Sketch -> Verify/Compile or press Ctrl+R.
This verifies your code without uploading it to the Arduino. It checks for errors so you can make sure the code will work on your board before you upload it.
When the code has no errors, verification looks like this:
You have written Arduino code that works.
Next, look at what happens when the Arduino code contains an error.
To learn how verification reports an error, we will deliberately make a syntax error. A semicolon marks the end of each expression, telling the compiler where that expression ends and a new one begins. Leaving out a semicolon is a common programming mistake, even among experienced programmers. We can make that mistake here and look at the result.
Change line 4 from this:
pinMode(LED_BUILTIN, OUTPUT);
to this:
pinMode(LED_BUILTIN, OUTPUT)
Now, go to Sketch -> Verify/Compile or press Crtl+R
Verification now gives a different result:
The status bar turns orange and displays an error message. One line also turns red. Together, these show you what the error is and where it occurs.
The error message is:
expected ‘;’ before ‘}’ token
The compiler is telling you that it expects a semicolon before the bracket.
Line 4 is an expression. Without its semicolon, the compiler has no indication that the expression has ended. It keeps reading the code, expecting that expression to continue or end. The next bracket closes the setup function before the expression has finished. The compiler reports an error because it has reached that closing bracket with an unfinished expression.
Put the semicolon back on line 4 to fix the error.
Uploading Sketch to Arduino
Once the code has no errors, upload it to the Arduino board.
As before, choose Sketch -> Upload or press Ctrl+U.
The message “Done uploading.” means your sketch has compiled and uploaded successfully to the Arduino board.
Before the upload begins, you might notice that the Arduino IDE compiles the sketch. This translates the code you wrote into code the Arduino (AVR microcontroller) can understand. The microcontroller only understands 0’s and 1’s. During compilation, all of your code is translated into those 0’s and 1’s so the board can run it.
After uploading the code, look at the Arduino board.
The LED close to pin 13, called L1, should now be on. Our code changed the state of its pin to HIGH. As a result, pin 13 has a voltage level of 5 volts and lights the LED.
For an experiment, change the pin state from HIGH to LOW in the code. This should reduce its voltage to 0 volts (ground) and turn the LED off.
The changed code looks like this:
void setup() {
// put your setup code here, to run once:
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(LED_BUILTIN, LOW); // turn the LED off (LOW is the voltage level)
}
Watch the Arduino board closely as you upload this code.
You will see two other LEDs begin to blink. They are labelled “TX” and “RX”, and they indicate communication with the Arduino Uno board. Each blink shows that communication is taking place. Uploading a sketch involves that communication, which is why you see the LEDs blinking during the upload.
When the upload finishes, those LEDs turn off. Our new code also turns off the built-in LED.
Working with the Loop()
The loop() function repeats continuously. We can use that repetition to make the program do more.
For now, there is one line of code inside the loop() function. That line runs continuously, setting pin # 13 to the same state on every pass through the loop. Because the state does not change, the LED stays either on or off.
We can add two lines to the loop, one to turn the LED on and another to turn it off. In theory, this should make the LED blink.
The code now looks like this:
void setup() {
// put your setup code here, to run once:
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(LED_BUILTIN, LOW); // turn the LED off (LOW is the voltage level)
}
The loop repeats both lines of code continuously. Each pass turns the LED on and then off before the same sequence begins again.
Upload the code and watch the Arduino board. You might be surprised by the result: the LED appears dim instead of visibly switching on and off.
The Arduino switches the LED faster than your eyes can follow. Although the LED is blinking, the on and off states pass too quickly for you to see them separately. What you see is the average light output. With the LED on for 50% of the time and off for 50% of the time, the apparent intensity is 50%.
Slow Down the Code with Delay()
We need to slow the code down until the LED blinks slowly enough to see.
We can slow the sequence by adding delays to the code. After turning the LED on, we need to wait before turning it off. We then need another pause after turning it off. Those pauses give us time to see each part of the blink.
Arduino includes a predefined function for adding delays to your program. You do not need to build that timing yourself. The function is called delay() and takes one parameter. Its syntax is shown in the Arduino reference:
delay(ms)
The parameter ms is where you specify how long the delay lasts. The function measures that time in milliseconds, with 1000 milliseconds (ms) in one second.
Add the delays to our code as shown below. Half a second should give us enough time to see the LED blink, so we will use 500ms as the parameter in each delay function:
void setup() {
// put your setup code here, to run once:
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // Wait 500 milliseconds
digitalWrite(LED_BUILTIN, LOW); // turn the LED off (LOW is the voltage level)
delay(500);
}
I put delay() after the instruction that turns the LED on and after the one that turns it off. This makes the LED stay on for 500ms, then off for 500ms.
Upload the code and watch how the LED behaves.
The LED now blinks.
It keeps blinking because the loop runs continuously.












more like this software and thank you
Thanks for the quick tutorial! Great introduction
Thanks!
It is very basic, but is so well written and easy to understand with thorough examples that it is perfect for the beginner to learn and move on quickly. Thanks for taking the time to do it Write()
Thank you very much Dale! I’m glad you liked the article.
Great tutorial! Where is chapter 2?