0% found this document useful (0 votes)
4 views

Sensors, Microcontrollers, ARM

The document provides an overview of various sensors and their interfacing with microcontrollers, particularly focusing on Arduino. It covers different types of sensors such as IR, PIR, thermistors, touch sensors, pH sensors, and ultrasonic sensors, detailing their working principles, applications, and example code for interfacing. Additionally, it includes circuit diagrams and specifications for each sensor type to aid in practical implementation.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Sensors, Microcontrollers, ARM

The document provides an overview of various sensors and their interfacing with microcontrollers, particularly focusing on Arduino. It covers different types of sensors such as IR, PIR, thermistors, touch sensors, pH sensors, and ultrasonic sensors, detailing their working principles, applications, and example code for interfacing. Additionally, it includes circuit diagrams and specifications for each sensor type to aid in practical implementation.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 186

Sensors,

Microcontrollers,
ARM
Dr. Jay Joshi
Sensor Interfacing
● What is Sensor Interfacing?
Connecting sensors to a microcontroller to read and process data.
● Why Use Arduino?
○ Open-source and beginner-friendly.
○ Large community support.
○ Wide range of compatible sensors.
Sensor Interfacing
● Analog Sensors:
○ Example: Temperature sensor (LM35), Light-dependent
resistor (LDR).
● Digital Sensors:
○ Example: HC-SR04 Ultrasonic Sensor, DHT11 Temperature &
Humidity Sensor.
● Communication Protocol-Based Sensors:
○ I2C: MPU6050 (Accelerometer + Gyroscope)
○ SPI: RFID Reader
○ UART: GPS Module
IR Sensor
Definition:
"An Infrared (IR) sensor is an electronic device that detects infrared radiation
emitted by objects in its field of view."

Basic Function:

● Detects heat and motion


● Converts IR radiation into an electrical signal
Working Principle of IR Sensor
● Infrared Radiation: IR sensors detect
infrared radiation, which is a type of
light invisible to the human eye. This
radiation is emitted by objects based
on their temperature.
● Components: An IR sensor typically
consists of an IR LED (emitter) and a
photodiode (receiver). The IR LED
emits infrared light, which reflects off
objects and is detected by the
photodiode.
● Signal Processing: The photodiode
converts the received infrared light
into an electrical current. This current
is then amplified by an operational
amplifier to generate a digital output.
Types of IR Sensors
● Active IR Sensors: Emit infrared light and detect the reflection. Used in
proximity sensors and obstacle detection.
● Passive IR Sensors (PIR): Detect infrared radiation emitted by objects.
Commonly used in motion detectors
IR Sensor Pinout
● VCC (Power Supply Pin): Connect to 5V on Arduino.
● GND (Ground Pin): Connect to GND on Arduino.
● OUT (Output Pin): Connect to a digital input pin on Arduino.
● Additional Pins: Some IR sensor modules include additional pins or
potentiometers for sensitivity adjustments
Working
Circuit Diagram
void setup() {
Serial.begin(9600); // Initialize serial communication

Code pinMode(2, INPUT); // Set pin 2 as input for IR sensor


pinMode(13, OUTPUT); // Set pin 13 as output for LED
}
void loop() {
int sensorValue = digitalRead(2); // Read the sensor value
if (sensorValue == 1) {
digitalWrite(13, HIGH); // Turn on LED if object detected
Serial.println("Object detected");
} else {
digitalWrite(13, LOW); // Turn off LED if no object detected
Serial.println("No object detected");
}
delay(100); // Wait for 100 milliseconds
}
Introduction to PIR Sensors
Definition: Passive Infrared (PIR) sensors detect infrared radiation emitted by warm objects,
such as humans and animals.

Key Features:

● Small and inexpensive


● Low power consumption
● Easy to use
How PIR Sensors Work
● PIR sensors consist of two slots made of pyroelectric material.
● When both slots detect the same amount of infrared radiation, the sensor
remains idle.
● Movement of a warm object causes a differential change between the
slots, triggering a high or low output signal.
Specifications of PIR Sensors
● Detection Range: Up to 7 meters
● Detection Angle: 110 degrees
● Operating Voltage: 4.5V to 12V DC
● Output Signal: 3.3V digital output
● Delay Time: Adjustable from 0.3 seconds to 5 minutes
● Operating Temperature: -15°C to +70°C
● Sensitivity: Adjustable
Pin Configuration
Pin Descriptions:

● GND: Connects to ground


● Output: Sends a 3.3V signal upon motion detection
● VCC: Connects to the power supply (4.5V to 12V DC)
Circuit Diagram
● Connect the PIR sensor's VCC to Arduino's 5V
● Connect the PIR sensor's GND to Arduino's GND
● Connect the PIR sensor's OUT to Arduino's digital pin 5
● Connect the LED's positive terminal to Arduino's digital
pin 9 through a 10kΩ resistor
● Connect the LED's negative terminal to GND
Diagram
const int led = 9;
const int sensor = 5;

Code void setup() {


pinMode(led, OUTPUT);
pinMode(sensor, INPUT);
Serial.begin(9600);
}

void loop() {
int state = digitalRead(sensor); // Read PIR sensor

if (state == HIGH) {
// Motion detected
Serial.println("Motion detected!");
digitalWrite(led, HIGH); // Turn LED ON
} else {
// No motion detected
Serial.println("No motion detected.");
digitalWrite(led, LOW); // Turn LED OFF
}

delay(1000); // Delay for stability


}
Application
● Home Security Systems: Motion-triggered alarms and cameras.
● Smart Lighting: Lights turn on/off based on occupancy.
● Energy Management: Optimize HVAC and lighting in buildings.
● Retail Analytics: Track customer movement patterns.
● Industrial Automation: Monitor movement in restricted zones.
Thermistor
● Definition: A thermistor is a type of resistor whose resistance varies
significantly with temperature.
● Types of Thermistors:
● NTC (Negative Temperature Coefficient): Resistance decreases as
temperature increases.
● PTC (Positive Temperature Coefficient): Resistance increases as
temperature increases.
● Common Uses: Thermistors are commonly used in temperature sensing
and control applications.
Working Principle
● Resistance Change: The thermistor's resistance
changes with temperature.
● Voltage Divider: The voltage divider circuit converts
the resistance change into a voltage change.
● Analog Reading: The Arduino reads the voltage and
calculates the corresponding temperature using the
Steinhart-Hart equation.
RT = VRT / (VR/R)

● Steinhart-Hart equation:
Steinhart-Hart equation
This equation provides an accurate method to calculate temperature from
resistance:

● T is the temperature in Kelvin.


● R is the resistance of the thermistor.
● A, B, and C are coefficients specific to the thermistor and provided in its
datasheet.
Simplified Beta Parameter Equation
A simplified way to estimate temperature is:

