0% found this document useful (0 votes)
2 views27 pages

Arduino Unit5 Complete Notes

This document provides an overview of Arduino, detailing its types (UNO, NANO, MEGA), key features, and applications in embedded system design. It includes functional block diagrams, pin functions, and specifications for each board type, emphasizing their differences in I/O capabilities and memory. Additionally, it covers interfacing with various peripherals such as sensors, motors, and displays.

Uploaded by

vibhuti baldva
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views27 pages

Arduino Unit5 Complete Notes

This document provides an overview of Arduino, detailing its types (UNO, NANO, MEGA), key features, and applications in embedded system design. It includes functional block diagrams, pin functions, and specifications for each board type, emphasizing their differences in I/O capabilities and memory. Additionally, it covers interfacing with various peripherals such as sensors, motors, and displays.

Uploaded by

vibhuti baldva
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Unit V

I/O Interfacing with Arduino

BTech Third Year — Embedded System Design

Final Examination Notes

Contents
→ Overview of Arduino

→ Types: UNO, NANO, MEGA

→ Functional Block Diagram of Arduino

→ Pin Functions: Analog I/O, Digital I/O, Timer, PWM

→ Introduction to ATmega328P

→ Peripheral Interfacing: LCD, Seven Segment LED

→ Relay, Stepper Motor, DC Motor Interfacing

→ Sensor Interfacing with Arduino


Unit V — I/O Interfacing with Arduino BTech Embedded System Design

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.

Key Features of Arduino


• Reads analog and digital input signals from different sensors such as temperature, humidity, and
motion sensors, and converts them into useful outputs like activating a motor, turning an LED on or off,
or connecting to the cloud.
• Programmable via Arduino IDE using a simplified version of C++, which makes it easier to learn and
use compared to traditional microcontroller programming.
• No external programmer required — unlike most previous programmable circuit boards, Arduino can
load new code directly through a USB cable, which serves as both a power and data connection.
• Standard form factor — Arduino provides a consistent physical layout that exposes the
microcontroller's functions through accessible connectors, making it easy to attach sensors, actuators,
and shields.
• Open-source hardware and software — both the hardware design files and the IDE source code are
freely available, which has resulted in a massive global community and hundreds of compatible
accessories.
• Cross-platform IDE — the Arduino IDE runs on Windows, macOS, and Linux, making development
accessible on any operating system.

What Can Arduino Do?


Arduino can serve as the brain of almost any simple embedded project. It can read sensor values, perform
logic and calculations, control motors and displays, communicate over wired or wireless protocols, and
respond to real-world events in real time. Practical applications include home automation systems,
weather stations, robotics, automatic irrigation, gesture-controlled devices, and many more.

Page 2
Unit V — I/O Interfacing with Arduino BTech Embedded System Design

2. Types of Arduino Boards

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.

2.1 Arduino UNO


The Arduino UNO is the most widely used and recommended Arduino board for beginners. It holds more
than 50% market share among all Arduino boards and is considered the standard reference board for
prototyping and learning. The UNO is based on the ATmega328P microcontroller, an 8-bit AVR RISC
processor running at 16 MHz. It is powered via USB or through an external barrel jack power supply
(7–12V recommended).

Feature Specification

Microcontroller ATmega328P

Architecture 8-bit AVR RISC

Clock Speed 16 MHz

Operating Voltage 5V

Digital I/O Pins 14 (of which 6 support PWM output)

Analog Input Pins 6 (A0 to A5), 10-bit ADC

Flash Memory 32 KB (0.5 KB used by bootloader)

SRAM 2 KB

EEPROM 1 KB

DC Current per I/O Pin 40 mA (max)

USB Interface USB-B (square type)

External Power 7–12V via barrel jack

2.2 Arduino NANO


The Arduino NANO is a compact, breadboard-friendly version of the UNO. It uses the same ATmega328P
microcontroller, so it has the same processing power and memory as the UNO, but it is significantly
smaller in size. The NANO is ideal for projects where space is limited, such as wearable electronics, small
robots, and compact sensor nodes. A key advantage over the UNO is that the NANO provides 8 analog
input pins instead of 6, giving more flexibility for analog sensor reading.

Feature Specification

Microcontroller ATmega328P

Page 3
Unit V — I/O Interfacing with Arduino BTech Embedded System Design

Feature Specification

Architecture 8-bit AVR RISC

