Getting started with the Arduino Nano

Getting started with the Arduino Nano

The Arduino Nano development board, or simply Arduino Nano, is a popular choice for microelectronic projects. Here we show how to get started.

Introduction to getting started with the Arduino Nano

Using the Arduino Nano is a great way to learn about microcontrollers and electronics. With its small size and versatility, it can be used in a wide range of DIY projects, from simple LED displays to more complex robotic systems.

Programming the Arduino Nano is also easy and can be done using the Arduino IDE, which has a vast community and library of code examples to draw from.

Getting started with the Arduino Nano will explain and show how to hook the board up to a LED, set up and connect it to the Arduino IDE and how to upload a simple sketch to make the LED blink on and off.

Requirements and assumptions

These are the parts that were used:

Get the Microelectronics Starter Kit from Amazon.com or BangGood

Wiring the components

Rrduino Nano v3 Basic PinoutUsing a breadboard, wire the Arduino Nano, resistor and LED together. Here D2 was wired, but any digital pin can be used. The pins will probably be marked. D2 and the ground (GND) pin should be right next to each other.

Arduino Nano LED schematic

Schematic of the Arduino Nano with LED.

Arduino Nano board layout

Arduino Nano board layout

Arduino Nano wiring

Wiring of the Arduino Nano to a LED.

The LED

Out of the box, LEDs will have a long leg (anode) and a short leg (cathode). The specifications (forward Voltage or Vf @ a specific current or If) of LEDs (usually size and colour dependent) will be available from the manufacturer/datasheet.

LEDs can be connected directly to a breadboard. The long leg is connected to the digital write pin of the Arduino Nano and the short leg to a resistor.

The resistor

Each digital pin of the Arduino Nano supplies 5V DC, so in order not to overload the LED (which usually has a forward Voltage (Vf) of about 2 – 3 V DC @ about 20 mA), a 220 Ohm resistor is usually safe to use.

Resistors can be connected directly to a breadboard. One leg is connected to the cathode of the LED and the other leg is connected to the ground (GND) pin of the Arduino Nano. It doesn’t matter which side of the resistor is used where.

Using the Arduino IDE

After the wiring has been done, the Arduino Nano should be connected and configured to be programmed by the Arduino IDE. Programming is done by uploading ‘sketches’ from the PC, on which the IDE is installed, onto the Arduino Nano.

Board drivers for the Nano are automatically installed when the software package is installed, but after connecting the PC with the Arduino Nano using a Mini-B USB cable, additional operating system drivers might start to install automatically. When the onboard LED of the Arduino Nano is lit, the Arduino IDE can be opened.

The Arduino IDE can be used to program a multitude of microcontroller boards. In order to use board-specific configuration, the board settings and the port settings need to be configured each time a new microcontroller board is connected.

In this case, Arduino Nano can be selected from the Tools > Board menu. Arduino Duemilanove or Nano w/ ATmega328 can also be used in the case of version 3 boards and Arduino Diecimila, Duemilanove, or Nano w/ ATmega168 can be used in the case of version 2 boards.

The Arduino IDE also needs to know what communication/serial port (COM port) to use to connect to the board. Selecting the correct port number is a bit of a guess, but generally, the highest port number will be the correct one. The serial port is selected from the Tools > Serial Port menu.

The sketch

After the Arduino IDE has been configured correctly, the Arduino Nano can be programmed by uploading a sketch. One way to get started with any microcontroller board is by uploading a simple tester or ‘blink’ script/code to see if everything is configured correctly and to start testing the final project code.

Choosing the sketch

In this case, the Blink sketch will be used to tell the microcontroller to switch the onboard LED on and then switch it off again — over and over again.

To access the Blink sketch, go to File > Examples > Basics > Blink. This will load the default blinking sketch from the Arduino IDE’s build-in sketch library:

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control.
  On the Uno, Nano and Leonardo, it is attached to digital pin 13.
 */

#define LED 13 // define connection of LED, in this case 13

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(LED, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(LED, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

To make the wired LED blink, the pin needs to be replaced with the pin used to wire the LED. In the following example, the second digital write pin (D2) was used, but any other digital write pin can be used. The sketch is also somewhat different from the previous one to show some variation in the possibilities:

// Pin connected to the LED
const int ledPin = 2;

// Time interval for blinking (in milliseconds)
const unsigned long interval = 1000;

// Variables to store the current and previous times
unsigned long previousTime = 0;
unsigned long currentTime = 0;

// Variable to store the current state of the LED
bool ledState = false;

void setup() {
  // Initialize the LED pin as an output
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // Get the current time
  currentTime = millis();

  // Check if the interval has elapsed
  if (currentTime - previousTime >= interval) {
    // Store the current time as the previous time
    previousTime = currentTime;

    // Toggle the LED state
    ledState = !ledState;

    // Set the LED pin to the new state
    digitalWrite(ledPin, ledState);
  }
}

This code will make the LED connected to pin 2 on the Arduino board blink on and off at a 1-second interval.

You can modify the ledPin variable to use a different pin if needed. Simply copy and paste this code into the Arduino IDE, upload it to your Arduino board, and you should see the LED blinking.

Uploading the sketch

Sketches are uploaded by pressing the Upload (->) button in the Arduino IDE. After the code has been successfully uploaded, the board will automatically reset and the sketch will start to run.

Arduino Nano Blink upload

Arduino IDE to Arduino Nano Blink sketch upload.

Conclusion

The Arduino Nano is great for learning microcontrollers and microelectronics. Programming the Arduino Nano is easy and can be done using the Arduino IDE, which has a vast community and library of code examples to draw from.

Leave a Reply

Your email address will not be published. Required fields are marked *