● T: Temperature in Kelvin.
● T0: Reference temperature (usually 25°C or 298.15 K).
● R: Thermistor resistance at temperature T.
● R0: Resistance at reference temperature T0.
● β: Beta constant (specific to the thermistor).
Circuit Diagram
void loop() {
VRT = analogRead(A0); //Acquisition analog value of

Code
VRT
VRT = (5.00 / 1023.00) * VRT; //Conversion to voltage
VR = VCC - VRT;
RT = VRT / (VR / R); //Resistance of RT
//These values are in the datasheet
ln = log(RT / RT0);
#define RT0 10000 // Ω
TX = (1 / ((ln / B) + (1 / T0))); //Temperature from
#define B 3977 // K
thermistor

#define VCC 5 //Supply voltage


TX = TX - 273.15; //Conversion to Celsius
#define R 10000 //R=10KΩ

Serial.print("Temperature:");
//Variables
Serial.print("\ ");
float RT, VR, ln, TX, T0, VRT;
Serial.print(TX);
delay(500);
void setup() {
}
Serial.begin(9600);
T0 = 25 + 273.15;
//Temperature T0 from datasheet
// conversion from Celsius to kelvin
}
Applications
● Smart Homes:
○ Monitor room temperature for HVAC (Heating, Ventilation, and Air Conditioning)
systems.
● Healthcare Devices:
○ Temperature monitoring in wearable health gadgets and medical instruments.
● Industrial IoT:
○ Temperature regulation in machinery and processes to ensure efficiency.
● Agriculture:
○ Soil temperature monitoring for optimized crop production.
● Automotive:
○ Engine and battery temperature monitoring in connected cars.
Touch Sensor
What is TTP223B Capacitive Touch Sensor?

● A sensor based on capacitive sensing principles.


● Detects touch or proximity using a sensing electrode and oscillator circuit.

Applications:

● Used in toys, touch switches, and other electronic devices.


Specifications
● Power Supply: 2 to 5.5V DC.
● Response Time:
○ Touch Mode: 60ms.
○ Low Power Mode: 220ms.
● Output:
○ High (VOH): 0.8V VCC.
○ Low (VOL): 0.3V VCC.
Pinout Description
VCC: Power supply pin.

SIG: Signal output pin (provides digital output when touch is detected).

GND: Ground connection.


Working Principle
● When a conductive material (e.g., finger) touches the sensor, it changes
the capacitance.
● The oscillator circuit detects this change and generates a digital output
signal.
Hardware Connection
#define ctsPin 2
int ledPin = 13; // pin for the LED

Code void setup() {


Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(ctsPin, INPUT);
}
void loop() {
int ctsValue = digitalRead(ctsPin);
if (ctsValue==HIGH){
digitalWrite(ledPin, HIGH);
Serial.println("TOUCHED");
}
else{
digitalWrite(ledPin,LOW);
Serial.println("not touched");
}
delay(500);
}
Application
Home Automation:

● Touch-controlled switches for lights, fans, and smart appliances.

Wearable Devices:

● Capacitive touch sensors for user interaction in smartwatches or fitness bands.

Healthcare:

● Touch-enabled medical devices, such as patient monitoring systems.

Security Systems:

● Biometric touchpads for doors, safes, and lockers.


PH sensor
● pH scale measures acidity/basicity of a liquid.
● Ranges from 0 to 14:
○ 0-6.9: Acidic
○ 7: Neutral
○ 7.1-14: Basic (Alkaline)
● pH plays a critical role in:
○ Environmental monitoring
○ Agriculture
○ Wastewater treatment
○ Swimming pool maintenance
Gravity Analog pH Sensor
● Measures hydrogen ion concentration.
● Outputs voltage corresponding to pH.
● Technical Features:
○ Supply Voltage: 3.3V - 5.5V
○ Detection Range: 0 - 14 pH
○ Accuracy: ±0.1 @ 25°C
○ Operating Temp: 5°C - 60°C
How the pH Sensor Works
● pH electrode has a glass membrane filled with buffer solution.
● Dipping into a solution causes ion exchange, generating potential.
● The Nernst Equation converts potential into pH value:
E = E0 - 2.3 (RT/nF) ln Q

Where
Q= Reaction coefficient
E = mV output from the electrode
E0 = Zero offset for the electrode
R = Ideal gas constant= 8.314 J/mol-K
T = Temperature in ºK
F = Faraday constant = 95,484.56 C/mol
n = Ionic Charge
pH Signal Conversion Board
● Converts analog signals from pH electrode to readable voltage.
● Technical Features:
○ Supply Voltage: 3.3V - 5.5V
○ BNC Probe Connector for pH electrode
○ High Accuracy: ±0.1 @ 25°C
○ Detection Range: 0 - 14 pH
○ Temperature Output: For compensation
● Pin Description:
○ V+: 5V DC input
○ G: Ground pin
○ Po: pH analog output
○ Do: 3.3V DC output
○ To: Temperature output
Circuit Diagram

pH Sensor → Arduino A0
#define SensorPin A0 // pH sensor connected to analog pin A0
void setup() {
Serial.begin(9600);
Serial.println("Basic pH Sensor Reading Started");
}

void loop() {
int sensorValue = analogRead(SensorPin); // Read analog value from pH sensor
float voltage = sensorValue * (5.0 / 1023.0); // Convert analog value to
voltage
float pH = 3.5 * voltage; // Basic conversion from voltage to pH value
Serial.print("Voltage: ");
Serial.print(voltage, 2);
Serial.print(" V | pH Value: ");
Serial.println(pH, 2);
delay(1000); // Delay for 1 second between readings
}
Basic Code Overview
● Analog Reading:
Reads raw data from the pH sensor.
● Voltage Conversion:
Converts the analog reading to a voltage (0-5V).
● pH Calculation:
Applies a simple formula pH = 3.5 * voltage to estimate the pH
value. (You can calibrate this based on your sensor.)
● Serial Output:
Displays the voltage and pH value on the Serial Monitor every
second.
Testing PH meter
Tested with:
● Pure Water: pH ~7.0
● Lemon Juice: pH ~2.0
● Soap Solution: pH ~10.0
Application
● Smart Agriculture:
○ Real-time soil pH monitoring.
○ Optimizes irrigation and fertilization.
● Water Quality Monitoring:
○ IoT-enabled water bodies monitoring.
○ Tracks pH in rivers, lakes, and aquariums.
● Industrial IoT (IIoT):
○ Monitors pH in chemical and pharmaceutical industries.
○ Ensures compliance with safety standards.
● Smart Aquaculture:
○ Maintains optimal pH levels in fish farms.
○ Integrates with IoT platforms for remote monitoring.
● Environmental Monitoring:
○ Tracks pH levels in soil and water ecosystems.
○ Helps in pollution control and analysis.
● Home Automation:
○ Monitors pH in swimming pools and home aquariums.
○ Sends alerts when pH levels go out of range.
HC-SR04 Ultrasonic Sensor
● The HC-SR04 is an affordable and precise ultrasonic sensor widely used in
various applications.
● It measures distances by emitting ultrasonic waves and calculating the
time it takes for the echo to return.
Understanding the HC-SR04 Sensor
Features:
● Operating Voltage: 5V DC
● Measuring Range: 2cm to 400cm
● Accuracy: ±3mm
Pin Configuration:
● VCC: Power supply
● Trig: Trigger input
● Echo: Echo output
● GND: Ground
How the HC-SR04 Works
Operating Principle:
● The sensor emits an ultrasonic pulse via the Trig pin.
● This pulse reflects off an object and returns to the sensor.
● The Echo pin outputs the time duration the pulse took to
return.
● Distance is calculated using the formula:
○ Distance = (Time × Speed of Sound) / 2
○ Time in μs
○ Speed of Sound: Sound travels at approximately 343
meters per second in air, which is 0.034 cm/μs.
How HC-SR04 Works
Timing Diagram
Wiring Diagram
Connection
Code
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);