Clock Speed 16 MHz

Operating Voltage 5V

Digital I/O Pins 14

Analog Input Pins 8 (A0 to A7) — more than UNO

Flash Memory 32 KB

SRAM 2 KB

EEPROM 1 KB

USB Interface Mini-USB

Form Factor Much smaller than UNO; fits on breadboard

No Barrel Jack Powered via USB or Vin pin only

2.3 Arduino MEGA


The Arduino MEGA is the high-end Arduino board designed for complex projects that require a large
number of I/O pins and significant memory capacity. It is based on the ATmega2560 microcontroller,
which provides 54 digital I/O pins and 16 analog input pins — far more than the UNO or NANO. It also has
4 hardware serial ports (UARTs), making it suitable for projects that require simultaneous serial
communication with multiple devices. The MEGA is commonly used in 3D printers, CNC machines, and
large robotics platforms.

Feature Specification

Microcontroller ATmega2560

Architecture 8-bit AVR RISC

Clock Speed 16 MHz

Operating Voltage 5V

Digital I/O Pins 54 (of which 15 support PWM output)

Analog Input Pins 16 (A0 to A15)

Flash Memory 256 KB (8 KB used by bootloader)

SRAM 8 KB

EEPROM 4 KB

Hardware Serial Ports 4 UARTs

USB Interface USB-B

Best Use Case 3D printers, CNC machines, large robotics

Page 4
Unit V — I/O Interfacing with Arduino BTech Embedded System Design

2.4 Quick Comparison: UNO vs NANO vs MEGA


Feature UNO NANO MEGA

Digital I/O Pins 14 14 54

Analog Input Pins 6 8 16

PWM Pins 6 6 15

Flash Memory 32 KB 32 KB 256 KB

SRAM 2 KB 2 KB 8 KB

EEPROM 1 KB 1 KB 4 KB

Clock Speed 16 MHz 16 MHz 16 MHz

Microcontroller ATmega328P ATmega328P ATmega2560

Serial Ports (UART) 1 1 4

Size Medium Small (fits breadboard) Large

Best For Beginners, prototyping Compact/wearable projects Complex, pin-heavy projects

Page 5
Unit V — I/O Interfacing with Arduino BTech Embedded System Design

3. Functional Block of Arduino (Block Diagram)

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.

Figure 1: Arduino UNO Board — Labelled Hardware Overview

Figure 2: Arduino / ATmega328P Internal Block Diagram

3.1 Explanation of Each Block

■ Flash Program Memory (32 KB)


This is the non-volatile memory that permanently stores your Arduino sketch (program). Because it is flash
memory, the program survives even when the board is powered off. Out of 32 KB, 0.5 KB is reserved for
the Arduino bootloader — the small program that allows new code to be uploaded via USB without a
dedicated programmer.

■ SRAM — Data Memory (2 KB)


SRAM (Static Random-Access Memory) is the working memory of the microcontroller. It stores all
variables, arrays, and function call stacks while the program runs. Unlike Flash memory, SRAM is volatile
— its contents are lost when the power is removed. Since only 2 KB is available, careful memory
management is important in complex programs.

■ 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.

■ ALU — Arithmetic Logic Unit


The ALU is the mathematical core of the microcontroller. It performs all arithmetic operations (addition,
subtraction, multiplication) and logical operations (AND, OR, NOT, XOR) on 8-bit data values. Every
calculation in your Arduino program eventually gets executed by the ALU.

■ Instruction Register and Instruction Decoder


These two blocks work together to fetch and interpret each instruction from Flash memory. The Instruction
Register holds the current instruction being executed, while the Instruction Decoder determines what
operation needs to be performed and activates the correct internal pathways within the microcontroller.

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.

■ General Purpose Registers (32 × 8-bit)


The ATmega328P has 32 general-purpose 8-bit registers (R0 to R31) that are used for fast, temporary
data storage during calculations. The ALU can only operate on data held in these registers, so values are
frequently moved between registers, SRAM, and the ALU during 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.

■ SPI Unit — Serial Peripheral Interface


The SPI unit enables high-speed serial communication between the Arduino and external devices such as
SD cards, TFT displays, and other microcontrollers. SPI uses four lines — MOSI, MISO, SCK, and SS —
and is a synchronous, full-duplex protocol.

■ 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.

■ I/O Modules (Digital and Analog)


