Become a subscriber (Free)

Join 29,000 other subscribers to receive subscriber sale discounts and other free resources.
:
:
Don't worry -- youre-mail address is totally secure. I promise to use it only to send you MicroZine.

Using the Arduino IDE

You use the Arduino IDE to upload programs to the Arduino Uno - these are know as sketches in Arduino. It shows in detail screen shots of each part of the process so you can follow along. All you need is an Arduino Uno and a USB cable.


The IDE gives you a very simple interface which is one of the reasons the Arduino is so popular. It gives you a simple editor and virtually one button programming of the Arduino. Here's the IDE when you first start it.

Arduino IDE first start

The black area at the bottom is where programming status will be displayed and the top white are is where you enter your programs to control the Arduino. Bottom right shows you the board currently selected.

Ardino IDE - Board selection

The Arduino IDE can progarm many different types of boards such as the Uno, Nano, Mega, Leonard and many more. To set up the IDE for your board use the Menu:

Menu > Tools > Board:

Now select: "Arduino/Genuino Uno" for the Arduino Uno Board.

arduno IDE Board selection
The new board selection will be displayed in the arduino IDE at the bottom right.

Arduino Uno to PC link setup

Serial Port Selection

The Arduino Uno communicates to yor PC via a serial USB link using an RS232 port.  You now need to select the port in use by the Arduino.

Plug in the USB cable from your PC to the Arduino. 

Now use the Menu:

    Menu > Tools > Port

You will see text showing you to which port the Arduno is attached - Select it.

Arduino IDE port Selection

Note: Your port number may be different e.g. COM5. Select whichever has the "Arduino/Genuion Uno" text.

Setup Check

Having selected the port you can check by using the Menu:

    Menu > Tools

Arduino IDE board setup

If you selected the board correctly (and the Arduino was plugged in) then you will see the Board and Port in use, similar to the above image.

Run your First Program

Using the serial Port

As well as loading programs into the Arduino you can use the USB serial link yourself to communicate with the board. Typically you will output information to the PC screen (from the Arduino) and quite often use this output to debug what is going on in the program. But for now lets just get some text output from the Arduino.

This program is going to output "Hi there" using the serial monitor built into the Arduino IDE.

First of all : Copy and paste the following program into the white text area of the IDE replacing what is already there.

void setup() {
  Serial.Begin(9600);
  Serial.println("Hi there.");
}

void loop() {
}

Once you have done that hit the save button in the IDE and save the program as hi-there. The tab in the IDE will change to the text "hi-there" as below.

First program Arduino IDE

Compiling and Uploading

The tick mark on the left is the verify button - this verifies that your code is correct. The right arrow is the upload button. You only need to hit this button as preferences default to upload then verify.

So hit the upload button.

Observe what happens.

it didn't work!

There was an error in the code!


Click to show error screen

Arduino Error screen
You can see that the line with the error is highlighted in pink and the error message is repeated in orange bar and in the black panel. If there are many errors you can expand the black panel to see them all.

In C/C++ programming you have to be very accurate in the words used - even putting a capital letter instead of lower case one (as here) means that the program will not compile.

The problem is that the word 'Begin' should be all-lowercase.

You will get used to these "syntax errors" and as you get used to programming will have fewer and fewer of these types of error.

If you don't know why an error occurred then search for 'Serial' in the Arduino reference - this gives you the details of functions you can use.

The main serial reference is here
and the specific information is here (found by clicking begin() from within the link above).

Lets correct the error and contine

To correct the error simply change the capital 'B' to lowercase 'b'.

void setup() {
  Serial.begin(9600);
  Serial.println("Hi there.");
}

void loop() {
}

Then save the file again. Now click the right arrow upload button again.

The right arrow will change to an orange background during the compilation and upload process:

Arduino IDE compile and upload

Arduino IDE upload

Observe that the two green LEDs on the Arduino Uno are flashing during the upload process (this is a small program so it will be for a short time). Uploading begins immediately compilation is complete. The LEDs indicate that communication is working in both directions between the PC and the Uno.

You may need to re-upload to see this as it is quite a short upload time for this small program.

When compilation is complete you'll get a status report showing how much memory has been used for Flash and RAM.

Flash is the program storage area (fixed data - contents kept on power down) and for the Arduino Uno is 32kBytes, while RAM is the variable storage area (changing data - contents lost on power down) and for the Arduino Uno is 2kBytes.

The following image shows that program summary:

Arduino IDE uploaded
You can scroll the bottom message but the contents is:

Sketch uses 1488 bytes (4%) of program storage space.
Maximum is 32256 bytes.
Global variables use 198 bytes (9%) of dynamic memory, leaving 1850 bytes for local variables. Maximum is 2048 bytes.

When you create larger programs you may need to keep an eye on these numbers so you don't run out (of course you could use an Arduino Mega2560 that has 256k Flash and 8k RAM!).

Open the Arduino IDE Serial monitor

To see the output data from the Arduino Uno start the serial monitor either by clicking the magnifying glass at top right of the Arduino IDE or using the menu:

    Menu > Tools > Serial Monitor

Serial output from The Arduino Uno

The output you should see is shown below:

arduino IDE  serial monitor

You can see the output from the Arduino Uno in the main window. If you don't see it make sure you set the Baud rate in the above window (bottom right) to 9600 baud.

To make the Arduino output the data again press the reset button on the Arduino Uno (top left of the board).

