Arduino beginner programming

Arduino for Beginners: Your First Arduino Program!

Getting started with Arduino
Matt Matt (3)
Total time: 10 minutes 

In this Arduino beginner's guide I'll cover what an Arduino is, how to set up the Arduino IDE, and how to create your first Arduino program.

About this guide

This guide is an absolute introduction that assumes the reader has little or no experience with an Arduino. I'm going to explain all the basics of an Arduino and show you how to write your first Arduino program: a variation on the classic "blinking LED" example. Even if you don't have an LED handy, this guide will be useful to you.

If you have experience using Arduino and are aware of all of its components and how they are utilized, you may use this guide as a refresher on the basics. We've also put together a handy Arduino FAQ for you to peruse.

To complete this guide fully, you'll need an Arduino or cheaper Arduino clone.

Upcoming series

This will be the first in a series of articles that will broaden into more advanced uses with Arduino by adding sensors and consuming the data to make real-time graphs and other interesting things that I have not yet thought of.

Because I have a background in science and physics, I'll be doing some experiments with this data to prove and illustrate some already-understood scientific concepts in ways that are as ridiculous as I can get away with.

Follow Howchoo on Facebook to get notified when these new articles are released!

Here's everything you'll need to complete this guide:

Arduino UnoArduino Uno×1
USB cable, type BUSB cable, type B×1
Jumper wires, female-to-femaleJumper wires, female-to-female×2

An Arduino is a microcontroller that's meant to have a cheap form factor for all kinds of DIY projects; it can easily read many different sensors, control servos, and more.

Arduino vs. Raspberry Pi

It's different from a Raspberry Pi in that it doesn't run a full operating system. It's meant primarily for directly controlling and reading external devices with precision and ease. You can learn more about the differences between Raspberry Pi and Arduino.

When should you use an Arduino?

Arduinos are deliberately limited in the scope of what they can accomplish but do a great job at what they're designed for: rapid, easy, flexible, and extendible input and output handling.

As more specifics of the hardware are explained later, I'll point out which aspects are unique and illustrate when you would turn to this hardware for your project.

Combining Raspberry Pi and Arduino

It's possible to connect one or more Arduinos to a Raspberry Pi to utilize the wide variety of things a full OS can accomplish or simply to read the Arduino data.

Since Arduinos are just better at integrating with and controlling external hardware with precise timing, the Pi can orchestrate the initiation of "sketches" and combine and make sense of all of the data coming in from each Arduino.

This illustrates where they are different and the relationship they have with each other.

Arduino online sketchbook IDE

The Arduino IDE is the program you'll use to write code for the Arduino.

Here I'll be using the official Arduino Web Editor IDE because of its simplicity of getting set up quickly. and this method is independent of the Operating System that you use, but there are many ways to use some of your favorite IDEs to write Arduino programs.

Arduino programs are called "sketches".


Arduino programs are called "sketches". Sketches control Arduino projects and are saved in a folder called a "sketchbook".

Get going with the Arduino Web Editor or download the Arduino IDE for Mac, Windows, or Linux.

Arduino Uno pin diagram

The microcontroller

This is the brain of the Arduino. It's accessible via the black strip running vertically at the bottom left of the attached image.


There are 14 pins on the Arduino Uno, which was the earliest model available and has continually been updated since. These pins are capable of both input and output (I/O), but there are different groups of pins you'd use for different scenarios. For instance, there are both analog and digital pins, 5 volt (5V) and 3 volt (3V) pins and a ground (GND) to make sure your circuit is grounded with the board; this is also how the circuit is completed after connecting a different wire to one of the positive pins.


The analog pins are meant for taking input or for outputting continuous signals. A common example of this would be using a potentiometer to change the brightness of a dimmable LED. The continuous signal usually is split into a digital quantized signal by setting the lowest value to 0 and the highest to 255 so the computer has a way to use the information.


The digital pins are similar to the analog pins except that the signal doesn't need to be converted to digital (quantized) before use. However, it may still need to be normalized in the same manner by setting some low and high value to a corresponding number that can be used by the Arduino.