The I/O modules form the interface between the microcontroller and the external world. They manage the
digital I/O pins (D0–D13), the analog input pins (A0–A5), timer/counter units for PWM generation, and
communication peripherals (UART, SPI, I2C). Each I/O module is controlled by dedicated configuration
registers inside the ATmega328P.

■ USB to TTL Converter (ATmega16U2)


A separate ATmega16U2 chip on the Arduino UNO board acts as a USB-to-serial converter. It translates
USB signals from your computer into TTL (Transistor-Transistor Logic) serial signals that the
ATmega328P understands. This embedded converter is what allows you to upload code without any
external programmer.

Page 7
Unit V — I/O Interfacing with Arduino BTech Embedded System Design

4. Pin Functions — Analog I/O, Digital I/O, Timer, PWM

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

4.1 Power Pins


The Arduino UNO has a dedicated group of power pins that supply voltage to the board and to external
components connected to it. These pins are located at the bottom-left corner of the board.

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

4.2 Digital I/O Pins (D0 to D13)


The Arduino UNO has 14 digital input/output pins, numbered D0 through D13. Each of these pins can be
configured in software to act as either a digital input (to read a HIGH or LOW signal) or a digital output (to
output a HIGH=5V or LOW=0V signal). They operate at 5V logic and can each source or sink a maximum
of 40 mA of current.

Pin Function

D0 (RX) Serial Receive — receives serial data. Avoid using this pin as GPIO if the Serial Monitor is in use.

D1 (TX) Serial Transmit — sends serial data. Same caution as D0 applies.

D2 General digital I/O. Also serves as External Interrupt 0 (INT0) — can trigger an ISR on rising/falling/changing

D3 (~) External Interrupt 1 (INT1). Also a PWM output pin.

D4 to D8 General-purpose digital I/O pins. No special alternate functions on most boards.

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.

4.3 Analog Input Pins (A0 to A5)


The Arduino UNO has 6 analog input pins, labelled A0 through A5. These pins are connected to the
ATmega328P's built-in 10-bit Analog-to-Digital Converter (ADC). The ADC reads an analog voltage
between 0V and 5V (by default) and converts it into a digital integer value between 0 and 1023. This allows
the microcontroller to process real-world analog signals from sensors.

Conversion Formula:

Digital Value = (Analog Voltage ÷ 5.0V) × 1023

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

A0 Analog input channel 0. General-purpose analog reading.

A1 Analog input channel 1.

A2 Analog input channel 2.

A3 Analog input channel 3.

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.

4.4 Timer and PWM Pins


The ATmega328P contains three built-in hardware timer/counter modules — Timer0, Timer1, and Timer2.
These timers are used to generate precise time delays, count events, and produce PWM (Pulse Width
Modulation) output signals. PWM is a technique that simulates an analog output voltage by switching a
digital pin rapidly between HIGH and LOW at varying duty cycles.

Timer PWM Pins Primary Function

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 PWM Pins Primary Function

Timer 2 (8-bit) D3, D11 Used by tone() function for sound generation. Produces PWM on D3 and D11.

What is PWM and How Does It Work?


PWM works by turning a digital output ON and OFF very rapidly. The fraction of time the signal is ON
(HIGH) within one cycle is called the duty cycle. A higher duty cycle means more average voltage at the
output pin.

Duty Cycle Effective Voltage Effect

0% 0V Motor stopped / LED fully off

25% 1.25V Motor at 25% speed / LED dim

50% 2.5V Motor at 50% speed / LED at half brightness

75% 3.75V Motor at 75% speed / LED bright

100% 5V Motor at full speed / LED fully on

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.

4.5 SPI Pins (Serial Peripheral Interface)


SPI is a high-speed, synchronous, full-duplex serial communication protocol that uses four wires to
connect a master device (the Arduino) to one or more slave devices such as SD cards, TFT displays, and
SPI-based sensors.

Pin SPI Name Description

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.

4.6 I2C Pins (Inter-Integrated Circuit)


I2C (also written as I²C) is a two-wire serial communication protocol that allows multiple slave devices to
share the same two lines — SDA and SCL. Each device has a unique 7-bit address, so the Arduino can
communicate with many devices using just two wires. I2C is slower than SPI but requires fewer
connections, making it popular for displays, sensors, and real-time clock modules.

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

5. Introduction to ATmega328P Microcontroller