const int trigPin = 11; digitalWrite(trigPin, HIGH);

const int echoPin = 12; delayMicroseconds(10);

long duration; digitalWrite(trigPin, LOW);

int distance;
duration = pulseIn(echoPin, HIGH);

void setup() { distance = duration * 0.034 / 2;

pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT); Serial.print("Distance: ");

Serial.begin(9600); Serial.print(distance);

} Serial.println(" cm");
delay(500);
}
Code Overview
Key Steps in the Code:
● Initialize Trig and Echo pins.
● Send a 10µs pulse to the Trig pin to initiate
measurement.
● Read the time duration from the Echo pin.
● Calculate distance using the time duration.
● Display the distance on the Serial Monitor.
Application
● Smart Parking Systems:
○ Detect vehicle presence in parking spots.
○ Send data to cloud platforms for real-time monitoring.
● Smart Waste Management:
○ Monitor bin fill levels.
○ Optimize collection routes using IoT networks.
● Home Automation:
○ Implement touchless faucets or smart doors.
○ Integrate with home automation systems.
● Industrial Automation:
○ Track object distances on conveyor belts.
○ Real-time monitoring via IoT dashboards.
● Agriculture:
○ Measure water levels in tanks or reservoirs.
○ Transmit data to centralized control systems.
● Security Systems:
○ Motion detection in restricted areas.
○ Alert systems via IoT networks.
● Robotics:
○ Obstacle detection and avoidance.
○ Data sharing with IoT-enabled control units.
Introduction to DHT11 Sensor
Overview:
● The DHT11 is a basic, ultra-low-cost digital
temperature and humidity sensor.
● It uses a capacitive humidity sensor and a
thermistor to measure the surrounding air.
● It provides calibrated digital output and
operates via a single-wire protocol.
Key Features
● Operating Voltage: 3.3V - 5V
● Temperature Range: 0°C to 50°C (±2°C accuracy)
● Humidity Range: 20% - 90% RH (±5% accuracy)
● Sampling Rate: 1 reading per second
● Interface: Single-wire digital output
● Low power consumption
Pin Configuration of DHT11
Microcontroller Communication with DHT11
● The DHT11 sensor communicates with a microcontroller using a
single-wire digital signal.
● It requires a start signal from the microcontroller to initiate data
transfer.
● The sensor responds by sending 40 bits of data (humidity, temperature,
checksum).
DHT11 Communication Protocol
Start Signal:

● The microcontroller pulls the data pin LOW for at least 18ms to wake up the sensor.
● Then, it pulls the data pin HIGH for 20-40µs and waits for the response.

Response Signal:

● The sensor pulls the line LOW for 54µs and then HIGH for 80µs to indicate readiness.
Data Transmission Format
The DHT11 sends 40 bits of data in the following format:
● 8 bits → Humidity Integer
● 8 bits → Humidity Decimal
● 8 bits → Temperature Integer
● 8 bits → Temperature Decimal
● 8 bits → Checksum (Error detection)
The microcontroller reads the high and low pulse
durations to interpret the data bits.
Timing Diagram
The data signal consists of pulses representing 0s and 1s:

● 0 bit → 24µs HIGH pulse


● 1 bit → 70µs HIGH pulse

The microcontroller measures the pulse duration to determine if it is 0 or 1.


Wiring diagram
#include <dht11.h>
#define DHT11PIN 4

Code dht11 DHT11;

void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println();
int chk = DHT11.read(DHT11PIN);
Serial.print("Humidity (%): ");
Serial.println((float)DHT11.humidity, 2);
Serial.print("Temperature (C): ");
Serial.println((float)DHT11.temperature, 2);
delay(2000);
}
Applications of DHT11 Communication
● Smart Agriculture: Optimize soil and air conditions
● Home Automation: Control HVAC systems
efficiently
● Industrial Monitoring: Maintain ideal working
conditions
● Weather Stations: Real-time environmental tracking
● Healthcare: Monitor room climate in sensitive
environments
Grove Gas Sensor (MQ2)
What is MQ2 Sensor?
The Grove - Gas Sensor (MQ2) is a gas detection module used to sense gases like
LPG, methane, alcohol, hydrogen, and smoke in the air.

Key Features:

● Detects flammable and hazardous gases


● Fast response time and high sensitivity
● Provides both analog and digital output
● Wide operating voltage range (compatible with Arduino)
Working Principle
● The sensor uses a heated
SnO₂ (tin dioxide) surface
that changes resistance
when exposed to gas.
● The higher the gas
concentration, the lower
the resistance, generating
an analog voltage output.
Gas Sensor Pinout
● VCC (Power Supply Pin): Connect to
5V on Arduino.
● GND (Ground Pin): Connect to GND
on Arduino.
● A0 (Analog Output Pin): Connect to
an analog input pin on Arduino.
● D0 (Digital Output Pin): Connect to
a digital input pin on Arduino
(optional).
Circuit Diagram
#define MQ2_D0 8 // Digital output from MQ2 sensor
#define LED 13 // Built-in LED on Arduino

Code void setup() {


pinMode(MQ2_D0, INPUT); // Set MQ2 digital pin as input
pinMode(LED, OUTPUT); // Set LED as output
Serial.begin(9600); // Start serial communication
}
void loop() {
int smokeDetected = digitalRead(MQ2_D0); // Read digital output

if (smokeDetected == LOW) { // LOW means gas/smoke detected


Serial.println("Smoke detected!");
digitalWrite(LED, HIGH); // Turn ON LED
} else {
Serial.println("No smoke detected.");
digitalWrite(LED, LOW); // Turn OFF LED
}
delay(1000); // Wait for 1 second before next reading
}
const int MQ2_Pin = A0; // MQ2 analog output pin
const int ledPin = 9; // LED to indicate gas detection