Pulse Width Modulation (PWM)

This is a large topic that I will not be able to do full justice here and will be covering in a future guide. The easiest way to think of PWM is that the pulse is a "square" wave and the width of each wave is the wavelength or half the wavelength.

Some devices, such as servos, require a very specific pulse width to activate and this pulse width can be changed, (or modulated), to achieve different motion or direction. Hence the name "Pulse Width Modulation".

This video illustrates PWM concepts well:

Selecting Arduino device
Selecting Arduino device

At the top of the online IDE, there's a dropdown that you can use to select which device will be used to upload the given sketch. If there is no device plugged in, you will see a list of all available devices. If your device is plugged in and working correctly, it should be the first device in the list for you to select.

This sketch comes as part of the standard sketch library examples in the online editor. The native desktop IDE also comes with similar examples.

  Blink without Delay

  Turns on and off a light-emitting diode (LED) connected to a digital pin,
  without using the delay() function. This means that other code can run at the
  same time without being interrupted by the LED code.

  The circuit:
  - Use the onboard LED.
  - Note: Most Arduinos have an on-board LED you can control. On the UNO, MEGA
    and ZERO it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN
    is set to the correct LED pin independent of which board is used.
    If you want to know what pin the on-board LED is connected to on your
    Arduino model, check the Technical Specs of your board at:

  created 2005
  by David A. Mellis
  modified 8 Feb 2010
  by Paul Stoffregen
  modified 11 Nov 2013
  by Scott Fitzgerald
  modified 9 Jan 2017
  by Arturo Guadalupi

  This example code is in the public domain.

// constants won't change. Used here to set a pin number:
const int ledPin = LED_BUILTIN; // the number of the LED pin

// Variables will change:
int ledState = LOW;             // ledState used to set the LED

// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change:
const long interval = 1000;           // interval at which to blink (milliseconds)

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);

void loop() {
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the difference
  // between the current time and last time you blinked the LED is bigger than
  // the interval at which you want to blink the LED.
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);

I wanted to make sure you could read the full code with all the credits and explanations but just to show how little code is needed, here is the same code without all of the comments.

const int ledPin = LED_BUILTIN;
int ledState = LOW;
unsigned long previousMillis = 0;
const long interval = 1000;

void setup() {
  pinMode(ledPin, OUTPUT);

void loop() {
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;

    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;

    digitalWrite(ledPin, ledState);

This example does not rely on the delay function so the delay is determined by reading the number of milliseconds passed since the last loop and if the difference between the current run and the last blink is greater than or equal to the interval, 1000 ms, in this case, the LED's state is switched from its current state.

Essentially, that's all that's happening in this code. The rest is just the instantiation of the constants, such as setting up which pin is to be altered in the setup function. As described in the comments, the constant LED_BUILTIN refers to a specific pin on the Arduino and can depend on which model you are using. You can read about all of the constants available with the standard Arduino library.

Upload Arduino Sketch

To the left of the device selection, there's a right arrow and a checkmark. You can use the checkmark to verify that the sketch compiles and is valid. After that, click the right checkmark to upload the sketch and you will see the button turn into saying busy.

The bottom console shows information about the status of the upload. When the upload is complete, it will say "Success: saved your online sketchbook and done uploading". If there's an issue, it will let you know that it's time for some troubleshooting.

The possibilities are quite endless with what you can accomplish messing around with an Arduino, and it's pretty fun to work with. Unlike many, many computer hardware interfaces for hobbyists, the Arduino really is plug-and-play as advertised. You don't have to spend hours with driver configurations or reflashing SD cards, you just make a change to the sketch and click play and I find that quite refreshing.

I'm excited for the upcoming guides in my series where we'll be adding sensors and reading the information and hopefully using it in some interesting ways. If you don't have an Arduino yet, I recommend picking one up since they're very inexpensive.

Series: Arduino
Arduino FAQ
Show all in the Arduino series