The ATmega328P is a high-performance, low-power 8-bit microcontroller manufactured by Microchip


Technology (formerly Atmel). It is the core processing unit of the Arduino UNO and Arduino NANO boards.
The '328P' variant includes the picoPower technology that reduces power consumption significantly,
making it suitable for battery-powered applications.

5.1 Architecture — AVR RISC


The ATmega328P is based on the AVR RISC (Reduced Instruction Set Computer) architecture. RISC
processors use a small, optimised set of instructions that can each be executed in a single clock cycle (for
most instructions), making the processor very fast and efficient. The ATmega328P specifically uses the
Harvard architecture, which means it has separate memory buses for program (Flash) and data (SRAM)
— allowing both to be accessed simultaneously, further improving throughput.

Feature Detail

CPU Architecture 8-bit AVR RISC, Harvard Architecture

Clock Speed Up to 20 MHz (Arduino uses 16 MHz via crystal oscillator)

Flash Program Memory 32 KB (512 bytes reserved for bootloader)

SRAM Data Memory 2 KB

EEPROM 1 KB (readable/writable during runtime)

General Purpose Registers 32 × 8-bit registers (R0 to R31)

I/O Lines 23 programmable I/O lines

ADC 10-bit, 6 multiplexed channels

Timers 2 × 8-bit, 1 × 16-bit timer/counter with compare and capture

PWM Channels 6 channels

UART 1 programmable serial USART

SPI Master/Slave Serial Peripheral Interface

I2C / TWI 2-wire Serial Interface (I2C compatible)

Operating Voltage 1.8V – 5.5V

Operating Temperature -40°C to +85°C (industrial range)

Package 28-pin DIP, 32-pin TQFP, 32-pad QFN/MLF

5.2 Memory Organisation


The ATmega328P has three distinct memory spaces, each serving a different purpose in program
execution.

Page 12
Unit V — I/O Interfacing with Arduino BTech Embedded System Design

Memory Type Size Volatile? Purpose

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

5.3 Applications of ATmega328P


• Used as the core microcontroller in Arduino UNO, Arduino NANO, and Arduino MICRO boards.
• Industrial control systems such as PLCs, relay controllers, and automation panels.
• SMPS (Switched-Mode Power Supplies) and power regulation systems.
• Digital data processing and signal acquisition from sensors.
• Embedded consumer electronics such as coffee machines and vending machines.
• Motor control systems for DC motors, stepper motors, and servo motors.
• Display units for seven-segment displays, LCD panels, and LED matrices.
• Wireless sensor nodes using SPI/I2C radio modules (NRF24L01, CC1101).

Page 13
Unit V — I/O Interfacing with Arduino BTech Embedded System Design

6. Peripheral Interfacing — LCD with Arduino

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.

6.1 Pin Description of 16×2 LCD


Pin Description

1 — VSS Ground (0V reference for the LCD).

2 — VDD Power supply (+5V).

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.

15 — LED+ Backlight anode (+). Connect to 5V through a 220Ω resistor.

16 — LED– Backlight cathode (–). Connect to GND.

6.2 Interfacing Modes

4-Bit Mode (Most Common)


In 4-bit mode, only the upper 4 data pins (D4–D7) of the LCD are connected to the Arduino. Each 8-bit
data byte is sent in two halves (nibbles) — the upper nibble first, then the lower nibble. This method uses
only 6 Arduino pins in total (RS, EN, D4, D5, D6, D7), conserving I/O pins for other components. It is the
most commonly used method in practice.

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.

I2C Mode (Most Convenient)


An I2C LCD module (typically based on the PCF8574 I/O expander) can be soldered onto the back of the
16×2 LCD, reducing the connection requirement to just 4 wires: VCC, GND, SDA, and SCL. The I2C
address is typically 0x27 or 0x3F. This is by far the most convenient method when using multiple
components on the same Arduino.

Page 14
Unit V — I/O Interfacing with Arduino BTech Embedded System Design

6.3 Arduino Code Example (4-Bit Mode)

#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

7. Seven Segment LED Display Interfacing

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).

7.1 Segment Labelling


The seven segments are positioned as follows: segment a is the top horizontal bar, b is the upper-right
vertical bar, c is the lower-right vertical bar, d is the bottom horizontal bar, e is the lower-left vertical bar, f
is the upper-left vertical bar, and g is the middle horizontal bar. By turning specific combinations of these
segments ON, any digit from 0 to 9 can be displayed.

