Professional Documents
Culture Documents
UNIVERSITY OF CALCUTTA
MCA – P3
IoT and Embedded System Laboratory Assignment Copy
Semester: III
Name: Pritam Sarkar
CU Registration Number: 544-1111-0587-19
CU Roll Number: C91/MCA/222013
Team Members
Akshay Kumar Das
Arijit Bose
Sarita Khatun Mollah
1
INDEX
S No. Practical Name Page no.
The Internet of Things (IoT) refers to a network of physical objects, devices, and sensors that
are connected to the internet and can communicate with each other and exchange data. These
objects can include a wide range of everyday items, such as household appliances, vehicles,
wearable devices, industrial machinery, environmental sensors, and more.
The key idea behind IoT is to enable these objects to collect and share data, often in real-time,
without requiring direct human intervention. This data can then be analysed and processed to
provide insights, optimize operations, and create new services or applications.
A three-tier IoT architecture is a common approach used to design and implement IoT
systems. It consists of three main layers or tiers: the Perception Layer, the Network Layer, and
the Application Layer. Each layer serves a specific purpose and contributes to the overall
functionality of the IoT system.
Perception Layer:
The Perception Layer is responsible for collecting data from various sensors and devices
deployed in the field. In the context of smart agriculture, this layer includes sensors that
monitor soil moisture, temperature, humidity, light levels, and other relevant environmental
factors. These sensors gather real-time data about the conditions in the agricultural field.
Network Layer:
The Network Layer facilitates the communication between the devices in the Perception
Layer and the Application Layer. It includes networking technologies and protocols that
allow data to be transmitted efficiently and securely. In the smart agriculture use case, the
Network Layer would involve technologies such as Low-Power Wide-Area Networks
(LPWAN), cellular networks, or even satellite communication, depending on the location of
the agricultural field.
Application Layer:
The Application Layer is where the data collected from the Perception Layer is processed,
analysed, and transformed into meaningful insights and actions.
An IoT node, also known as a "smart node" or simply a "node," refers to a physical device or
sensor that is part of an Internet of Things (IoT) network. These nodes are responsible for
collecting data from the environment, performing basic processing, and communicating with
other nodes or a central hub. They play a crucial role in the functioning of IoT systems by
gathering and transmitting data that can be used for analysis, control, and decision-making.
3
Air Quality Sensor: Measures various pollutants like particulate matter (PM2.5 and PM10),
carbon monoxide (CO), nitrogen dioxide (NO2), etc.
Connectivity: The IoT node needs a way to communicate data. It might include:
Wireless Module: Like Wi-Fi, Bluetooth, Zigbee, or LoRa to transmit data to a central server or
gateway.
Power Supply: Depending on the deployment location, the node might have a battery or be
connected to a power source.
Edge devices, also known as edge computing devices, refer to hardware devices that are
located at the edge of a network, closer to where data is generated or consumed. These devices
perform data processing and analysis locally, reducing latency and improving real-time
responsiveness. The concept of edge computing is especially valuable in scenarios where quick
decision-making, low latency, and efficient use of bandwidth are critical. Here's an example to
help illustrate the concept of edge devices:
Static and mobile fog nodes are two variations of fog computing devices that play
different roles within an edge computing architecture. Let's explore the concepts of both static
and mobile fog nodes:
A static fog node refers to an edge computing device that remains fixed in a specific location
within the network infrastructure. It is designed to provide localized data processing, analysis,
and other edge computing capabilities to devices or sensors within its vicinity. Static fog nodes
are particularly useful in scenarios where there is a consistent need for processing at a specific
location or to serve devices with limited processing capabilities.
Stability: Static fog nodes are stable and have a predictable location within the network
architecture.
Resource Allocation: These nodes can be equipped with substantial processing power,
memory, and storage since they are not constrained by mobility concerns.
Distributed Processing: They distribute the computational load away from the central cloud
and reduce latency for devices within their coverage area.
A mobile fog node refers to an edge computing device that is capable of mobility, allowing it
to move within the network environment. These devices can be vehicles, drones, robots, or any
other mobile platform equipped with processing capabilities. Mobile fog nodes are employed in
scenarios where the processing needs to follow the movement of data sources or where
dynamic data processing is required in various locations.
Mobility: Mobile fog nodes can relocate to different areas as needed, providing processing
resources where they are most required.
Real-time Processing: Mobile fog nodes can offer real-time processing capabilities at the
edge, even for data sources on the move.
There are several cloud platforms available that cater to IoT (Internet of Things) applications,
providing services for data storage, analysis, device management, and more. Here are some
examples of popular cloud platforms specifically designed for IoT:
AWS IoT Core (Amazon Web Services): AWS IoT Core offers a wide range of services for IoT
device management, data processing, and communication. It supports secure device
5
connectivity, message brokering, rules engine, and integration with other AWS services for data
storage and analytics.
Azure IoT Hub (Microsoft Azure): Azure IoT Hub provides scalable and secure bi-directional
communication between IoT applications and devices. It includes features like device identity
management, telemetry data ingestion, command and control, and integration with Azure
services like Azure Stream Analytics and Azure Functions.
Google Cloud IoT Core: This platform by Google Cloud offers tools to manage, connect, and
process data from IoT devices at scale. It includes device registration, secure communication,
and integration with Google Cloud's data processing and machine learning services.
IBM Watson IoT Platform: IBM's IoT platform allows organizations to connect devices, collect
data, and manage devices' lifecycle. It includes device management features, real-time data
visualization, and integration with AI and analytics tools through IBM Watson.
Particle Cloud: Particle Cloud is a platform tailored for IoT device connectivity, management, and
data collection. It provides tools for building and managing connected devices and enables
developers to create custom IoT solutions.
Fog computing and cloud computing are both paradigms that deal with processing and
managing data, but they have distinct characteristics and use cases. Let's compare them using
two case studies:
Fog Computing:
Benefits: Reduced latency, real-time optimization, quick response to localized events, improved
operational efficiency.
Cloud Computing:
o In the same smart manufacturing scenario, cloud computing comes into play for broader
analysis and long-term trends.
o Data processed by the fog nodes is periodically aggregated and sent to the cloud. Cloud-
based analytics platforms process the data from multiple factories to identify larger
patterns, correlations, and trends. For instance, it can identify systemic inefficiencies
across multiple production lines.
Benefits: Scalability, in-depth analysis, centralized data management, insights across multiple
facilities.
6
Fog Computing:
o In a smart city traffic management scenario, fog computing can enhance real-time
decision-making for traffic control.
o Fog nodes located at intersections process data from traffic cameras and sensors. They
analyse traffic flow, detect congestion, and adjust traffic signal timings in real time. This
helps to optimize traffic flow and reduce congestion at specific intersections.
Cloud Computing:
Benefits: Centralized data analysis, long-term planning, and holistic view of traffic patterns.
Key Differences:
o Location: Fog computing emphasizes processing data closer to the data source, while cloud
computing centralizes data processing in remote data canters.
o Latency: Fog computing minimizes latency by processing data locally, while cloud computing
might introduce higher latency due to data transmission.
o Real-Time vs. Aggregated Analysis: Fog computing focuses on real-time, localized decision-
making, whereas cloud computing excels in aggregated analysis, historical trends, and large-
scale insights.
o Scalability: Cloud computing offers greater scalability for analysing massive data sets,
whereas fog computing is ideal for localized, real-time processing.
o Use Cases: Fog computing suits scenarios requiring immediate responses, while cloud
computing is better suited for broader analysis and long-term planning.
Both fog and cloud computing have their strengths, and the choice depends on the specific
requirements of the application and the balance between local processing and centralized
analysis.
A fog node, also known as an edge node or edge device, is a key component in fog
computing that processes and analyses data locally, closer to the data source, rather than
sending all data to a centralized cloud.
o Proximity to Data Source: A fog node is located in close proximity to where data is
generated, allowing for reduced latency in data processing and quicker decision-making.
o Local Processing: Fog nodes have computational capabilities that enable them to perform
data processing and analysis tasks locally, without needing to send data to a remote cloud
server.
7
Required components:
Arduino Uno R3 board
The Arduino Uno R3 is a popular microcontroller board that serves as a versatile platform for
learning and prototyping. Here are the basics of its key components and features:
Components:
● Analog pins: (A0-A5)
○ The Arduino Uno features 6 analog input pins (A0-A5) that can read analog voltage
levels using the built-in Analog-to-Digital Converter (ADC). These pins are useful for
interfacing with sensors that provide analog output.
○ Positive power is analog cycle.
I2C: 4 (SDA) and 5 (SCL). Support I2C (TWI) communication using the Wire library
(documentation on the Wiring website).
● Voltage Regulator:
○ The Arduino Uno has two voltage regulators. One voltage regulator is 5V and the
other one is a 3.3V regulator. Arduino can take power from multiple sources either it
can be USB or an external power supply (8 to 20 volts DC). The regulator reduces
this to the 5 volt DC level that the Arduino uses.
● Power pins:
○ VIN (sometimes labelled "9V"): The input voltage to the Arduino board when it's
using an external power source (as opposed to 5 volts from the USB connection or
other regulated power source). You can supply voltage through this pin, or, if
supplying voltage via the power jack, access it through this pin.
○ Power OUT (5V and 3.3V pins): The board regulated 5V and 3.3V output for
powering external components.
11
● ATmega328P microcontroller:
The heart of the Arduino Uno R3 is the Atmega328P microcontroller, which has 32KB of
flash memory for program storage, 2KB of SRAM for data storage, and 1KB of EEPROM for
non-volatile storage.
● Memory Specifications:
○ Flash Memory: 32KB
○ SRAM: 2KB
○ EEPROM: 1KB
● USB Connector:
The most common and easiest way we can power an Arduino board is by using its
onboard USB B connector. The USB connector provides a regulated 5V line to power the board's
electronics. However, 5V from the USB connector can also power external components through
the 5V pin that can be found in Arduino boards.
● Power Port:
It is a 2.1mm DC power jack. Arduino Uno accepts 7-12V DC through this port and
the onboard voltage regulator regulates it down to the required 5 and 3.3V.
● Reset Switch:
Pressing it has the same effect as disconnecting and reconnecting the power supply: The
board will wait briefly for a new sketch to upload, then it will start executing any instructions in
the sketch from the beginning. Powering down the board clears RAM memory, so values that
were previously assigned to variables are not kept.
● Power Pins:
The board has a 5V pin and a 3.3V pin for supplying power to external components. It
also has multiple Ground (GND) pins.
1. Data Collection: The DHT11 sensor is used to gather temperature and humidity data from
the surrounding environment. This data can be used for various purposes, such as
monitoring environmental conditions in a room, greenhouse, or any other space where
temperature and humidity play a significant role.
3. Automation and Control: The acquired data can be integrated into automation systems to
control devices such as heaters, fans, or humidifiers, based on predefined thresholds. For
example, if the temperature rises above a certain level, a cooling system can be activated
automatically.
4. Alerts and Notifications: If the temperature or humidity goes beyond acceptable limits, the
acquired data can trigger alerts or notifications. This is important for scenarios where
maintaining a specific environment is critical, such as in server rooms or museum storage.
5. Data Analysis: The collected data can be analyzed over time to identify trends, patterns, and
correlations between temperature and humidity. This information can aid in making
informed decisions for improving environmental conditions.
6. Research and Experimentation: Temperature and humidity data acquisition is essential for
various scientific research and experimentation projects. It helps researchers study the
effects of environmental conditions on different phenomena.
7. Education: This objective can also serve as a hands-on educational project to teach students
or hobbyists about sensor interfacing, data acquisition, and basic programming concepts.
Required components:
15
To perform temperature and humidity data acquisition using the DHT11 sensor, you will need a
few components to set up the hardware and software for data collection. Here's a list of the
required components:
1. DHT11 Sensor: The DHT11 is a digital temperature and humidity sensor that provides
accurate readings. It's a compact and relatively inexpensive sensor commonly used for
environmental monitoring projects.
3. Breadboard and Jumper Wires: A breadboard and jumper wires are essential for creating
connections between the DHT11 sensor and the microcontroller pins. Jumper wires help
establish a secure and flexible connection.
4. Resistor (10k Ohm): A 10k Ohm resistor is required to provide a pull-up on the data line of
the DHT11 sensor.
6. Computer or Device: You'll need a computer or device to program the microcontroller and
receive the temperature and humidity data. This could be your PC, laptop, or even a
Raspberry Pi.
8. Software Libraries: You'll need the appropriate software libraries to communicate with the
DHT11 sensor and retrieve temperature and humidity data. For Arduino, you can use the
"DHT sensor library." For Raspberry Pi, you can use the "Adafruit DHT Library."
9. Optional Display or Output Device: If you want to display the temperature and humidity
readings, you might need an optional display device such as an LED display, LCD screen, or
OLED screen.
1. Sensing Element: The heart of the DHT11 sensor is its sensing element, which is a composite
material made of polymers that changes its electrical properties with variations in
temperature and humidity. This element allows the sensor to measure both temperature
and humidity.
3. Data Pin: The DHT11 sensor communicates with external devices (such as microcontrollers)
using a single-wire digital communication protocol. The data pin is used to both transmit and
receive data.
4. Power and Ground Pins: The sensor requires a power supply (typically 3.3V or 5V) and a
ground connection to operate.
Working Principle:
The DHT11 sensor operates based on the capacitive sensing principle, which involves measuring
changes in the electrical capacitance of the sensing element due to changes in temperature and
humidity. Here's how it works:
1. Initialization: When the microcontroller initiates a request for data, it sends a start signal to
the DHT11 sensor.
2. Measurement: The sensor measures the initial capacitance of the sensing element, which is
affected by the ambient temperature and humidity.
3. Heating and Cooling: The sensor briefly applies heat to the sensing element, causing it to
reach a known temperature. Then, it measures the capacitance of the element as it cools
down. The rate of cooling is influenced by the ambient humidity.
4. Digital Conversion: The sensor's signal processing circuitry analyzes the differences in
capacitance during the heating and cooling cycles. It then converts these differences into
digital temperature and humidity values.
5. Data Transmission: The converted temperature and humidity values are sent back to the
microcontroller using a single-wire digital protocol. The data is transmitted bit by bit, with
specific timing patterns indicating whether a bit is 0 or 1.
6. Checksum: The DHT11 sensor also calculates a checksum value based on the transmitted
data. The checksum is used to verify the integrity of the received data and ensure accurate
measurements.
7. Data Interpretation: The microcontroller receives the data from the DHT11 sensor and
interprets it according to the sensor's specifications. It then uses this data for display,
recording, or other intended purposes.
The DHT11 sensor has four pins, each serving a specific purpose in the sensor's operation. Here's
the pinout and functionality of each pin:
Function: This pin is used for bidirectional digital communication between the
sensor and the microcontroller.
Connection: Connect this pin to a digital I/O pin on your microcontroller. This is the
pin where data is sent and received.
Function: This pin does not have any functional purpose and is not used in the
DHT11 sensor's operation.
Connection: This pin is not connected to anything and can be left unconnected.
4. GND (Ground Pin):
Function: This pin is used to establish the ground connection for the DHT11 sensor.
Connection: Connect this pin to the ground (GND) pin on your microcontroller or
development board.
Functionality of Data Pin:
The data pin of the DHT11 sensor serves a critical role in communication between the sensor
and the microcontroller. It uses a single-wire digital communication protocol to transmit
temperature and humidity data to the microcontroller. The communication involves the following
steps:
1. Initialization: The microcontroller sends a start signal to the sensor by setting the data line
low for a brief period. This indicates to the sensor that the microcontroller is ready to
receive data.
2. Response: The sensor responds by pulling the data line low for a short duration, followed by
a high signal for a fixed period. This response confirms that the sensor is ready to transmit
data.
3. Data Transmission: The sensor transmits data bit by bit. Each bit is encoded by the duration
of time that the data line is held low (bit value 0) or high (bit value 1).
4. Checksum: After transmitting the temperature and humidity data, the sensor calculates a
checksum value and transmits it. The microcontroller uses this checksum to verify the
integrity of the received data.
5. Data Interpretation: The microcontroller receives the data from the sensor, decodes it
based on the timing information, and then uses the data to determine the temperature and
humidity values.
Coding :
#include <DHT.h>
#define DHTPIN 8
DHT dht(DHTPIN,DHTTYPE);
void setup()
Serial.begin(9600);
dht.begin();
void loop()
Serial.print("temperature: ");
Serial.print(temp);
Serial.print("humidity: ");
Serial.print(humid);
Serial.println("");
delay(1000);
Output :
1. Home Automation:
Control HVAC systems: Use temperature and humidity data to automate heating,
cooling, and ventilation systems in homes or offices.
20
Optimal plant growth: Monitor temperature and humidity to create the right
environment for plants in greenhouses.
Prevent diseases: Detect conditions that could lead to mold or plant diseases due to
excessive humidity.
3. Weather Stations:
Personal weather monitoring: Collect temperature and humidity data for local
weather observations and predictions.
Mold prevention: Detect and prevent conditions conducive to mold growth, which
can be harmful to health.
Long-term monitoring: Record temperature and humidity data over time for
analysis, trends, and research purposes.
1. High Accuracy Measurements: The DHT22 sensor provides more accurate temperature and
humidity readings compared to the DHT11 sensor. This improved accuracy makes it suitable
for applications where precise data is required.
2. Wider Operating Range: The DHT22 sensor can operate over a wider temperature and
humidity range, making it suitable for environments that experience more extreme
conditions.
4. Research and Analysis: Researchers can use the DHT22 sensor to gather accurate data for
analysing environmental trends, studying the effects of temperature and humidity on
various processes, and conducting scientific experiments.
5. Automation and Control: The acquired data from the DHT22 sensor can be used in
automation systems to control devices like heaters, coolers, and humidifiers to maintain
specific environmental conditions.
6. Health and Comfort: The DHT22 sensor can be employed in applications such as home
automation to ensure a comfortable living environment, as well as in medical settings to
monitor temperature and humidity in patient rooms.
7. Data Logging and Analysis: Data collected from the DHT22 sensor can be logged over time
and analysed to identify patterns, trends, and correlations between temperature and
humidity changes.
22
Required components:
To perform temperature and humidity data acquisition using a DHT22 sensor, you'll need several
components and tools. The DHT22 sensor is a digital sensor that can measure temperature and
humidity with reasonable accuracy.
1. DHT22 Sensor: This is the main sensor that measures temperature and humidity.
3. Jumper Wires: These are used to connect the DHT22 sensor to the microcontroller.
4. Resistor (10k ohms): A pull-up resistor is often required for stable communication between
the sensor and the microcontroller.
5. Power Supply: Make sure you have a stable power supply for both the microcontroller and
the DHT22 sensor. This could be a USB cable, battery pack, or another suitable power
source.
6. Computer: You'll need a computer for programming the microcontroller and for processing
the acquired data.
7. Programming Environment: Depending on the microcontroller you're using, you'll need the
appropriate programming environment. For example, the Arduino IDE for Arduino boards.
1. Sensing Element: The heart of the DHT22 sensor is its sensing element, which includes a
capacitive humidity sensor and a digital temperature sensor. These components work
together to measure temperature and humidity accurately.
2. Microcontroller and Signal Processing Circuitry: Similar to the DHT11 sensor, the DHT22
sensor also includes a microcontroller and signal processing circuitry. This microcontroller is
responsible for converting the analog signals from the sensing elements into digital data that
can be read and processed by external devices.
3. Data Pins: The DHT22 sensor communicates with external devices using a single-wire digital
communication protocol. It has a single data pin that is used for both transmitting and
receiving data.
23
4. Power Supply and Ground Pins: The sensor requires a power supply (typically 3.3V or 5V)
and a ground connection for its operation.
Working Principle:
The DHT22 sensor operates based on the capacitive sensing principle, similar to the DHT11
sensor. However, the DHT22's design and components result in improved accuracy and
performance. Here's how it works:
1. Initialization: When the microcontroller initiates a data request, it sends a start signal to the
DHT22 sensor.
2. Response: The sensor responds by pulling the data line low for a brief period, followed by a
high signal for a fixed period. This response indicates that the sensor is ready to transmit
data.
3. Data Transmission: The DHT22 sensor transmits data bit by bit using a single-wire digital
communication protocol. Each bit is represented by the duration of time that the data line is
held low (bit value 0) or high (bit value 1).
4. Checksum: After transmitting the temperature and humidity data, the sensor calculates a
checksum value based on the transmitted data. The checksum is used by the receiving
device to verify the integrity of the received data.
5. Data Interpretation: The microcontroller receives the transmitted data from the sensor,
decodes it based on the timing information, and then converts the data into temperature
and humidity values.
7. Digital Conversion: The analog signals from the humidity and temperature sensors are
converted into digital values using the sensor's internal analog-to-digital converters.
The DHT22 sensor, also known as the AM2302, has four pins, each serving a specific purpose in
the sensor's operation. Here's the pinout and functionality of each pin:
Function: This pin does not have any functional purpose and is not used in the
DHT22 sensor's operation.
Connection: This pin is not connected to anything and can be left unconnected.
4. GND (Ground Pin):
Function: This pin is used to establish the ground connection for the DHT22 sensor.
Connection: Connect this pin to the ground (GND) pin on your microcontroller or
development board.
The data pin of the DHT22 sensor is used for communication between the sensor and an
external microcontroller. The sensor uses a single-wire digital communication protocol to transmit
temperature and humidity data to the microcontroller. The communication involves the following
steps:
1. Initialization: The microcontroller sends a start signal to the sensor by pulling the data line
low for a brief period. This indicates to the sensor that the microcontroller is ready to
receive data.
2. Response: The sensor responds by pulling the data line low for a specific duration, followed
by a high signal for a fixed period. This response confirms that the sensor is ready to transmit
data.
3. Data Transmission: The sensor transmits data bit by bit using specific timing patterns. Each
bit is encoded by the duration of time that the data line is held low (bit value 0) or high (bit
value 1).
4. Checksum: After transmitting the temperature and humidity data, the sensor calculates a
checksum value and sends it to the microcontroller. The microcontroller uses this checksum
to verify the integrity of the received data.
5. Data Interpretation: The microcontroller receives the data from the sensor, decodes it
based on the timing information, and then converts the data into temperature and humidity
values.
Coding:
#include <DHT.h>
#define DHTPIN 8
DHT dht(DHTPIN,DHTTYPE);
void setup()
Serial.begin(9600);
dht.begin();
void loop()
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println("°C");
26
Serial.print("Humidity: ");
Serial.print(humid);
Serial.println("%");
delay(1000);
Output:
1. Environmental Monitoring:
Server rooms: Monitor and control temperature and humidity levels in data centres
to prevent overheating and equipment failure.
Accurate weather data: Use the DHT22 sensor in personal weather stations or small-
scale meteorological setups to gather precise temperature and humidity
information.
Smart thermostats: Incorporate the DHT22 sensor into home automation systems to
create energy-efficient heating, cooling, and ventilation schedules.
Optimal crop conditions: Use the DHT22 sensor to ensure the right temperature and
humidity levels for various crops in indoor and outdoor settings.
1. Data Collection: The LDR sensor is used to collect light intensity data, which can be utilized
for various purposes such as monitoring changes in ambient lighting conditions.
2. Environmental Monitoring: By continuously tracking light levels, you can gain insights into
how natural light changes throughout the day or how artificial lighting affects different
spaces.
3. Energy Efficiency: Use light intensity data to optimize the use of artificial lighting in indoor
spaces, saving energy by only activating lights when necessary.
4. Security and Safety: Light intensity data can be used to trigger security systems or lighting
automation in response to changes in ambient lighting conditions.
5. Research and Analysis: Collect light intensity data over time to analyse trends and patterns
in lighting conditions, which can be useful for various research purposes.
6. Agriculture and Plant Growth: Monitor light levels in agricultural settings to ensure that
plants receive the appropriate amount of light for healthy growth.
7. Photography and Videography: Use light intensity data to control camera settings, such as
adjusting exposure, based on ambient lighting conditions.
Required components:
To perform light intensity data acquisition using an LDR (Light Dependent Resistor) sensor, you'll
need a few components and tools. An LDR is a variable resistor whose resistance changes based on
the intensity of light falling on it. Here's a list of the required components:
1. LDR (Light Dependent Resistor): This is the primary sensor that will change its resistance
based on light intensity.
3. Jumper Wires: These wires will be used to connect the LDR sensor to the microcontroller.
4. Resistor (optional): Depending on your circuit design and the LDR used, you might need a
fixed resistor to create a voltage divider circuit for more accurate measurements.
29
5. Power Supply: Ensure you have a stable power supply for both the microcontroller and the
LDR sensor. This could be a USB cable, battery pack, or another suitable power source.
6. Computer: You'll need a computer for programming the microcontroller and for processing
the acquired data.
7. Programming Environment: Depending on the microcontroller you're using, you'll need the
appropriate programming environment. For example, the Arduino IDE for Arduino boards.
Working Principle:
The operation of an LDR is based on the principle of the photoconductive effect, which is a
property of certain materials to conduct electricity better when exposed to light. Here's how it
works:
In the absence of light or under low light conditions, the semiconductor material in
the LDR has a high resistance. This means it restricts the flow of electric current.
5. Output Signal:
The output signal from the voltage divider circuit can be processed using analog-to-
digital converters (ADCs) in microcontrollers or other electronics.
By analysing the output voltage, the microcontroller or circuit can determine the
light intensity.
Pinout and functionality of each pin
An LDR (Light Dependent Resistor) is a passive component with two pins. The pinout and
functionality of each pin are quite straightforward:
1. Two Pins:
An LDR has two leads or pins: one lead is connected to one side of the photoresistor,
and the other lead is connected to the other side.
2. No Specific Polarity:
Unlike some active components (such as diodes or transistors), LDRs do not have a
specific polarity. This means that you can connect either pin to the positive voltage
and the other to the negative voltage (ground) without any concerns about
reversing the connection.
The primary function of an LDR is to vary its resistance based on the intensity of light
falling on it. This variation in resistance is used to sense and measure light levels in
various applications.
Coding:
int ldrPin = A0; // Analog pin for LDR sensor
void setup() {
Serial.begin(9600); // Initialize serial communication
}
void loop() {
// Read analog value from LDR sensor
int ldrValue = analogRead(ldrPin);
// Convert analog value to voltage (0 to 5V)
float voltage = ldrValue * (5.0 / 1023.0);
// Convert voltage to light intensity (adjust this based on your sensor's characteristics)
// You might need to calibrate this based on your specific LDR sensor
float lightIntensity = map(voltage, 0.0, 5.0, 0.0, 100.0);
Serial.print("LDR Value: ");
Serial.print(ldrValue);
Serial.print("\tVoltage: ");
Serial.print(voltage, 2);
Serial.print("V\tLight Intensity: ");
Serial.print(lightIntensity, 2);
Serial.println("%");
delay(1000); // Wait for 1 second
}
Output:
32