Programming an Arduino Nano
This project will help you understand how to connect a development board to your computer, install and open an IDE, write and compile a sketch, and upload and test the sketch running on the board. This is a good starting project to get familiar with a development board.
Learning Objectives
Install the Arduino IDE
To get started, install the Arduino IDE on your computer. Alternately, you can use the Arduino Cloud IDE available on the Arduino Cloud .
Components
| Component | Purpose |
|---|---|
| Arduino Nano | The microcontroller board. |
| USB Cable | To connect the board to the microcontroller. |
Circuit Diagram
There is no circuit diagram for this project, it only requires the board connected to the computer USB port using the appropriate cable.
Connections
The board needs to be connected to a computer via a USB cable for power and to upload code.There are multiple types of USB cables (with combinations of connector types A, B, and C). Connect the board to the computer using the appropriate cable.


Code
The sketch below will simply print a message to the serial monitor on setup and the repeatedly print another message to the serial monitor in a loop.
While there are no rules for structuring a sketch other than using the setup() and loop() functions as intended, it helps to organize your code in a consistent way, especially for larger sketches, as suggested in the code below.
/*
Project: A project may comprise multiple circuits and sketches.
Function: The function this sketch serves.
Circuit: The circuit within the project this sketch is for.
Boards Supported: Boards supported.
Description: Function description.
Author: STEMVentor Educonsulting
This code is copyrighted. Please do not reuse or share for any purpose other than for learning with subscribed STEMVentor programs. This code is for educational purposes only and is not for production use.
*/
// LIBRARIES
// Libraries are programs that can be used within a sketch to simplify various functions, such as reading data from complex sensors, connecting to WiFi and Bluetooth, and other such commonly used functions. Libraries may be provided by the board OEM or by individuals. Libraries can be installed from the Arduino IDE using the library installation option.
// PIN DEFINTIONS
// Components are connected to pins on the board and these pins must be specified for use in the sketch.
// CONSTANT DEFINITIONS
// A sketch may need some values that are used for computations in multiple functions but are fixed and do not change. These can be defined here as constants.
// GLOBAL VARIABLES
// A sketch may need some values that are used for computations in mulitple functions and may change through the processing steps. These can be defined here as global variables.
// INITIALIZE OBJECTS
// Libraries usually follow an object-oriented approach that requires an instance of the class to call its methods.
// LOCAL FUNCTIONS
// These functions separate out reusable or specific tasks and can be called in the setup() or loop() functions as required. In addition to reusability, this helps organize and manage code better.
// THE setup FUNCTION RUNS ONCE WHEN YOU PRESS RESET OR POWER THE BOARD.
void setup() {
Serial.begin(9600);
Serial.println("Board connected. No program loaded.");
}
// THE loop FUNCTION RUNS OVER AND OVER AGAIN FOREVER UNTIL THE BOARD IS POWERED OFF.
void loop() {
delay(1000*10); // In milliseconds
Serial.println("Board connected. No program loaded.");
}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.