7.2 Types — Common Anode vs Common Cathode


Type Working Principle

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

7.3 Segment Truth Table (Common Cathode)


Digit a b c d e f g

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.

7.4 Multiplexed Multi-Digit Displays

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

8. Relay Interfacing with Arduino

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.

8.1 Working Principle of a Relay


A relay consists of an electromagnetic coil and a set of mechanical contacts. When the coil is energised
(current flows through it), it generates a magnetic field that physically moves the switch contacts, changing
their state. When the coil is de-energised, a spring returns the contacts to their original position. The relay
thus provides complete electrical isolation: the low-voltage control circuit (Arduino) and the high-voltage
load circuit (230V appliance) are never electrically connected.

8.2 Relay Module Pins


Pin Description

VCC Power supply for the relay module. Typically +5V from the Arduino 5V pin.

GND Ground connection. Connected to Arduino GND.

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

8.3 Important Design Considerations


• Flyback Diode (Freewheeling Diode): When the relay coil is de-energised, the collapsing magnetic
field produces a large reverse voltage spike (back-EMF) that can damage the Arduino's output pin. A
diode (such as 1N4007) placed in reverse bias across the coil absorbs this spike and protects the
circuit. Most relay modules already have this diode built in.
• Transistor Driver: The relay coil typically requires 70–90 mA to operate, while an Arduino digital pin
can only supply 40 mA. Therefore, a transistor (such as BC547 or 2N2222) is used as a current
amplifier between the Arduino pin and the relay coil. Again, most relay modules include this transistor.
• Active-LOW Logic: Most commercial relay modules activate (turn ON) when the IN pin is driven LOW
(0V), not HIGH. Always check the module's datasheet before use.

Page 18
Unit V — I/O Interfacing with Arduino BTech Embedded System Design

9. Stepper Motor Interfacing with Arduino

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.

9.1 Types of Stepper Motors


Type Description Common Use

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

9.2 Step Sequence (Full Step, Unipolar)


To make a unipolar stepper motor rotate, the four coil outputs (IN1–IN4 on the ULN2003 driver) must be
energised in the following sequence. The motor advances one step with each transition, and reversing the
sequence reverses the rotation direction.

Step IN1 IN2 IN3 IN4 Description

Step 1 HIGH LOW LOW LOW Coil A energised

Step 2 LOW HIGH LOW LOW Coil B energised

Step 3 LOW LOW HIGH LOW Coil C energised

Step 4 LOW LOW LOW HIGH Coil D energised

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.

9.3 Speed and Position Control


The rotational speed of a stepper motor is controlled by adjusting the delay between each step — a
shorter delay produces faster rotation, and a longer delay produces slower rotation. The position is
controlled by counting the number of steps sent to the motor — since each step is a fixed 1.8° (for a
standard motor), moving 200 steps produces exactly one full revolution. This open-loop precision makes
stepper motors ideal for CNC machines, 3D printer axes, and robotic arms.

Page 19
Unit V — I/O Interfacing with Arduino BTech Embedded System Design

10. DC Motor Interfacing with Arduino

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.

10.1 Why a Motor Driver is Required


The Arduino's digital output pins can supply a maximum of only 40 mA of current, while a typical DC motor
requires 100 mA to several amperes depending on its size. Connecting a motor directly to an Arduino pin
would either fail to drive the motor or permanently damage the Arduino's output driver. Therefore, a
dedicated motor driver IC (such as the L298N or L293D) is placed between the Arduino and the motor.
The driver takes the control signals from the Arduino and provides the necessary current from an external
power supply to drive the motor.

10.2 L298N Motor Driver


The L298N is a dual H-bridge motor driver IC capable of controlling two DC motors simultaneously (or one
stepper motor). It can handle motor supply voltages up to 46V and continuous current up to 2A per
channel, with peak current of 3A.

L298N Pin Function

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.

ENB (Enable B) PWM signal to control speed of Motor B.

IN3 Direction control for Motor B — pin 1.

IN4 Direction control for Motor B — pin 2.

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.

10.3 Direction Control Logic


IN1 IN2 Motor Action

HIGH LOW Motor rotates FORWARD

LOW HIGH Motor rotates REVERSE

HIGH HIGH Motor BRAKES (short-circuit braking)

Page 20
Unit V — I/O Interfacing with Arduino BTech Embedded System Design

