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.
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
Menu > Tools > Board:
Now select: "Arduino/Genuino Uno" for the Arduino Uno Board.
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.
Note: Your port number may be different e.g. COM5. Select whichever has the "Arduino/Genuion Uno" text.
Having selected the port you can check by using the Menu:
Menu > Tools
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
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.
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.
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 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
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'.
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 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:
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:
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
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
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:
... and change it to:
... 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.
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…