Code int gasValue = 0;

void setup() {
// Variable to store gas sensor reading

pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
gasValue = analogRead(MQ2_Pin); // Read gas sensor value
Serial.print("Gas Sensor Value: ");
Serial.println(gasValue);

if (gasValue > 400) { // Threshold for gas detection


Serial.println("Gas Detected! Warning!");
digitalWrite(ledPin, HIGH); // Turn LED ON
} else {
digitalWrite(ledPin, LOW); // Turn LED OFF
}
delay(1000); // Delay to stabilize readings
}
Applications
Smart Home Safety: Gas leakage detection in kitchens.

Industrial Monitoring: Prevents hazardous gas buildup in factories.

Smart Cities: Monitors air quality and pollution levels.

Healthcare: Ensures clean air in hospitals.


ADXL335 Accelerometer Module
Definition: The ADXL335 is a small, thin, low-power, complete 3-axis accelerometer with
signal-conditioned voltage outputs.

Measurement Range: Capable of measuring acceleration up to ±3 g along the X, Y, and Z axes.

Applications: Used in tilt sensing, motion detection, and vibration monitoring.


Key Features and Specifications
● Supply Voltage: Operates between 2.8V to 3.6V.
● Current Consumption: Approximately 320 µA.
● Sensitivity: 300 mV/g.
● Bandwidth: Selectable from 3 Hz to 5 kHz.
● Operating Temperature: -40°C to +85°C.
● Output Type: Analog voltage proportional to acceleration.
How Accelerometers Work
Basic Structure:
● Comprises fixed plates and moving plates (mass).
● Acceleration causes deflection of the moving mass.
Working Principle:
● Deflection unbalances a differential capacitor.
● Results in an output voltage proportional to the acceleration.
● Phase-sensitive demodulation determines acceleration magnitude and direction.
Pin Configuration and Descriptions
Pin Layout:
● VCC: Connect to 3.3V power supply.
● GND: Ground connection.
● X_OUT: Analog output for X-axis.
● Y_OUT: Analog output for Y-axis.
● Z_OUT: Analog output for Z-axis.
Note: Outputs analog voltages
proportional to acceleration; interface
with microcontroller ADC pins.
Interfacing with Microcontrollers
Analog Signal Reading: Connect X_OUT, Y_OUT, and Z_OUT to ADC pins of a microcontroller (e.g., A1, A2, A3).

Power Supply: Ensure a stable 3.3V supply to VCC.


int xPin = A1; // X_OUT to A1
int yPin = A2; // Y_OUT to A2

Code
int zPin = A3; // Z_OUT to A3

void setup() {
Serial.begin(9600);
}

void loop() {
int xVal = analogRead(xPin);
int yVal = analogRead(yPin);
int zVal = analogRead(zPin);
// Convert ADC values to voltage
float xVoltage = (xVal / 1024.0) * 3.3;
float yVoltage = (yVal / 1024.0) * 3.3;
float zVoltage = (zVal / 1024.0) * 3.3;

// Output the results


Serial.print("X Voltage: "); Serial.println(xVoltage);
Serial.print("Y Voltage: "); Serial.println(yVoltage);
Serial.print("Z Voltage: "); Serial.println(zVoltage);

delay(500);
}
Application
● Vehicle Tracking & Anti-Theft: Detects sudden acceleration, collisions,
or unauthorized movement.
● Smart Home Security: Senses vibrations or door/window movements.
● Wearable Devices: Monitors steps, activity levels, and orientation.
● Industrial Monitoring: Tracks machinery vibrations for predictive
maintenance.
● Gaming & VR: Enhances interactivity through motion sensing.
Soil Moisture Sensors
Definition: Devices that measure the water content in soil.

Importance: Crucial for agriculture, gardening, and environmental monitoring to ensure


optimal soil conditions.
Components of Soil Moisture Sensor
● Two conducting plates acting as probes.
● LM393 comparator IC.
● Power and output indicator LEDs.
Components of Soil Moisture Sensor
● Two conducting plates acting as probes.
● LM393 comparator IC.
● Power and output indicator LEDs.
Operating Principle
● The sensor functions as a variable resistor.
● Increased soil moisture decreases resistance between the probes,
enhancing conductivity.
Working Principle
Voltage Divider Network:

● One probe connects to a +5V supply through a 10kΩ resistor; the other connects to ground.
● Acts as a voltage divider; output voltage varies with soil moisture levels.

Output Behavior:

● Dry soil (low moisture): Higher resistance, output voltage near 5V.
● Wet soil (high moisture): Lower resistance, output voltage decreases.
Specifications
Operating Voltage: 3.3V to 5V DC.

Operating Current: Approximately 15mA.

Output Types:

● Analog voltage: Continuous values representing moisture levels.


● Digital signal: Threshold-based output indicating wet or dry conditions.

Indicators:

● Power LED: Shows sensor is powered.


● Output LED: Indicates moisture detection status.
Interfacing with Arduino
Analog output to Arduino analog input pin (e.g., A1).

VCC to 3.3V or 5V on Arduino.

GND to Arduino ground.


Code
const int sensor_pin = A1; // Soil moisture sensor output pin

void setup() {
Serial.begin(9600); // Initialize serial communication
}

void loop() {
int sensor_value = analogRead(sensor_pin); // Read analog value
float moisture_percentage = 100 - ((sensor_value / 1023.0) * 100);
Serial.print("Moisture Percentage = ");
Serial.print(moisture_percentage);
Serial.println("%");
delay(1000); // Wait for 1 second
}
Applications
● Smart Irrigation Systems: Automates watering based on soil moisture
levels.
● Home Gardening: Remote monitoring and alerts for potted plants and
gardens.
● Precision Agriculture: Optimizes water usage across large fields.
● Greenhouse Monitoring: Maintains ideal soil conditions for different
crops.
● Environmental Monitoring: Tracks soil health in forests and wetlands.
Capacitive Proximity Sensor
What is a Capacitive Proximity Sensor?

● A sensor that detects the presence or absence of solid or liquid objects without physical
contact.
● Works by emitting an electrical field and detecting changes in capacitance caused by
nearby objects.

Applications:

● Used in proximity detection, and non-contact sensing.


Working Principle
Capacitance Change:

● The sensor emits an electrical field.


● When an object enters the field, it alters the capacitance.

Signal Conversion:

● The change in capacitance is converted into an electrical signal, which can be


processed by the Microcontroller.
Sensor Diagram
Circuit Diagram
const int Pin=2;