IN1 IN2 Motor Action

LOW LOW Motor STOPS (coast/free-spin)

10.4 Speed Control with PWM


Motor speed is controlled by applying a PWM signal to the Enable pin of the L298N. In Arduino code, this
is done using analogWrite(ENA, value), where value ranges from 0 (motor stopped) to 255 (motor at full
speed). For example, analogWrite(ENA, 128) sets the motor to approximately 50% speed.

Page 21
Unit V — I/O Interfacing with Arduino BTech Embedded System Design

11. Sensor Interfacing with Arduino

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.

11.1 Temperature Sensor — LM35


The LM35 is an analog temperature sensor that produces an output voltage linearly proportional to
temperature in Celsius. Its output is exactly 10 mV per °C. It requires no external calibration and draws
only 60 µA from the supply, making it very power-efficient. Connect its output to an Arduino analog pin
(e.g., A0). The temperature in Celsius is calculated as: Temperature (°C) = (analogRead(A0) × 5.0 /
1023.0) × 100. The LM35 can measure temperatures from –55°C to +150°C.

Specification Detail

Supply Voltage 4V – 30V

Output 10 mV/°C

Range –55°C to +150°C

Interface Analog (connect to A0–A5)

11.2 Temperature & Humidity Sensor — DHT11


The DHT11 is a digital sensor that measures both temperature and relative humidity. It uses a single-wire
proprietary protocol to send data to the Arduino. The DHT11 sends a 40-bit data packet containing
humidity (16 bits), temperature (16 bits), and a checksum (8 bits). In Arduino, it is used with the DHT.h
library. It can measure temperatures from 0°C to 50°C and humidity from 20% to 90% RH.

Specification Detail

Supply Voltage 3.3V – 5V

Temperature Range 0°C to 50°C

Humidity Range 20% to 90% RH

Interface Single-wire digital (one data pin)

Page 22
Unit V — I/O Interfacing with Arduino BTech Embedded System Design

11.3 Light Sensor — LDR (Light Dependent Resistor)


An LDR (also called a photoresistor) changes its resistance based on the intensity of light falling on it — its
resistance decreases as light intensity increases. It is always used in a voltage divider configuration with a
fixed resistor. The output of the voltage divider is connected to an Arduino analog pin. As light increases,
the voltage at the analog pin decreases (or increases, depending on the divider configuration), allowing the
Arduino to detect light levels. Common applications include automatic street lights and night-mode
detection.

Specification Detail

Type Passive analog sensor

Interface Analog pin (voltage divider)

Application Light detection, automatic lighting control

11.4 Ultrasonic Distance Sensor — HC-SR04


The HC-SR04 uses ultrasonic sound waves to measure distance. The Arduino sends a 10-microsecond
HIGH pulse to the TRIG pin, which causes the sensor to transmit 8 pulses of ultrasonic sound at 40 kHz.
The sensor then measures how long it takes for the echo to return and outputs a pulse on the ECHO pin
proportional to the distance. Distance is calculated using the formula: Distance (cm) = Duration (µs) ÷ 58.
This formula accounts for the speed of sound (343 m/s) and divides by 2 because the pulse travels to the
object and back.

Specification Detail

Supply Voltage 5V

Range 2 cm to 400 cm

Resolution 3 mm

Pins VCC, GND, TRIG (trigger), ECHO (receive)

Formula Distance (cm) = pulseIn(ECHO) ÷ 58

Page 23
Unit V — I/O Interfacing with Arduino BTech Embedded System Design

11.5 PIR Motion Sensor


A PIR (Passive Infrared) sensor detects changes in infrared radiation in its field of view. Since humans and
animals emit infrared radiation due to body heat, the PIR sensor can detect their presence and movement.
The sensor has a single digital output pin that goes HIGH when motion is detected and LOW when no
motion is present. Most PIR modules include two adjustable potentiometers — one for sensitivity
(detection range, up to 7 metres) and one for the output pulse duration (delay time). Applications include
automatic lighting, intruder alarms, and occupancy detection.

Specification Detail

Supply Voltage 5V

Output Digital HIGH/LOW

Detection Range Up to 7 metres

Cone Angle Approximately 120°

Interface Single digital input pin

Page 24
Unit V — I/O Interfacing with Arduino BTech Embedded System Design

12. Quick Revision Summary

Topic Key Points

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

You might also like