Arduino Unit5 Complete Notes
Arduino Unit5 Complete Notes
Contents
→ Overview of Arduino
→ Introduction to ATmega328P
1. Overview of Arduino
Arduino is an open-source electronics prototyping platform that combines easy-to-use hardware and
software, making it accessible to both beginners and advanced users. It consists of a programmable circuit
board — called a microcontroller board — and a software environment called the Arduino IDE
(Integrated Development Environment), which is used to write and upload programs to the board.
Page 2
Unit V — I/O Interfacing with Arduino BTech Embedded System Design
Although all Arduino boards are programmed through the same Arduino IDE, they differ in terms of the
number of I/O pins, speed, operating voltage, memory capacity, and physical size. The three most
commonly used boards — and the ones specified in your syllabus — are the Arduino UNO, Arduino
NANO, and Arduino MEGA.
Feature Specification
Microcontroller ATmega328P
Operating Voltage 5V
SRAM 2 KB
EEPROM 1 KB
Feature Specification
Microcontroller ATmega328P
Page 3
Unit V — I/O Interfacing with Arduino BTech Embedded System Design
Feature Specification
Operating Voltage 5V
Flash Memory 32 KB
SRAM 2 KB
EEPROM 1 KB
Feature Specification
Microcontroller ATmega2560
Operating Voltage 5V
SRAM 8 KB
EEPROM 4 KB
Page 4
Unit V — I/O Interfacing with Arduino BTech Embedded System Design
PWM Pins 6 6 15
SRAM 2 KB 2 KB 8 KB
EEPROM 1 KB 1 KB 4 KB
Page 5
Unit V — I/O Interfacing with Arduino BTech Embedded System Design
The Arduino UNO hardware is built around a PCB-mounted microcontroller — the ATmega328P — along
with all supplementary components required for power regulation, USB communication, and I/O
interfacing. The block diagram below shows the major functional modules of the Arduino UNO board.
■ EEPROM (1 KB)
EEPROM (Electrically Erasable Programmable Read-Only Memory) is non-volatile storage that can be
written and read by the program at runtime. It is slower than SRAM but retains data after power-off,
making it useful for storing user settings, sensor calibration values, or any data that must persist between
sessions. The EEPROM.h library in Arduino makes it easy to read and write EEPROM.
Page 6
Unit V — I/O Interfacing with Arduino BTech Embedded System Design
■ Program Counter
The Program Counter is a special register that always holds the memory address of the next instruction to
be executed. After each instruction completes, the Program Counter automatically increments to point to
the next instruction, enabling sequential program execution.
■ Interrupt Unit
The interrupt unit allows external events — such as a button press or a timer overflow — to temporarily
pause the main program and execute a special Interrupt Service Routine (ISR). Once the ISR finishes, the
main program resumes from where it left off. This mechanism is essential for real-time responsiveness in
embedded systems.
■ Watchdog Timer
The watchdog timer is a safety mechanism that automatically resets the microcontroller if the program
becomes stuck in an infinite loop or crashes. The program must periodically 'pet' (reset) the watchdog
timer to prevent a reset. This is critically important in industrial and safety-critical embedded applications.
■ Analog Comparator
The analog comparator compares two analog voltage levels applied to its input pins and outputs a digital
HIGH or LOW signal depending on which input is greater. It is used in applications like zero-crossing
detection and simple threshold monitoring.
Page 7
Unit V — I/O Interfacing with Arduino BTech Embedded System Design
The Arduino UNO exposes the microcontroller's capabilities through a set of clearly labelled pins on its two
pin headers. Understanding what each pin does is fundamental to building any Arduino circuit. The pin
diagram below shows the physical layout of all pins on the Arduino UNO.
Figure 3: Arduino UNO Pin Diagram showing Analog, Digital, PWM, and Power Pins
Pin Description
3.3V (Pin 6) Provides a regulated 3.3V output to power external components that operate at 3.3V logic. Maximum
5V (Pin 7) Provides a regulated 5V output. This pin is the standard supply for most sensors and modules.
GND (Pin 8) Ground reference (0V). Multiple GND pins are available and any one can be used to complete a circu
Vin (Pin 9) Voltage Input — when powering the Arduino from an external source (7–12V) via the barrel jack, this
AREF Analog Reference pin. It sets the maximum voltage that the ADC uses as reference for analog-to-dig
RESET Pulling this pin LOW resets the microcontroller, restarting the sketch from the beginning.
IOREF Provides the reference voltage at which the microcontroller operates. Shields use this to determine th
Pin Function
D0 (RX) Serial Receive — receives serial data. Avoid using this pin as GPIO if the Serial Monitor is in use.
D2 General digital I/O. Also serves as External Interrupt 0 (INT0) — can trigger an ISR on rising/falling/changing
D9 (~) PWM output pin. Commonly used for servo motor control.
D10 (~) PWM output pin. Also used as SPI SS (Slave Select).
D11 (~) PWM output pin. Also used as SPI MOSI (Master Out Slave In).
Page 8
Unit V — I/O Interfacing with Arduino BTech Embedded System Design
Pin Function
D12 General digital I/O. Also used as SPI MISO (Master In Slave Out).
D13 General digital I/O. Also used as SPI SCK (Serial Clock). Connected to the on-board LED (L).
Note: Pins marked with '~' on the Arduino board support PWM (Pulse Width Modulation) output. These are pins D3,
D5, D6, D9, D10, and D11.
Conversion Formula:
For example, if a temperature sensor outputs 2.5V, the ADC will produce a reading of (2.5 ÷ 5.0) × 1023 =
511. The analog pins can also be used as regular digital I/O pins when analog input is not needed. Pins A4
and A5 serve the additional role of I2C communication pins (SDA and SCL respectively) when the Wire
library is used.
Pin Function
A4 (SDA) Analog input channel 4. Also serves as I2C Serial Data line.
A5 (SCL) Analog input channel 5. Also serves as I2C Serial Clock line.
Timer 0 (8-bit) D5, D6 Manages millis(), micros(), delay() functions. Also produces PWM on D5 and D6.
Timer 1 (16-bit) D9, D10 Higher resolution timer. Used for servo library. Produces PWM on D9 and D10.
Page 9
Unit V — I/O Interfacing with Arduino BTech Embedded System Design
Timer 2 (8-bit) D3, D11 Used by tone() function for sound generation. Produces PWM on D3 and D11.
In Arduino code, PWM is generated using the analogWrite(pin, value) function, where 'value' ranges from
0 (0% duty cycle, 0V) to 255 (100% duty cycle, 5V). PWM pins are D3, D5, D6, D9, D10, and D11 on the
UNO.
D10 SS (Slave Select) Pulled LOW by the master to select (activate) a specific slave device.
D11 MOSI (Master Out Slave In) Data flows FROM the Arduino (master) TO the slave device.
D12 MISO (Master In Slave Out) Data flows FROM the slave device TO the Arduino (master).
D13 SCK (Serial Clock) Clock signal generated by the master to synchronise data transfer.
Pin Function
A4 (SDA) Serial Data Line — carries the actual data bits between master and slave.
Page 10
Unit V — I/O Interfacing with Arduino BTech Embedded System Design
Pin Function
A5 (SCL) Serial Clock Line — provides the synchronisation clock signal generated by the master.
Page 11
Unit V — I/O Interfacing with Arduino BTech Embedded System Design
Feature Detail
Page 12
Unit V — I/O Interfacing with Arduino BTech Embedded System Design
Flash Memory 32 KB Non-volatile Stores the user program (sketch). Written via the bootloader over USB. Retaine
SRAM 2 KB Volatile Stores variables, stack, and heap at runtime. Contents lost on power-off.
EEPROM 1 KB Non-volatile Stores persistent data that must survive power cycles. Endurance: 100,000 writ
Page 13
Unit V — I/O Interfacing with Arduino BTech Embedded System Design
An LCD (Liquid Crystal Display) is one of the most common output devices used with Arduino. The 16×2
LCD — which has 16 columns and 2 rows, able to display 32 characters total — is the standard choice for
most projects. It uses the HD44780 controller, which is compatible with the Arduino LiquidCrystal library.
3 — V0 Contrast adjustment. Connected to the wiper of a 10kΩ potentiometer. Adjusting this changes charac
4 — RS Register Select. RS=0 selects the Command Register (send instructions). RS=1 selects the Data Re
5 — RW Read/Write select. RW=0 for write mode (most common). Typically connected to GND since we almo
6 — EN Enable pin. A HIGH-to-LOW pulse on this pin causes the LCD to read the data present on the data p
7–10 (D0–D3) Lower 4 data bits. Not used in the common 4-bit interface mode.
11–14 (D4–D7) Upper 4 data bits. Used in 4-bit mode to send data as two nibbles sequentially.
8-Bit Mode
In 8-bit mode, all 8 data pins (D0–D7) are connected to the Arduino. Each byte is sent in a single transfer,
making it slightly faster than 4-bit mode. However, it uses 10 Arduino pins (RS, RW, EN, D0–D7), which is
expensive in terms of I/O. This mode is rarely used in Arduino projects due to the pin requirement.
Page 14
Unit V — I/O Interfacing with Arduino BTech Embedded System Design
#include <LiquidCrystal.h>
// LiquidCrystal(RS, EN, D4, D5, D6, D7)
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
[Link](16, 2); // Initialize 16 cols, 2 rows
[Link]("Hello World!"); // Print text on row 1
[Link](0, 1); // Move to row 2, col 0
[Link]("Arduino LCD");
}
void loop() {} // Nothing repeating needed
Page 15
Unit V — I/O Interfacing with Arduino BTech Embedded System Design
A seven segment display is an electronic display device that uses seven individual LED segments
arranged in a figure-8 pattern to represent decimal digits (0–9) and some alphabetical characters. Each
segment is labelled 'a' through 'g', with an optional decimal point (dp).
Common Anode (CA) All the anodes (positive terminals) of the seven LEDs are connected together to VCC (+5V). To light a se
Common Cathode (CC) All the cathodes (negative terminals) are connected together to GND. To light a segment, its anode mus
0 1 1 1 1 1 1 0
1 0 1 1 0 0 0 0
2 1 1 0 1 1 0 1
3 1 1 1 1 0 0 1
4 0 1 1 0 0 1 1
5 1 0 1 1 0 1 1
6 1 0 1 1 1 1 1
7 1 1 1 0 0 0 0
8 1 1 1 1 1 1 1
9 1 1 1 1 0 1 1
Note: 1 = Segment ON (LED lit), 0 = Segment OFF. A current-limiting resistor of 220Ω–470Ω must be placed in series
with each segment pin to protect the LEDs from excessive current.
Page 16
Unit V — I/O Interfacing with Arduino BTech Embedded System Design
When multiple seven-segment digits are needed (for example, to display a 4-digit number), it is impractical
to control each digit independently — that would require too many Arduino pins. Instead, time-division
multiplexing is used. In this technique, only one digit is enabled (its common pin activated) at a time, and
the segment data for that digit is applied. This switches between digits so rapidly (typically every 1–5 ms)
that the human eye perceives all digits as being lit simultaneously due to the persistence of vision effect.
This allows 4 digits to be driven using just 8 segment pins + 4 digit select pins.
Page 17
Unit V — I/O Interfacing with Arduino BTech Embedded System Design
A relay is an electrically operated switch. It uses a small control signal (from the Arduino) to switch a much
larger electrical load — such as a 230V AC appliance — ON or OFF. This makes it possible for the
Arduino (which operates at 5V) to control high-voltage devices safely, with complete electrical isolation
between the control circuit and the load circuit.
VCC Power supply for the relay module. Typically +5V from the Arduino 5V pin.
IN (Signal) Control input from an Arduino digital pin. Writing HIGH or LOW here controls the relay state. Note: most rela
COM (Common) The common terminal of the relay switch. The load is typically connected between COM and NO or NC.
NO (Normally Open) This contact is OPEN when the relay is not energised. It CLOSES when the relay is activated. Used to switc
NC (Normally Closed) This contact is CLOSED when the relay is not energised. It OPENS when the relay is activated. Used when
Page 18
Unit V — I/O Interfacing with Arduino BTech Embedded System Design
A stepper motor is a brushless DC motor that divides a full rotation into a number of equal discrete steps.
Unlike a regular DC motor that spins continuously when power is applied, a stepper motor moves one step
at a time, and each step corresponds to a fixed angle — typically 1.8° per step, which means 200 steps
equal one full 360° revolution. Because of this, stepper motors can be precisely controlled in terms of both
position and speed without requiring a position feedback sensor.
Unipolar Has 5 or 6 wires. Each coil winding has a centre tap. Easier to control
5V steppers,
as eachprinters
half-winding is driven independe
Bipolar Has 4 wires. Both ends of each coil are driven, reversing current3D
direction
printers,
to CNC
change
machines,
polarity. robotics
Produces more to
Note: Half-step mode alternates between single-coil and dual-coil energisation, doubling the resolution to 0.9° per
step (400 steps per revolution). The Stepper library in Arduino IDE simplifies stepper motor control.
Page 19
Unit V — I/O Interfacing with Arduino BTech Embedded System Design
A DC (Direct Current) motor converts electrical energy into rotational mechanical energy. When a voltage
is applied across its terminals, the motor shaft spins continuously. The speed of rotation is proportional to
the applied voltage, and the direction of rotation can be reversed by reversing the polarity of the applied
voltage. DC motors are widely used in robotics, conveyor systems, and fan control.
ENA (Enable A) PWM signal from Arduino to control the speed of Motor A. analogWrite(ENA, 0–255) sets speed.
IN1 Direction control for Motor A — pin 1. Set HIGH or LOW to select direction.
IN2 Direction control for Motor A — pin 2. Opposite of IN1 for forward; same as IN1 for brake.
VCC (Motor Supply) External power supply for the motors (up to 46V). Separate from Arduino's 5V supply.
GND Common ground shared between Arduino and motor power supply.
5V Output Provides regulated 5V output (when the onboard regulator is enabled) to power the Arduino.
Page 20
Unit V — I/O Interfacing with Arduino BTech Embedded System Design
Page 21
Unit V — I/O Interfacing with Arduino BTech Embedded System Design
Sensors are devices that detect and measure physical quantities from the environment — such as
temperature, light intensity, distance, and motion — and convert them into electrical signals that the
Arduino can read. Different sensors interface with the Arduino through analog pins, digital pins, or
communication protocols such as UART, SPI, and I2C.
Specification Detail
Output 10 mV/°C
Specification Detail
Page 22
Unit V — I/O Interfacing with Arduino BTech Embedded System Design
Specification Detail
Specification Detail
Supply Voltage 5V
Range 2 cm to 400 cm
Resolution 3 mm
Page 23
Unit V — I/O Interfacing with Arduino BTech Embedded System Design
Specification Detail
Supply Voltage 5V
Page 24
Unit V — I/O Interfacing with Arduino BTech Embedded System Design
Arduino Overview Open-source platform with IDE + microcontroller board. Uses simplified C++. No external program
Arduino UNO ATmega328P, 8-bit, 16 MHz, 14 digital pins (6 PWM), 6 analog pins, 32KB Flash, 2KB SRAM, 1K
Arduino NANO Same chip as UNO (ATmega328P) but smaller form factor. 8 analog pins. No barrel jack. Breadb
Arduino MEGA ATmega2560, 54 digital pins (15 PWM), 16 analog pins, 256KB Flash, 8KB SRAM, 4 UART ports
Block Diagram Flash (program) + SRAM (data) + EEPROM (persistent) + ALU + Registers + Interrupt Unit + Wa
Digital Pins D0–D13 14 pins. HIGH=5V, LOW=0V. D0=RX, D1=TX, D2/D3=Interrupts, D3/5/6/9/10/11=PWM.
Analog Pins A0–A5 10-bit ADC. Reads 0–5V as 0–1023. A4=SDA (I2C), A5=SCL (I2C). Formula: value = (V/5.0) × 10
PWM Pins D3, D5, D6, D9, D10, D11 (marked ~). analogWrite(pin, 0–255). Used for LED brightness, motor
SPI Pins D10=SS, D11=MOSI, D12=MISO, D13=SCK. High-speed 4-wire synchronous protocol.
I2C Pins A4=SDA, A5=SCL. 2-wire multi-device protocol. Each device has unique 7-bit address.
ATmega328P 8-bit AVR RISC, Harvard architecture. 32KB Flash, 2KB SRAM, 1KB EEPROM, 16 MHz (on UNO
LCD 16×2 16 cols × 2 rows. HD44780 controller. Pins: RS, EN, D4–D7 (4-bit mode). I2C module reduces to
Seven Segment 7 LEDs (a–g). Common Anode: LOW=ON. Common Cathode: HIGH=ON. Multiplexing for multi-d
Relay Electrically isolated switch. Coil (5V) → Magnetic field → Contacts switch 230V load. Active-LOW
Stepper Motor 1.8°/step = 200 steps/revolution. Unipolar: ULN2003 driver. Bipolar: L298N driver. Full-step sequ
DC Motor Speed via PWM on Enable pin. Direction via IN1/IN2 logic. Driver: L298N (up to 2A, 46V).
Sensors LM35: 10mV/°C analog. DHT11: digital temp+humidity. LDR: light-dependent resistance (analog)
Exam Tips: Focus on (1) differences between UNO, NANO, MEGA in a table format, (2) the role of each
block in the ATmega328P block diagram, (3) which pins are PWM, SPI, I2C, and analog, (4) relay working
principle and the need for a flyback diode, (5) stepper motor step sequence and driver ICs, and (6) the
distance formula for HC-SR04. All the best for your final examination!
Page 25