Code
void setup(){
pinMode(Pin, INPUT);
Serial.begin(9600);
}
void loop(){
int sensorValue = digitalRead(Pin);
if(sensorValue==LOW){
Serial.println("no Object");
delay(500);
}
else{
Serial.println("Object Detected");
delay(500);
}
}
Applications
● Smart Homes:
○ Automatic lighting systems triggered by proximity.
○ Touchless control of appliances like fans and TVs.
● Healthcare:
○ Liquid level monitoring in medical devices like IV drips.
○ Proximity-based patient monitoring systems.
● Industrial IoT:
○ Object detection in conveyor belt systems.
○ Monitoring material levels in storage tanks.
● Retail:
○ Smart shelving to detect product placement or removal.
GPS Module
● Global Positioning System
(GPS): GPS is a satellite-based
navigation system that provides
location, time, and speed
information.
● NEO-6M GPS Module: This
module receives signals from
GPS satellites and calculates the
position, speed, and time.
● Data Format: The module
outputs data in standard NMEA
sentences, which include
information like latitude,
longitude, altitude, and time.
How Does It Work?
● Receives signals from multiple GPS satellites.
● Calculates position using triangulation.
● Outputs latitude, longitude, altitude, speed, and time data.
● Sends data via UART (TX/RX) or I2C communication to
microcontrollers like Arduino.
Circuit Diagram
Sample Code:
#include <SoftwareSerial.h>

SoftwareSerial ss(4, 3); // RX, TX

void setup() {
Serial.begin(9600);
ss.begin(9600);
}

void loop() {
while (ss.available() > 0) {
byte gpsData = ss.read();
Serial.write(gpsData);
}
}
Output on Serial Monitor
What are NMEA Sentences?
● Standard Data Format: NMEA sentences are a standard data format
used by GPS manufacturers to transmit data.
● Structure: Each NMEA sentence starts with a dollar sign ($) and ends
with a carriage return and line feed.
● Types of Sentences: Different types of NMEA sentences provide
various pieces of information such as position, time, and speed.
Common NMEA Sentences
● $GPGGA: Provides 3D location and accuracy data.
● $GPGLL: Provides geographic position (latitude and longitude).
● $GPGSA: Provides GPS DOP (Dilution of Precision) and active
satellites.
● $GPGSV: Provides information about satellites in view.
● $GPRMC: Provides recommended minimum specific GPS/Transit
data.
● $GPVTG: Provides track made good and ground speed.
Structure of NMEA Sentences
● Example Sentence:
$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47
● Components:
● $GPGGA: Sentence identifier.
● 123519: Fix taken at 12:35:19 UTC.
● 4807.038,N: Latitude 48°07.038' N.
● 01131.000,E: Longitude 11°31.000' E.
● 1: Fix quality (0 = invalid, 1 = GPS fix, 2 = DGPS fix).
● 08: Number of satellites being tracked.
● 0.9: Horizontal dilution of position.
● 545.4,M: Altitude, Meters, above mean sea level.
● 46.9,M: Height of geoid (mean sea level) above WGS84 ellipsoid.
● (empty field): Time in seconds since last DGPS update.
● (empty field): DGPS station ID number.
● *47: Checksum data.
Parsing NMEA Sentences
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
SoftwareSerial ss(4, 3); // RX, TX
TinyGPSPlus gps;
void setup() {
Serial.begin(9600);
ss.begin(9600);
}
void loop() {
while (ss.available() > 0) {
gps.encode(ss.read());
}

if (gps.location.isUpdated()) {
Serial.print("Latitude: ");
Serial.println(gps.location.lat(), 6);
Serial.print("Longitude: ");
Serial.println(gps.location.lng(), 6);
}
}
Applications of IoT with GPS
● Smart Vehicle Tracking – Real-time car/bike tracking using IoT & Google Maps.
● Logistics & Fleet Management – Monitors trucks and delivery routes.
● Drones & UAV Navigation – Autonomous drone control using GPS data.
● Healthcare & Personal Safety – GPS-enabled wearables for elderly or patient
tracking.
● Smart Agriculture – Precision farming using GPS location tracking for tractors &
equipment.
● Geofencing & Security – Alerts when a device/person exits a predefined zone.
Heartbeat Sensor
● Photoplethysmogram (PPG): The
sensor detects subtle changes in blood
flow through the skin caused by the
expansion and contraction of blood
vessels with each heartbeat.
● Optical Method: A light source (usually
an LED) emits light that penetrates the
skin and blood vessels. A
photodetector measures the amount
of light absorbed or reflected back.
● Signal Processing: The photodetector
converts the light into an electrical
signal, which is then amplified and
filtered to calculate the heart rate.
Heartbeat Sensor Pinout
● VCC (Power Supply Pin): Connect to 5V on Arduino.
● GND (Ground Pin): Connect to GND on Arduino.
● Signal (Analog Output Pin): Connect to an analog input pin on Arduino (e.g., A0).
Circuit Diagram
const int pulsePin = A0; // Pulse sensor connected to A0
int sensorValue = 0;

Code
int threshold = 550; // Adjust based on sensor sensitivity
unsigned long previousTime = 0; // Stores the last beat time
float bpm = 0; // Calculated BPM

void setup() {
Serial.begin(9600);
Serial.println("Heart Rate Monitor Initialized...");
}

void loop() {
sensorValue = analogRead(pulsePin); // Read pulse sensor value
if (sensorValue > threshold) { // If a heartbeat is detected
unsigned long currentTime = millis(); // Get current time
if (currentTime - previousTime > 300) { // Debounce to avoid false beats
bpm = (60000.0 / (currentTime - previousTime)); // Calculate BPM
previousTime = currentTime; // Update last beat time
Serial.print("BPM: ");
Serial.println(bpm); // Print BPM to Serial Monitor
}
}
}
Applications
● Remote Patient Monitoring – Doctors can monitor patient heart rate remotely.
● Fitness Wearables – Smartwatches & fitness bands track heart rate in real-time.
● Cardiac Emergency Alert System – Sends an alert when BPM exceeds normal
limits.
● IoT Health Cloud – Stores patient data securely for analysis & AI-based health
predictions.
● Biomedical Research – Used in clinical studies for heart-related conditions.
Why Microcontroller?

Purpose ?
Microcontroller
• Microcontrollers are important part of
Embedded systems
• To understand Structure & working of
Microcontrollers
• For Designing good Embedded system
complete understanding of
microcontrollers required
Microcontroller
Integrated chip that typically contains integrated CPU,
memory (RAM ROM), I/O ports on a single Chip.

System on a single Chip

Designed to execute a specific task to control a single


system

Smaller & Specified (design cost)


Differs from Microprocessor
general-purpose chip
Used to design multi purpose computers or devices
Require Multiple chips to to handle various tasks
General Purpose Microprocessors vs. Microcontrollers
● General Purpose Microprocessors

