LAB NO: 03
Objectives:
Learn about the Arduino Nano board
Understand the detailed specifications of the Arduino Nano
Familiarize with the pinouts of the Arduino Nano
Learn how to use digital and analog pins
Write a small program for the Arduino Nano
1. Introduction to Arduino Nano:
The Arduino Nano is a small, breadboard-friendly microcontroller board based on the
ATmega328P. It is similar in functionality to the Arduino Uno but comes in a smaller form
factor, making it ideal for compact projects and embedding into small spaces.
2. Specifications of Nano:
Microcontroller: ATmega328P
Operating Voltage: 5V
Input Voltage (recommended): 7-12V
Input Voltage (limit): 6-20V
Digital I/O Pins: 14 (of which 6 provide PWM output)
Analog Input Pins: 8
DC Current per I/O Pin: 40 mA
Flash Memory: 32 KB (ATmega328P) of which 2 KB used by the bootloader
SRAM: 2 KB (ATmega328P)
EEPROM: 1 KB (ATmega328P)
Clock Speed: 16 MHz
3. Pinouts:
The Arduino Nano has various pins for connecting external components. These pins can
be categorized into digital pins, analog pins, and power pins.
Digital Pins:
Total: 14 (D0-D13)
PWM Pins: 6 (D3, D5, D6, D9, D10, D11)
Special Functions: Pin 0 (RX) and Pin 1 (TX) are used for serial communication.
Analog Pins:
Total: 8 (A0-A7)
Resolution: 10-bit (returns values between 0 and 1023)
Special Functions: These pins can also be used as digital I/O pins.
Power Pins:
Vin: Input voltage to the Arduino board when using an external power source (7-12V).
5V: Provides a regulated 5V output.
3.3V: Provides a 3.3V output generated by the on-board regulator.
GND: Ground pins.
4. Using Digital Pins:
Digital pins on the Arduino Nano can be used as input or output. When used as output,
they can drive LEDs, relays, and other components. When used as input, they can read the state
of switches, sensors, etc.
Example - Digital Pin as Input: This example will read the state of a push button connected to
digital pin 7 and turn on an LED connected to digital pin 8 if the button is pressed.
Circuit Setup:
Connect one terminal of the push button to 5V.
Connect the other terminal of push button to digital pin 7.
Connect the positive leg of the LED to digital pin 8.
Connect the negative leg of the LED to a 220-ohm resistor.
Connect the other end of the resistor to GND.
Code:
int buttonPin = 7; // Define the button pin
int ledPin = 8; // Define the LED pin
int buttonState = 0; // Variable to store the button state
void setup() {
pinMode(buttonPin, INPUT); // Set the button pin as input
pinMode(ledPin, OUTPUT); // Set the LED pin as output
}
void loop() {
buttonState = digitalRead(buttonPin); // Read the button state
if (buttonState == HIGH) { // If the button is pressed
digitalWrite(ledPin, HIGH); // Turn the LED on
} else { // If the button is not pressed
digitalWrite(ledPin, LOW); // Turn the LED off
}
}
Expected Result: The LED connected to pin 8 will turn on when the button connected to pin 7 is
pressed.
5. Using Analog Pins:
Analog pins on the Arduino Nano can read analog signals (e.g., from a potentiometer or a
sensor) and convert them into digital values.
Example - Reading an Analog Value: This example will read the value from a temperature
sensor connected to analog pin A0 and print the value to the Serial Monitor.
Circuit Setup:
Connect the LM35 temperature sensor:
VCC to 5V
GND to GND
Vout to analog pin A0
Code:
int tempPin = A0; // Define the temperature sensor pin
float temperature = 0; // Variable to store the temperature value
void setup() {
Serial.begin(9600); // Start the Serial Monitor
}
void loop() {
int tempReading = analogRead(tempPin); // Read analog value of sensor
temperature = (tempReading * 5.0 * 100.0) / 1024; // Convert to Celcious
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
delay(1000); // Wait for one second
}
Expected Result: The Serial Monitor will display the temperature in degrees Celsius read from
the LM35 sensor.
6. Small Program for Controlling a DC Motor:
Components Needed:
Arduino Nano
NPN Transistor (e.g., 2N2222)
DC Motor
Diode (e.g., 1N4007)
220-ohm resistor
Potentiometer
External Power Supply (if needed, e.g., 9V battery)
Breadboard and jumper wires
Connections:
1. Potentiometer:
o Connect one end to 5V.
o Connect the other end to GND.
o Connect the wiper (middle pin) to analog pin A0.
2. Transistor:
o Base: Connect to digital pin 9 through a 220-ohm resistor.
o Collector: Connect to one terminal of the DC motor.
o Emitter: Connect to GND.
3. DC Motor:
o Connect the other terminal to the positive terminal of the external power supply.
o Connect the negative terminal of the external power supply to GND.
4. Diode:
o Connect across the DC motor terminals (cathode to the positive terminal, anode to
the negative terminal).
Code:
int potPin = A0; // Define the potentiometer pin
int motorPin = 9; // Define the motor control pin
void setup() {
pinMode(motorPin, OUTPUT); // Set the motor control pin as output
}
void loop() {
int potValue = analogRead(potPin); // Read the analog value
// Map the value to a range of 0-255
int motorSpeed = map(potValue, 0, 1023, 0, 255);
analogWrite(motorPin, motorSpeed); // Set the motor speed
delay(100); // Wait for a short period
}
Expected Result: The speed of the DC motor will vary based on the position of the
potentiometer.
~~~~~~~~~~~~~ End Lab 3~~~~~~~~~~~~~