Skip to content

Arduino IDE

Udaya Bhaskar Kothapalli edited this page Sep 11, 2015 · 1 revision

Introduction

What is Arduino?

Arduino

Arduino is an open-source prototyping platform based on easy-to-use hardware and software.

Over the years Arduino has been the brain of thousands of projects, from everyday objects to complex scientific instruments. A worldwide community of makers - students, hobbyists, artists, programmers, and professionals - has gathered around this open-source platform, their contributions have added up to an incredible amount of accessible knowledge that can be of great help to novices and experts alike.

Why Arduino?

It has a simple and accessible user experience, Arduino has been used in thousands of different projects and applications. The Arduino software is easy-to-use for beginners, yet flexible enough for advanced users. It runs on Mac, Windows, and Linux.

Arduino simplifies the process of working with microcontrollers, but it offers some advantages over other systems such as:

1. Low price.
2. Cross-platform 
3. Simple, clear programming environment
4. Open source and extensible software
5. Open source and extensible hardware

Getting started

Setting up the IDE

The first step to programming with Arduino is to download the Arduino IDE for your operating system here: Download Page

Once you have installed the IDE, connect your Arduino board to your PC using a USB cable.

Next, open the Arduino IDE and make sure that you have the correct device selected:

  1. Go to Tools>Board>... and select the board you are using (Arduino Uno for this tutorial).
  2. Go to Tools>Serial Port>... and select the port that the board is connected to (there is typically only one option). Note: For windows 7 and below we have to manually update the device drivers. General Troubleshooting Procedures

Programming Arduino

The code you write for your Arduino are known as sketches. They are written in C++.

Every sketch needs two void type functions, setup() and loop(). A void type function doesn’t return any value.

The setup() method runs once when the Arduino is powered up and the loop() method runs continuously afterwards. The setup() is where you want to do any initialisation steps, and in loop() you want to run the code you want to run over and over again.

So, your basic sketch or program should look like this:

void setup()
{
   // Your Setup code in here.
}

void loop()
{
  // Your Loop code in here.
}

Now we have the basic skeleton in place we can now do the Hello, World program of microcontrollers, a blinking an LED.

Arduino UNO board

Arduino Bord

The pin numbers are listed next to the headers on the board in white.

The onboard LED we want to control is on pin 13.

In our code above the setup() method let’s create a variable called ledPin.

int ledPin = 13;

void setup()
{
   // Your Setup code in here.
}

void loop()
{
  // Your Loop code in here.
}

To make the LED blink, we have to initialize the pin corresponding to the LED as an OUTPUT. So in the setup() method we have to set the ledPin to the output mode. We do this by calling a special function called pinMode() which takes two variables, the first the pin number, and second, whether it’s an input or output pin. Since we’re dealing with here with an output we need to set it to a constant called OUTPUT. If you were working with a sensor or input it would be INPUT.

int ledPin = 13;

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

void loop()
{
  // Your Loop code in here.
}

Now we are going to write the blinking action. We do this by calling another special function called digitalWrite() which takes two variables, the first the pin number, and second, whether the output value is HIGH or LOW i.e, whether you want to Switch ON the LED or Switch OFF the LED. We’re going to use another method called delay() which takes an integer of a time interval in milliseconds ( meaning the integer of 1000 is 1 second) and waits for that time interval to finish before it executing the next command.

int ledPin = 13;

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

void loop()
{
    digitalWrite(ledPin, HIGH);
delay(2000);
digitalWrite(ledPin, LOW);
delay(2000);
}

Once we are done writing this blinking example, lets go ahead Verify our code and Upload it.

Verify - Verify: Checks your code for errors compiling it.

Upload - Upload: Compiles your code and uploads it to the configured board. See uploading below for details.

Note: If you are using an external programmer with your board, you can hold down the "shift" key on your computer when using this icon. The text will change to "Upload using Programmer"

References

To read further about the technicalities of the Arduino use the following links

Arduino - Foundations

Arduino - Memory

Examples and Tutorials

Arduino Eamples