The Arduino IDE

The Arduino Integrated Development Environment (or Arduino IDE) allows you to write a sketch, compile the sketch, upload the sketch to a board connected to the computer via an USB cable, send data to the board and read the output from the board.

Sketches are written in the text editor and are saved with the file extension .ino. The Arduino IDE supports the most commonly used boards and even includes sample sketches for each board that can be used as a starting point for writing your sketches or only to test the board.

The following steps should be followed when creating a sketch using the IDE features and functions:

Connect the Board

An Arduino board needs to be connected to a computer via a USB cable (each board may use different USB connectors) for three things:

  • To power up the board
  • To upload programs from the computer to the board.
  • To send input data from the computer to the board and output data from the board to the computer.

The IDE includes the drivers (a driver is an operating system level program that sets up devices attached to a computer to interact with each other) for most current boards. The IDE also has a Boards Manager to add a new board that is not already supported. Some boards connect without much effort, and others may need a small effort to get them to connect.

In computing, a serial port is a serial communication interface through which information transfers in or out sequentially one bit at a time. It is in contrast to a parallel port, which communicates multiple bits simultaneously in parallel. Although the USB (Universal Serial Bus) port is much faster than earlier serial ports and designed differently, but works just like a serial port. To communicate with the board, the IDE needs to know which port to the board is connected. You can select the port using the Tools->Port menu option. The port name is different for each operating system and the drivers used, but some of the more common port names are listed below: Windows: Ports are named COM1, COM2, etc. COM is short for communication. An Arduino board generally connects on COM3 or higher, but that could change depending on the driver. macOS: Ports are named as /dev/tty.usbserial or /dev/cu.usbserial, but the name can be anything, depending on the driver.

The Arduino IDE should detect the serial port where the board is connected, but for some boards, specific serial communication drivers may need to be installed. For example, the CH340 chip is used by several Arduino compatible boards (including the Arduino Nano) for serial communication. It requires a CH340 driver to be installed on your computer, and the port shows up as /dev/cu.wchusbserial or something similar. For more information, visit: https://github.com/adrianmihalko/ch340g-ch34g-ch34x-mac-os-x-driver (opens in a new tab)

If you use all original Arduino boards, all the software and drivers you need will be available on the board or the official Arduino website. However, original boards are slightly expensive, and hobbyists and learners tend to use compatible boards. The software and drivers for these boards may be provided by the manufacturer or a community of developers. While we try to provide links to stable versions of all software, but some versions of the board may not work for you. You will need to search the Arduino forum or the web for the right software.

Write the Sketch

The editor has the usual features of any text editor for writing code and editing it. The message area gives feedback while saving and exporting and also displays errors. The console displays text output by the Arduino Software (IDE), including complete error messages and other information. The bottom righthand corner of the window displays the configured board and serial port. The toolbar buttons allow you to verify and upload programs, create, open, save sketches, and open the serial monitor.

Connect a board to the Computer

When the board is connected to the computer it shows up in the list of boards. It also shows a list of serial ports on the computer to which the board is connected.

Select an Arduino Board and a Port

Before compiling a sketch, the Arduino board that it is intended to run on must be selected. Select the serial port the board is connected to. The computer and the board use the serial port to which the USB cable is connected to upload the sketch and exchange input and output data.

Compile the Sketch

Once a sketch has been written using the editor, it can be compiled. And if any error is displayed in the message area of the IDE, then shows an error or a compilation success message is displayed.

Upload the Sketch

Once the sketch is compiled successfully, it can be uploaded to the connected Arduino board.

The bootloader is a bit of code that is preloaded on all Arduino boards and starts running when you power up the board. Its main function is to wait for the Arduino IDE on your computer to which the board is connected to send it a new program, which it then writes to the memory on the Arduino board. The bootloader is what enables you to program the Arduino using just the USB cable.

Generally, every board has a fixed microprocessor, but sometimes the processor may vary. As in the case of the Arduino Nano, there is a newer version of the processor in the original board, while compatible boards still use the old version. For such boards, the IDE offers an option to select the processor bootloader. In the case of the Nano, you can choose between ATmega328P and ATmega328P (Old Bootloader). Read your board specifications and select the specified bootloader. If the incorrect bootloader is selected, the sketch upload will fail, and an error will be displayed in the console.

For some boards, a button needs to be pressed to allow the IDE to make a connection with the board before it starts to upload a sketch.

After the sketch has been compiled, click on the upload icon to upload the sketch to the board. Usually, you'll find some LED indicators on the board, which will blink while the sketch is being uploaded.

Serial Monitor

The IDE has a feature that allows you to communicate with a board connected to a computer. Once the sketch has been written, compiled, and uploaded to the board, you can open the Serial Monitor, which pops up as a new window. The sketch can be instructed to send data to the serial monitor for debugging or reading actual data sent by sensors in the circuit. And, if the sketch is programmed to receive and data as a serial input, you can type this data into the Serial Monitor window and send it to the board.

When using serial communication, such as from the Serial Monitor, a parameter known as baud rate is important. The baud rate specifies how fast data is sent over a serial line, which is determined by the in-built hardware and how fast a clock cycle it can support. Digital data transfer is also measured in bits per second (bps) which is the number of bits of data transferred per second. One or more bits are transferred in every clock cycle. So, at a baud rate of 9600, it is transferring 1 bit per clock cycle with the data transfer speed of 9600 bps; in the case of 2 bits per clock cycle, the data transfer speed will be around 19200 bps and continued to increase with the bits per clock cycle.

Two devices communicating with each other must use the same baud rate. The higher the baud rate, the faster data is sent and received, but there are limits to how fast data can be transferred. Generally, the highest baud rate for a microcontroller is 115200, with 9600 being the baud rate most commonly used. Using baud rates higher than what the hardware can support will result in transmission errors. When using the Serial Monitor, the baud rate must be set as programmed on the Arduino board. If an incorrect baud rate is selected, the Serial Monitor will show garbled data.

Test Sketches

The easiest way to test that the board is connected to the computer and working fine is to open a sketch from one of the basic examples, and we suggest you start with Blink. Open the sketch and upload it to the Nano connected to your computer.

After the sketch is opened, you can directly upload it using the quick access button or the Sketch->Upload menu option. The IDE will display a message when the upload is complete or display an error message if there is a problem. If the sketch is uploaded successfully, an onboard LED on Pin 13 should blink at 1-second intervals.

This blink suggests that you have successfully connected your Arduino board to your computer, loaded a simple pre-written sketch into your IDE, uploaded it to the board, and got the board to do what it is programmed in the sketch.