● Microcontrollers
CPU RAM ROM
Serial
Timer I/O
Port
Microprocessor vs. Microcontroller
Microprocessor Microcontroller
● CPU is stand-alone, RAM, ROM, I/O, ● CPU, RAM, ROM, I/O and timer are all
timer are separate on a single chip

● Designer can decide on the amount of ● Fix amount of on-chip ROM, RAM, I/O
ports
ROM, RAM and I/O ports.

● Not Expansive
● Expansive
● For applications in which cost, power
● Versatility and space are critical

● General-purpose ● Single-purpose
Microcontrollers

A microcontroller
interfaces to
external devices
with a minimum of
external
components
Most common microcontrollers
● 8-bit microcontrollers

○ AVR

○ PIC

○ HCS12

○ 8051

● 32-bit microcontrollers

○ ARM

○ PIC32
Intel 51 family (8-bit MC)
● 8051

○ 40 pin DIP

○ 4K ROM

○ 128 byte Data Memory

○ 32 I/O lines

○ Two 16-bit Timer

○ 5 Interrupt

○ UART

○ Support external 60K program memory

○ Support external 64K data memory


Pin Description of the 8051
● 8051 family members (e.g., 8751, 89C51, 89C52, DS89C4x0)

○ Have 40 pins dedicated for various functions such as I/O, RD, WR, address, data, and interrupts.

○ Come in different packages, such as

■ DIP(dual in-line package),

■ QFP(quad flat package), and


■ LLC(leadless chip carrier)

● Some companies provide a 20-pin version of the 8051 with a reduced number of I/O
ports for less demanding applications
Pin Diagram of the 8051
XTAL1 and XTAL2
● The 8051 has an on-chip oscillator but requires an external clock to run it

○ A quartz crystal oscillator is connected to inputs XTAL1 (pin19) and XTAL2 (pin18)

○ The quartz crystal oscillator also needs two capacitors of 30 pF value


XTAL1 and XTAL2 …..
● If you use a frequency source other than a crystal oscillator, such as a TTL oscillator:

○ It will be connected to XTAL1

○ XTAL2 is left unconnected


XTAL1 and XTAL2 …..
● The speed of 8051 refers to the maximum oscillator frequency connected to
XTAL.

● We can observe the frequency on the XTAL2 pin using the oscilloscope.
RST
● RESET pin is an input and is active high (normally low)
● Upon applying a high pulse to this pin, the microcontroller will reset and
terminate all activities
● This is often referred to as a power-on reset
● Activating a power-on reset will cause all values in the registers to be lost
RST
● In order for the RESET input to be effective, it must have a minimum duration
of 2 machine cycles.

● In other words, the high pulse must be high for a minimum of 2 machine
cycles before it is allowed to go low.
EA’
● EA’, “external access’’, is an input pin and must be connected to
Vcc or GND

● The 8051 family members all come with on-chip ROM to store
programs and also have an external code and data memory.

● Normally EA pin is connected to Vcc

● EA pin must be connected to GND to indicate that the code or


data is stored externally.
8051 Memory Structure

External

External
60
K
64 64
K K
SFR
EXT INT 4K
128
EA = 0 EA = 1
Program Memory Data Memory
PSEN’ and ALE
● PSEN, “program store enable’’, is an output pin

● This pin is connected to the OE pin of the external memory.

● For External Code Memory, PSEN’ = 0

● For External Data Memory, PSEN’ = 1

● ALE pin is used for demultiplexing the address and data.


I/O Port Pins
● The four 8-bit I/O ports P0, P1, P2 and
P3 each uses 8 pins.

● All the ports upon RESET are


configured as output, ready to be used
as input ports by the external device.
Port 0
● Port 0 is also designated as AD0-AD7.

● When connecting an 8051 to an external memory, port 0 provides


both address and data.

● The 8051 multiplexes address and data through port 0 to save pins.

● ALE indicates if P0 has address or data.

○ When ALE=0, it provides data D0-D7

○ When ALE=1, it has address A0-A7


Port 1 and Port 2
● In 8051-based systems with no external memory
connection:

○ Both P1 and P2 are used as simple I/O.

● In 8051-based systems with external memory connections:

○ Port 2 must be used along with P0 to provide the 16-bit address for the
external memory.

○ P0 provides the lower 8 bits via A0 – A7.

○ P2 is used for the upper 8 bits of the 16-bit address, designated as A8 – A15,
and it cannot be used for I/O.
Port 3
● Port 3 can be used as input or output.

● Port 3 has the additional function of


providing some extremely important
signals
Pin Description Summary
PIN TYPE NAME AND FUNCTION
Vss I Ground: 0 V reference.
Vcc I Power Supply: This is the power supply voltage for normal, idle, and
power-down operation.
P0.0 - P0.7 I/O Port 0: Port 0 is an open-drain, bi-directional I/O port. Port 0 is also the
multiplexed low-order address and data bus during accesses to external
program and data memory.
P1.0 - P1.7 I/O Port 1: Port I is an 8-bit bi-directional I/O port.