So that completes installing, and setting up the Arduino IDE. You have also programmed the Arduino Uno with your first program and should now be familiar with programming the Arudino Uno with code.

Tips for using the IDE

Easy Arduino IDE Block Comments

Quite often you will want to get rid of a block of troublesome code (temporarily) and there's an easy way of doing that - you don't have to use the cursor keys and forwards slash multiple times. just select some lines of code and use the following keystroke:

Use Control+'/' to Comment out lines of code. It also uncomments to undo commenting. Just select a set of lines and hit the keys to comment.

Arduino IDE Code Operation Query

You can find Arduino code operation by left clicking to select an element of code - for example and selecting Serial  and then right click to open the popup menu, then choose "Find in reference". This will open a page in your browser showing you how Serial operates.

Arduino IDE Setup Tab Spaces

This one is a bit of a pain to do (not too much though). The default tab spacing indent is 2 spaces. Most coders use three or four spaces so I like to change it to 3 spaces.

You can't set this unless you manually edit the Arduino IDE preferences file. So  open the preference panel to find out where the file is located:

    Menu > File > Preferences

And click the link below the text:

    "More preferences can be edited directly in the file"

Now an explorer window will open. Double click the preferences.txt file to edit it.

Shut down the Arduino IDE.

Search down the file for:

    editor.tabs.size=2

... and change it to:

    editor.tabs.size=3

... or whatever you need. Save it and restart the Arduino IDE.

Using an Arduino IDE External Editor

When you develop code the Arduino IDE is Ok for starting out, but as your file gets longer you will want to easily jump between functions. So you will want to use an editor in which that can view all the functions easily.

A free one is PSPAD. Install that.

To use the external editor save all Arduino IDE files then goto :

    Menu > File > Preferences > Use external editor

Click the check box and Hit OK.

The Arduino IDE will be greyed out - so you can't use it for file editing.

Load the file into PSPAD and edit it as you need.

An easy way to do this is open a File from within the Arduino IDE. Then open the file - the IDE will still be pointing to the current file location. Don't click Open, just drag and drop the (.ino) file from the "file-open-box" onto PSPAD.

At the moment this does not look to good as there is no syntax highlighting and that is because PSPAD does not know what .ino means. In fact .ino is just a C/C++ file so lets got and set that up in PSPAD. (You can close the Arduno IDE file open box).

In PSPAD Select

    Menu > View > Change Syntax

... and select the top one C/C++

Now you will see a nicely syntax coloured page. That's OK but we need the function list so select:

    Menu > Tools > Code Explorer Window.

Now on the right hand side you can see a list of all your functions - just click on them to jump directly to them.

This makes it so much easier to navigate complex code.

You need to keep the Arduino IDE running for compilation. So make edits in PSPAD and the Arduino IDE is ready to compile as above - it is monitoring the current file in the window - you can see this if you change the file in PSPAD and click into the Arduino IDE - the same changes appear in the Arduino IDE.

After changes are made just compile and test your program on the Arduino Uno as usual.



New! Comments

Have your say about what you just read! Leave me a comment in the box below.




Privacy Policy | Contact | About Me

Site Map | Terms of Use



Visit our Facebook Page:
To Visit Click Here


Recent Articles

  1. Arduino EEPROM - how it works and how to use it - with examples.

    Arduino EEPROM: How to use it and How to presrve the life of EEPROM. Two examples sketches to save multiple values to EEPROM.

    Read more

  2. How to use the ADS1115

    A tutorial on using the ADS1115 precision 16 bit ADC for low power use.

    Read more

  3. The TP4056: Lithium Ion/polymer Battery Charger IC

    Learn how to use the TP4056 properly. There's a right, and a wrong way, to use it to safely charge Lithium Ion batteries.

    Read more

  4. DW01A Battery Protector IC

    The DW01A chip is a Lithium Ion battery protector commonly used on TP4056 boards.  Find out Exactly how it works and how to use it the correct way.

    Read more

  5. Arduino String: How to read commands from the serial port.

    For Arduino string operations you can use Object Class Strings or C style strings but which should you use? Also find out how to decode commands and control variables in your programs using strings.

    Read more

  6. A Real Time Clock design (DS1307) with a PIC microcontroller

    Real Time Clock Design (FREE): A Free and Complete RTC design using the DS1307 and a PIC micro (16F88) also re-targetable. This PIC project uses an I2C Clock chip and 7-segment display to create a fou…

    Read more

Readers Comments

"I wanted to thank
you so so so much
for all the information
you have provided in
your site it's

SUPERB and FANTASTIC."

- Ranish Pottath

"This site really is
the best and my favorite.
I find here many useful
projects and tips."

- Milan

bursach<at>gmail.com<

"Awesome site,
very, very easy and nice
to navigate!"


- Matt
matt_tr<at>
wolf359.cjb.net


Learn Microcontrollers

"Interested in
Microcontrollers?"

Sign up for The
Free 7 day guide:

FREE GUIDE : CLICK HERE


"I am a newbie to PIC
and I wanted to say
 how great your
site has been for me."


- Dave

de_scott<at>bellsouth.net

"Your site is a great
and perfect work.
congratulations."


- Suresh

integratredinfosys<at>
yahoo.com

"I couldn't find the correct
words to define
yourweb site.

Very useful, uncovered,
honest and clear.

Thanks so much for
your time and works.
Regards."


- Anon

Back to Top