P2.0 - P2.7 I/O Port 2: Port 2 is an 8-bit bidirectional I/O. Port 2 emits the high order address
byte during fetches from external program memory and during accesses to
external data memory that use 16 bit addresses.
P3.0 - P3.7 I/O Port 3: Port 3 is an 8 bit bidirectional I/O port. Port 3 also serves special
features as explained.
Pin Description Summary
PIN TYPE NAME AND FUNCTION
RST I Reset: A high on this pin for two machine cycles while the oscillator is running,
resets the device.
ALE O Address Latch Enable: Output pulse for latching the low byte of the address
during an access to external memory.
PSEN* O Program Store Enable: The read strobe to external program memory. When
executing code from the external program memory, PSEN* is activated twice
each machine cycle, except that two PSEN* activations are skipped during each
access to external data memory.
EA*/VPP I External Access Enable/Programming Supply Voltage: EA* must be externally
held low to enable the device to fetch code from external program memory
locations. If EA* Is held high, the device executes from internal program
memory. This pin also receives the programming supply voltage Vpp during
Flash programming. (applies for 89c5x MCU's)
General Block Diagram of 8051
Interrupt 4K 128 B Timer 0
Control ROM Timer 1
RAM

CPU

Bus Serial
OSC Control
4 I/O Ports
Port

TXD RXD
P0 P1 P2 P3
SECTION 2.1: INSIDE THE 8051
• Registers

Figure 2–1a
Some 8-bit Registers of the 8051
SECTION 2.1: INSIDE THE 8051
• Registers

Figure 2–1b Some 8051 16-bit Registers


SECTION 2.1: INSIDE THE 8051
• most widely used registers are A, B, R0, R1,
R2, R3, R4, R5, R6, R7, DPTR and PC
• all registers are 8-bits, except DPTR and the
program counter which are 16 bit
• register A is used for all arithmetic and logic
instructions
• simple instructions MOV and ADD
SECTION 2.4: THE PROGRAM COUNTER AND ROM
SPACE IN THE 8051
• Program counter in the 8051
– 16 bits wide
– can access program addresses 0000 to FFFFH
– total of 64K bytes of code
SECTION 2.4: THE PROGRAM COUNTER AND ROM
SPACE IN THE 8051
• Where the 8051 wakes up when it is powered
up:
– wakes up at memory address 0000 when it is
powered up
– first opcode must be stored at ROM address
0000H
SECTION 2.4: THE PROGRAM COUNTER AND ROM
SPACE IN THE 8051
• Placing code in program ROM
– the opcode and operand are placed in ROM
locations starting at memory 0000
SECTION 2.4: THE PROGRAM COUNTER AND ROM
SPACE IN THE 8051

• ROM memory map in the 8051 family

Figure 2–3 8051 On-Chip ROM Address Range


Program Status Word [PSW]

C AC F0 RS1 RS0 OV F1 P
Carry Parity
Auxiliary Carry User Flag 1
User Flag 0 Register Bank Select Overflow
128 Byte RAM
• There are 128 bytes of RAM in the 8051.
– Assigned addresses 00 to 7FH General Purpose
Area
• The 128 bytes are divided into 3 different
groups as follows: BIT Addressable
1. A total of 32 bytes from locations 00 to 1F hex are 128Area
BYTE
set aside for register banks and the stack. INTERNAL
Reg Bank 3
RAM
2. A total of 16 bytes from locations 20H to 2FH are
set aside for bit-addressable read/write memory. Register
Reg Bank 2
3. A total of 80 bytes from locations 30H to 7FH are Banks
Reg Bank 1
used for read and write storage, called scratch Reg Bank 0
pad.
8051 RAM with addresses
8051 Register Bank Structure

Bank 3 R0 R1 R2 R3 R4 R5 R6 R7

Bank 2 R0 R1 R2 R3 R4 R5 R6 R7

Bank 1 R0 R1 R2 R3 R4 R5 R6 R7

Bank 0 R0 R1 R2 R3 R4 R5 R6 R7
8051 Register Banks with address
SECTION 2.7: 8051 REGISTER BANKS AND STACK
• How to switch register banks

Table 2–2 PSW Bits Bank Selection


8051 Stack
• The stack is a section of RAM used by the CPU to store
information temporarily.
– This information could be data or an address

• The register used to access the stack is called the SP (stack


pointer) register
– The stack pointer in the 8051 is only 8 bit wide, which means that it
can take value of 00 to FFH
– When the 8051 is powered up, the SP register contains value 07
– RAM location 08 is the first location begin used for the stack by the
8051
8051 Stack
• The storing of a CPU register in the stack is called a PUSH
– SP is pointing to the last used location of the stack
– As we push data onto the stack, the SP is incremented by one and
store the value
– This is different from many microprocessors

• Loading the contents of the stack back into a CPU register is


called a POP
– With every pop, the top byte of the stack is copied to the register
specified by the instruction and the stack pointer is decremented
once
AVR Microcontroller
AVR stand for?

Advanced Virtual RISC,


the founders are Alf Egil Bogen Vegard Wollan RISC

AVR architecture was conceived by two students at


Norwegian Institute of Technology (NTH) and further
refined and developed at Atmel Norway, the Atmel
company founded by the two chip architects.
AVR Microcontroller
AVR Micro controllers is Family of
RISC Microcontrollers from Atmel.

There are multiple architectures

RISC (Reduced Instruction Set Computer)


CISC (Complex Instruction Set Computer)
RISC Microcontroller
Reduced Introduction Set Computer

Till 1980 Trend was to build increasingly complex


CPUs with complex set of instructions like (CISC)

(RISC)
Instruction execute in single cycle

“Architecture which reduces the chip complexity by simpler


processing instructions”.

RISC architecture CPUs capable of executing only a very limited


RISC Microcontroller
Reduced Instruction Set Computers Advantages

• Fast Execution of Instructions due to simple instructions for


CPU.
• RISC chips require fewer transistors, which makes them
cheaper to design and produce.
• Emphasis on software
• Single-clock,reduced instruction only
• Register to register: “LOAD" and "STORE“
are independent instructions
• Spends more transistors on memory registers
AVR Microcontroller
The AVR is a Harvard architecture CPU.

Harvard Architecture

• Computer architectures that used physically separate storage


and signal pathways for their instructions and data.

• CPU can read both an instruction and data from memory at the
same time that makes it faster.

von Neumann architecture


CPU can Read an instruction or data from/to the memory.

Read, Write can`t occur at the same time due to same memory and
signal pathway for data and instructions.
AVR internal architecture
Pin configuration of ATmeag32
•ATMEGA32 has four ports, PORTA,
PORTB, PORTC and PORTD, each one
having 8 pins.
•The remaining 8 are mostly consumed by
supply pins (VCC, AVCC), ground (GND),
reset, XTAL pins, and other minor stuffs.
•Every MCU has an internal oscillator
which determines its frequency of
oscillator. But we can connect an external
crystal oscillator to generate higher
frequencies and clock pulses. This
external oscillator is connected across the
XTAL pins (XTAL1 and XTAL2).
Pin configuration of ATmeag32
•Can you see some things written in the
brackets? Like PA0 (ADC0), PB5 (MOSI),
PC2 (TCK), PD1 (TXD), etc. Well, these are
the extra features that the MCU can offer
you apart from GPIO. In other words,
these pins show dual behavior. If nothing
is specified, they act as GPIO pins. The
secondary features of these pins become
active only if you enable certain bits of
some registers. These are called
peripherals
AVR Peripherals
● There are several peripherals that AVR offers in ATMEGA32, some are as follows:
o ADC – Analog to Digital Converter – usually 10-12 bit
o Timers – 8 bit and 16 bit timers
o JTAG – Joint Test Action Group
o TWI – Two Wire Interface (or) I2C – Inter-Integrated Circuit
o USART – Universal Synchronous Asynchronous Receiver Transmitter
o UART – Universal Asynchronous Receiver Transmitter
o SPI – Serial Peripheral Interface
o WDT– Watchdog Timer …and many more!
AVR Peripherals
● ADC stands for Analog to Digital Conversion. The term is self-explaining. This feature
converts Analog signals into Digital signals. (8-channel ADC for ATmega32)

● Timers are something which are a consequence of clock frequency. We can


manipulate the clock pulses in order to generate timers of required resolution. (three
timers for ATmega32)

● JTAG corresponds to testing of the circuit. When we make a circuit and fix the MCU
onto it, we use JTAG to verify whether our connection, soldering, circuit design, etc is
correct or not.
AVR Peripherals
● TWI/I2C (its actually I-square-C) is a revolutionary technology by Philips, in which two devices
are connected and communicate by using two wires.

● USART/UART is related to serial communication in which the MCU sends and receives signals
from another device based on serial protocol.

● SPI is something which helps to interface I2C, UART, etc

● WDT (Watch Dog Timer) is something interesting it seems. The name is also quite interesting.
Just like a watchdog always keeps an eye on it’s master to protect him from any harm, WDT
keeps an eye on the execution of the code to protect the MCU from any harm. A WDT is a
computer hardware or software timer that triggers a system reset or other corrective action if
the main program, due to some fault condition, such as a hang, neglects to regularly service
the watchdog (writing a “service pulse” to it, also referred to as “kicking the dog”, “petting the
dog”, “feeding the watchdog” or “waking the watchdog”). The intention is to bring the system
back from the unresponsive state into normal operation.
Brief History of ARM
● First ARM processor developed in 3 micron technology in ‘83-85’ by Acron Computers
Ltd. of Cambridge, England. ARM- Acron RISC Machine.

● Later on ARM (Advanced RISC Machine) Ltd. spun out of Acorn Computers in 1990 and
hence now ARM stands for Advanced RISC Machine.

● Designs the ARM range of RISC processor cores but not fabricate.

● Licenses ARM core designs to semiconductor partners who fabricate ARM core with
other components as per requirements and sell to their customers.
ARM Application Areas

● The ARM is widely ○ GSM handsets


Cable/ADSL modems
used: ○
○ Routers
○ Video Games ○ Smart cards
○ Set-top boxes ○ Pocket PCs
○ Satellite receivers ○ Hand-held PCs
○ Digital cameras ○ Various PDAs
○ Laser printers
ARM is one of the most
popular 32-bit cores
4 billion ARM cores were manufactured in
2008
Is the ARM a RISC?
● Some RISC features in ARM are enhanced to meet requirement
of embedded systems:
● RISC features:
○ A large uniform register file
○ Load-store architecture
○ Uniform and Fixed length 32-bit instructions (32-bit CPU) with 16-bit
Thumb instructions
● Features rejected from RISC
○ Register window
○ Delayed branches
○ Single cycle execution of all instructions
● ARM is a RISC architecture but with few CISC features to achieve a higher code
density, power efficiency and small core size compared to pure RISC architecture.
● If offers simple hardware but RISC instruction set with some key CISC features.
ARM Architecture Versions/Variants
Version Core Important Features
V1 ARM 1 26-bit insts., no multiply, no co-processor
V2 ARM2, ARM 3 32-bit result multiply, coprocessor
V3 ARM 6, ARM 7 32-bit addressing
V4 ARM 8, StrongARM Add Signed, Unsigned half-word and
signed byte load-store instructions
V4T ARM 7 TDMI, ARM 9TDMI 16-bit Thumb compressed form of
instructions introduced
V5T ARM 10 Superset of 4T with new insts.
V5TE ARM 9E-S, ARM 10TDMI Add Signal Processing Extension
V6 ARM 11 Jazzale technology for Java acceleration,
ARM DSP and SIMD multimedia
extension
○ 8 Stage Pipeline

○ Static and Dynamic branch prediction logic


Naming ARM

J: Jazelle E: Enhanced DSP instruction


S: Synthesizable F: integral vector floating point unit
ARM data types
The Programmer’s Model: Full ARM Register Set

• There are 37 registers in the


register file
• 20 of these are hidden from a
program at different times
• This is called register banking
User Mode: The Register Set
• General purpose registers hold data or an address
• General purpose registers begin with an r, e.g., r4
• All registers are 32-bits wide
• In user mode, in which applications execute, the register
set appears like this:
• 16 Data registers – r0 .. r15
• Current program status register – cpsr
• Special purpose registers:
• r13 is stack pointer (sp)
• r14 is the link register (lr) – return address
• r15 is the program counter (pc) – address of next
instruction
Current Program Status Register - cpsr
Flags Status Extension Control

Bit: 31 30 29 28 7 6 5 4 0
N Z C V I F T Mode

Conditi Interrupt Processor


Thumb mode
on mask state
flags
Interrupt Disable/Mask bits.
V oVerflow The result causes signed overflow I = 1: Disables the IRQ.
C Carry Unsigned carry F = 1: Disables the FIQ.
Z Zero The result is zero T Bit: T = 0: Processor in ARM state
N Negative Bit 31 of the result is 1 T = 1: Processor in Thumb state
ARM Processor: Operating Modes
Mode Use Registers
User Normal user code user
Fast Interrupt (FIQ) Processing fast interrupts _fiq
Interrupt (IRQ) Processing standard interrupts _irq
Supervisor Control (SVC) Processing Software interrupts _svc
Abort Processing memory faults _abt
Undefined Handling undefined instruction traps _und
System Running Privileged operating system tasks user
Processor Modes: Privileged and Non-privileged
• The current mode determines the active register set and access rights to cpsr
• A mode may be privileged or non-privileged
• Privileged mode allows full read/write access to cpsr
• Non-privileged mode allows only read access to control field of cpsr but
read/write to condition flags
• Privileged mode is used to handle exceptions (interrupts) and supervisor calls
(software interrupt)
Mode Privileged Mode [4:0]
Abort yes 10111
FIQ yes 10001
IRQ yes 10010
Supervisor yes 10011
System yes 11111
Undefined yes 11011
User no 10000
SPSR: Saved Program Status Register
• There are two processor status registers – cpsr and spsr
– the current and saved psr
• The visibility of the register set depends on the current
mode of the processor
• Each privileged mode (except system mode) has
associated with it a save program status register (SPSR)
• It is used to save the state of the CPSR when the
privileged mode is entered in order that the user state
can be fully restored when the user process is resumed
The I/O system

● The ARM handles I/O peripheral as memory mapped devices with


interrupt support.

● The internal registers in these devices appears a addressable location


within the ARM’s memory map and may be read and written using the
same (load-store) instructions as any other memory locations.

● Peripherals may attract the processor’s attention by making an interrupt


request using either normal interrupt (IRQ) or fast interrupt (FIQ) input.

● Interrupts are form of exception.


ARM exception
● The ARM architecture supports a range of interrupts, traps and
supervisor calls, all grouped under the general heading of exceptions.
The way of handling these exceptions are
1. The current state is saved by copying the PC into r14_exc and CPSR into SPSR_exc (exc
stands for the exception type)

2. The processor operating mode is changed to the appropriate exception mode

3. The PC is forced to a value between 0016 and 1C16, the particular value depending
upon the type of exception.

● The exception handler will user r13_exc, which will normally have
been initialized to point to a dedicated stack in memory, to save some
user registers.

You might also like