Experiment - 1: Download The File From The Link Given Below

Download as pdf or txt
Download as pdf or txt
You are on page 1of 44

Name –PRINCE KHATRI Class - B.

Tech, III Year Branch - AI & DS Sem – VI


Subject – Sensor Theory and Applications (EC 363)

Experiment – 1
Aim – To install all the tools or Software required for Sensor Theory &
Application’s Lab.
Software Required –
Arduino IDE
Installation of Arduino IDE on Windows 11 –
Step 1: Download the file from the link given below.
Windows MSI installer (arduino.cc)

Step 2: Open the file by double clicking on it, it automatically installs the
Arduino IDE and create a Desktop shortcut.

1|Pa g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)

Step 4: Open the Arduino IDE by double clicking and install the
required libraries .

The Arduino IDE is installed now and you can use to run your codes.

2|Pa g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)

EXPERIMENT-4
Aim: To study the about Touch Sensor and its technical specifications.
Theory:
A touch sensor is a type of device that captures and records physical touch or embrace on a
device and/or object. It enables a device or object to detect touch or near proximity, typically by
a human user or operator. Touch sensing input devices offer numerous possibilities for novel
interaction techniques and it reliably replaces mechanical buttons and switches to eliminate
mechanical wear and tear. These can be configured into simple sliders, rotary wheels, or touch
pads for intuitive user interfaces.
A touch sensor primarily works when an object or individual gets in physical contact with it.
Touch sensors are also called as tactile sensors and are sensitive to touch, force or pressure. It
can be implemented using Capacitive or Resistive sensing technology.

Working Principle of Touch Sensors:


• Touch sensors work similar to a switch. When they are subjected to touch, pressure or
force they get activated and acts as a closed switch. When the pressure or contact is
removed they act as an open switch.
• Capacitive touch sensor contains two parallel conductors with an insulator between them.
These conductors plates act as a capacitor with a capacitance value C0.
• When these conductor plates come in contact with our fingers, our finger acts as a
conductive object. Due to this, there will be an uncertain increase in the capacitance.
• A capacitance measuring circuit continuously measures the capacitance C0 of the sensor.
When this circuit detects a change in capacitance it generates a signal.
• The resistive touch sensors calculate the pressure applied on the surface to sense the
touch. These sensors contain two conductive films coated with indium tin oxide, which is
a good conductor of electricity, separated by a very small distance.
• Across the surface of the films, a constant voltage is applied. When pressure is applied to
the top film, it touches the bottom film. This generates a voltage drop which is detected
by a controller circuit and signal is generated thereby detecting the touch.

20 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)

Principles of operation:
1. Capacitive Touch sensors: These sensors detect touch based on changes in capacitance.
When an object with capacitance (such as a finger) approaches the sensor surface, it
alters the capacitance, which is then detected by the sensor. Capacitive sensors are
widely used in smartphones, tablets, and touch-sensitive interfaces.

2. Resistive Touch Sensors: Resistive sensors consist of multiple layers separated by


insulating dots. When pressure is applied, the top and bottom layers make contact,
causing a change in resistance at the point of touch. Resistive sensors are commonly
found in older touchscreen devices and certain industrial applications.

3. Infrared Touch Sensors: Infrared sensors emit infrared light beams across the surface.
When an object touches the screen, it interrupts these beams, and the interruption is
detected to determine the touch location.
Types of Touch Sensors:
a. Single-Touch vs. Multi-Touch: Single-touch sensors can detect only one point of
contact at a time, whereas multi-touch sensors can detect multiple points simultaneously,
enabling gestures like pinch-to-zoom.
b. Surface vs. Projected Capacitive: Surface capacitive touch sensors are suitable for flat
surfaces and are commonly used in devices like kiosks and ATMs. Projected capacitive
touch sensors can detect touches through non-conductive materials like glass, making
them ideal for smartphones and tablets.
c. Analog vs. Digital: Analog touch sensors provide continuous data about touch pressure
or position, while digital touch sensors provide discrete outputs indicating touch/no -
touch events.
Technical Specifications:

21 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)

Specifications:
• Operating voltage - 2.0V~5.5V
• Operating temperature: -40 to 80 °C
• Operating current @VDD=3V, no load
• Input Voltage: GND-0.3 ~ VCC+0.3 V
• At low power mode typical 1.5uA, maximum 3.0uA
• The response time max - 220mS
• At low power mode @VDD=3V
• Sensitivity can adjust by the capacitance(0~50pF) outside.
• Stable touching detection of human body for replacing traditional direct switch key.
• Provides Low Power mode.
• Output pin sink current – 8 mA.
• Output pin pull-up current – 4 mA.
• Dimensions – 3 x 2 x 1 cm
• Weight – 5 grams
• All output modes can be selected active high or active low by pad option (AHLB pin)
• Auto calibration for life
On the basis of applications:-
1. Smartphones and Tablets:
Touch Type: Capacitve.
Dimensions: Customized to device size.
Touch Resolution: High (e.g., 1080p or higher).
Touch Accuracy: Very high (sub-millimetre precision).
Multi-Touch Support: Essential for pinch-to-zoom and multi-finger gestures.
Touch Response Time: Low (typically milliseconds).
Durability: Scratch-resistant, impact-resistant.
Environmental Conditions: Operating temperature range of -10°C to 40°C, high
22 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
humidity tolerance.
Interface: Directly integrated into device's touchscreen controller.
Power Consumption: Low to conserve battery life.
Controller Compability: Optimized for specific touch controller chips used in
smartphones and tablets.

2. Industrial Control Systems (HMI):


Touch Type: Resistive or Capacitive.
Dimensions: Varies based on application (e.g., control panel size).
Touch Resolution: Adequate for industrial use (typically lower than consumer devices).
Touch Accuracy: High for precise control in industrial settings.
Multi-Touch Support: Depends on application, usually single-touch for industrial control
panels.
Touch Response Time: Fast for real-time control applications.
Durability: Resistant to harsh industrial environments (e.g., chemicals, dust, moisture).
Environmental Conditions: Wide operating temperature range, high shock and
vibration tolerance.
Interface: Typically USB, RS-232, or Ethernet.
Power Consumption: Varies based on application and power source availability.
Controller Compatibility: Compatible with industrial grade touch controller chips and
software libraries.

3. Medical Devices and Healthcare Interfaces:


Touch Type: Capacitive or Infrared.
Dimensions: Customizable to fit various medical devices and interfaces.
Touch Resolution: High for clear and precise touch input.
Touch Accuracy: Very high for accurate interaction in critical medical procedures.
Multi-Touch Support: Desirable for intuitive user interfaces and multi-step interactions.
Touch Response Time: Fast to ensure immediate response to user input in time-
sensitive situations.
Durability: Highly durable to withstand frequent cleaning and disinfection protocols.
Environmental Conditions: Resistant to fluids, chemicals, and cleaning agents used in
medical settings.
Interface: USB, serial, or integrated with medical device communication protocols (e.g.,
DICOM, HL7).
Power Consumption: Low to moderate to ensure compatibility with battery -operated
medical devices.

23 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)

EXPERIMENT-5(A)
Aim: To measure the temperature using LM-35 and find out the reference room temperature.
Software: Arduino IDE
Hardware Board: Arduino Uno
Components Required:
• Arduino board
• LM35 sensor
• Bread board
• Jumper wires
Theory:
LM35 is a temperature sensor which can measure temperature in the range of -55°C to 150°C.
It is a 3-terminal device that provides analog voltage proportional to the temperature. Higher
the temperature, higher is the output voltage.
The sensitivity of LM35 is 10 mV/degree Celsius. As temperature increases, output voltage also
increases.
E.g. 250 mV means 25°C.
The output analog voltage can be converted to digital form using ADC so that a microcontroller
can process it.
LM 35 shows high voltage values than thermocouples and may not need the output voltage to
be amplified. The output voltage of LM35 is proportional to the Celsius temperature. The
temperature is calculated by formula, temperature= output voltage (in mv) /10 mv/ o C.
Specifications:

• Operating Voltage: 4 V to 30 V
• Output Voltage: 10mV/°C
• Sensitivity: 10mV/°C
• Linearity Error: ±1°C (for 0°C to +100°C)
• Operating Temperature: -55°C to +150°C
• Output Impedance: 100 Ω
• Power Consumption: 60 μA (typical)
• Package Type: TO-92, TO-220, SOIC
• Output Type: Analog
24 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
• Accuracy: ±1°C (typical)

LM35 sensor pinout:

VCC: Supply Voltage (4V – 30V)


Out: It gives analog output voltage which is proportional to the temperature (in degree
Celsius).
GND: Ground

Working Principle:
LM35 is the sensor that senses the temperature of its environment and based on it's value it
generates an analog output voltage. This analog voltage produced by the LM35 is then given as
input to the Bolt A0 pin. The Bolt then converts the analog value into a 10 bit digital value that
varies from 0-1023.

The LM35 temperature sensor uses the basic principle of a diode to measure known
temperature value. As we all know from semiconductor physics, as the temperature
increases the voltage across a diode increases at a known rate. By accurately amplifying the
voltage change, we can easily generate a voltage signal that is directly proportional to the
surrounding temperature.

Circuit Diagram:
The sensor can be powered from 5V. The positive voltage connects to ‘+Vs’ and ground
connects to ‘GND‘. The middle pin ‘Vout’ is the analog signal output from the sensor and
connects to the A0 analog input of an Arduino.

25 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)

Code:
const int lm35_pin = A1; /* LM35 O/P pin */
void setup() {
Serial.begin(9600);
}
void loop() {
int temp_adc_val;
float temp_val;
temp_adc_val = analogRead(lm35_pin); // Read Temperature
temp_val = (temp_adc_val * 4.88); // Convert adc value to vc
temp_val = (temp_val/10); // LM35 gives output of 10mv/°C
Serial.print("Temperature = ");
Serial.print(temp_val);
Serial.print(" Degree Celsius\n");
delay(1000);
}

RESULT: Hence, we find out the temperature to be 24.4°C.

26 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
Experiment – 5(B)
Aim – To develop a temperature-controlled LED system using an Arduino board and a
temperature sensor (LM 35).

Apparatus Required:
Arduino Uno Board
Bread Board
Jumper Wires
LED’s
Temperature Sensor (LM 35)
Resistors

Software Required:
Arduino IDE

Circuit Diagram:

27 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)

Theory:
The LM35, developed and produced by Texas Instruments, is a low-power, cost-effective
temperature sensor known for its high precision. This IC delivers a voltage output linearly
corresponding to temperature changes. With a sturdy construction, the LM35 is suitable for
diverse environmental conditions, eliminating the need for external calibration components. It
boasts a typical accuracy of ±0.5°C at room temperature and ±1°C across a broad −55°C to
+155°C temperature range. Operating on a voltage range of 4V to 30V, it consumes a mere 60
µA during operation, making it ideal for battery-powered applications.

Despite its merits, the LM35 has two notable drawbacks. Firstly, it cannot measure negative
temperatures without biasing it with a dual-polarity supply. In such cases, the LM36 sensor can
be considered. Secondly, due to its analog data output, the LM35 is sensitive to noise.

28 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
The LM35 functions as a temperature sensor, providing an analog signal proportionate to the
instantaneous temperature, easily interpretable for Celsius readings. Its advantages over
thermistors include not requiring external calibration and being protected from self-heating by its
coating. The low cost (approximately $0.95) and high accuracy have made it popular among
hobbyists, DIY circuit makers, and students. Despite being around for over 15 years since its
initial release, the LM35 continues to be widely used in various products.

Capable of measuring temperatures from -55 degrees Celsius to 150 degrees Celsius, the LM35
achieves high accuracy under optimal temperature and humidity conditions. The conversion of
its output voltage to centigrade is straightforward.

Operating on input voltages ranging from +4 volts to 30 volts, the LM35 draws about 60
microamperes of current. The LM35 family includes various members such as LM35C,
LM35CA, LM35D, LM135, LM135A, LM235, and LM335. While these family members work
on the same principles, their temperature measuring capacities vary, and they are available in
different packages (SOIC, TO-220, TO-92, TO).

Connecting the LM35 sensor to the Arduino is simple. You just need to connect 5V power to the
sensor and you need to connect the output of the sensor to the A0 pin of the Arduino. Once the
connection is done you need to write the code to convert the output voltage of the sensor to
temperature data. Now connect the anode of LED with digital Pin 8 and the cathode with a resister
and the other end of resistor to the Ground pin on to the Arduino Board. After that, first, you need
to convert the ADC values to voltage and multiply that voltage to 10 and you will get the output
in temperature. With that, you’re now ready to upload the code to Arduino.

Code –
#define sensor_pin A0
#define led_pin 8

void setup() {
Serial.begin(9600);
pinMode(sensor_pin, INPUT);
pinMode(led_pin, OUTPUT);
}

void loop() {
int adcData = analogRead(sensor_pin);

float voltage = adcData * (5.0 / 1024.0);


float temperature = voltage * 100;

29 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println("*C");

if (temperature > 30) {


digitalWrite(led_pin, HIGH);
} else {
digitalWrite(led_pin, LOW);
}

delay(800);
}

Output –

Result –
Therefore, we have successfully develop a temperature-controlled LED system using an
Arduino board and a temperature sensor (LM 35).

30 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)

EXPERIMENT-6(A)
Aim: To measure the intensity of light using an LDR and Arduino Uno R3.
Apparatus Required:
1. Arduino Uno R3 board
2. LDR (Light Dependent Resistor)
3. Resistor (10k ohms)
4. Breadboard
5. Jumper wires
6. Power source (USB cable or battery)
Theory:
An LDR, or Light Dependent Resistor, belongs to a class of semiconductors whose resistance
varies in response to incident light. Composed of a photoconductive material, typically
cadmium sulfide (CdS) or lead sulfide (PbS), LDRs exhibit higher resistance in darkness due to
minimal photon excitation. When illuminated, photons energize the semiconductor's valence
electrons, reducing the band gap and allowing more current flow, thus lowering the resistance.
This unique property renders LDRs ideal for light sensing applications, including ambient light
detection, dusk-to-dawn switches, and camera exposure control. Their spectral response,
operating temperature range, and dynamic resistance characteristics vary based on material
composition and manufacturing processes. Through voltage divider configurations, LDRs can
translate light intensity into measurable electrical signals, facilitating their integration with
microcontrollers for light-dependent control systems.
Specification:
• Maximum power dissipation is 200mW
• The maximum voltage at 0 lux is 200V
• The peak wavelength is 600nm
• Minimum resistance at 10lux is 1.8kΩ
• Maximum resistance at 10lux is 4.5kΩ
• Typical resistance at 100lux is 0.7kΩ
• Dark resistance after 1 sec is 0.03MΩ
• Dark resistance after 5 sec is 0.25MΩ

31 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)

Working Principle: The operation of the LDR-based light sensor revolves around the variable
resistance of the LDR in response to incident light. When exposed to light, photons excite
electrons within the semiconductor material of the LDR, reducing its resistance. Conversely, in
darkness, the absence of photons leads to higher resistance.
In this experiment, the LDR is connected to the Arduino Uno R3 in a voltage divider
configuration. As the resistance of the LDR changes with light intensity, the voltage across it
also varies. By measuring this voltage using the analog-to-digital converter (ADC) of the
Arduino, we can infer the light intensity.
Circuit Diagram:

Code:
const int ldrPin = A0; // LDR connected to analog pin A0

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

void loop() {
int ldrValue = analogRead(ldrPin); // Read LDR value (0-1023)

32 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
// Convert LDR value to resistance (adjust the parameters accordingly)
float resistance = (float)(1023 - ldrValue) * 10 / ldrValue;

// Print LDR resistance to serial monitor


Serial.print("LDR Resistance: ");
Serial.print(resistance);
Serial.println(" ohms");

delay(1000); // Delay for 1 second


}

Result: Upon running the experiment, the Arduino Uno R3 reads the analog voltage from the
LDR and calculates the corresponding resistance. This resistance value is then displayed on the
serial monitor. As the intensity of light changes, the resistance of the LDR will vary, thus
providing a measure of light intensity in ohms.
Light Intensity in room is 600 lux.

EXPERIMENT-6(B)
Aim: To automatically turn on an LED when the light intensity in the room drops below a
certain level using an LDR and Arduino Uno R3.

33 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
Apparatus Required:
1. Arduino Uno R3 board
2. LED (Light Emitting Diode)
3. LDR (Light Dependent Resistor)
4. Resistor (220-330 ohms)
5. Breadboard
6. Jumper wires
7. Power source (USB cable or battery)
Theory:
An LDR, or Light Dependent Resistor, belongs to a class of semiconductors whose resistance
varies in response to incident light. Composed of a photoconductive material, typically
cadmium sulfide (CdS) or lead sulfide (PbS), LDRs exhibit higher resistance in darkness due to
minimal photon excitation. When illuminated, photons energize the semiconductor's valence
electrons, reducing the band gap and allowing more current flow, thus lowering the resistance.
This unique property renders LDRs ideal for light sensing applications, including ambient light
detection, dusk-to-dawn switches, and camera exposure control. Their spectral response,
operating temperature range, and dynamic resistance characteristics vary based on material
composition and manufacturing processes. Through voltage divider configurations, LDRs can
translate light intensity into measurable electrical signals, facilitating their integration with
microcontrollers for light-dependent control systems.
Specification:
• Maximum power dissipation is 200mW
• The maximum voltage at 0 lux is 200V
• The peak wavelength is 600nm
• Minimum resistance at 10lux is 1.8kΩ
• Maximum resistance at 10lux is 4.5kΩ
• Typical resistance at 100lux is 0.7kΩ
• Dark resistance after 1 sec is 0.03MΩ
• Dark resistance after 5 sec is 0.25MΩ

34 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
Working Principle: The Arduino continuously reads the analog voltage from the LDR. Based
on the voltage value, the Arduino calculates the corresponding resistance of the LDR. If the
resistance surpasses a predefined threshold, indicating low light intensity, the Arduino activates
the LED by setting the corresponding digital pin to HIGH, thereby turning on the LED. This
process ensures that the LED is automatically turned on when the light intensity in the room
drops below the specified level.
Circuit Diagram:

Code:
const int ldrPin = A0; // LDR connected to analog pin A0
const int ledPin = 13; // LED connected to digital pin 13

void setup() {
pinMode(ledPin, OUTPUT); // Set LED pin as output
}

void loop() {
int ldrValue = analogRead(ldrPin); // Read LDR value (0-1023)

35 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
// Check if it's dark (adjust threshold as needed)
if (ldrValue < 500) {
digitalWrite(ledPin, HIGH); // Turn on LED
} else {
digitalWrite(ledPin, LOW); // Turn off LED
}
}
Result: Upon running the experiment, the Arduino Uno R3 continuously monitors the ambient
light intensity using the LDR. When the light intensity in the room drops below the predefined
threshold (500 in this case), indicating darkness, the Arduino activates the LED, providing
illumination. Conversely, when the light intensity increases above the threshold, the Arduino
turns off the LED, ensuring efficient energy usage and automatic lighting control based on
ambient light conditions. Adjust the threshold value (500 in this case) as needed for your
specific application.

36 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
EXPERIMENT-6(C)
Aim: To create a light-dependent LED system that turns on two LEDs when the light intensity
in the room drops below a certain level and activates another two LEDs when the light intensity
rises above a certain level. Additionally, when the intensity level changes, all four LEDs will
blink three times, signaling the transition, before returning to the initial state.
Apparatus Required:
1. Arduino Uno R3 board
2. LDR (Light Dependent Resistor)
3. Four LEDs (Light Emitting Diodes)
4. Resistors (220-330 ohms)
5. Breadboard
6. Jumper wires
7. Power source (USB cable or battery)
Theory:
An LDR, or Light Dependent Resistor, belongs to a class of semiconductors whose resistance
varies in response to incident light. Composed of a photoconductive material, typically
cadmium sulfide (CdS) or lead sulfide (PbS), LDRs exhibit higher resistance in darkness due to
minimal photon excitation. When illuminated, photons energize the semiconductor's valence
electrons, reducing the band gap and allowing more current flow, thus lowering the resistance.
This unique property renders LDRs ideal for light sensing applications, including ambient light
detection, dusk-to-dawn switches, and camera exposure control. Their spectral response,
operating temperature range, and dynamic resistance characteristics vary based on material
composition and manufacturing processes. Through voltage divider configurations, LDRs can
translate light intensity into measurable electrical signals, facilitating their integration with
microcontrollers for light-dependent control systems.
Specification:
• Maximum power dissipation is 200mW
• The maximum voltage at 0 lux is 200V
• The peak wavelength is 600nm
• Minimum resistance at 10lux is 1.8kΩ

37 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
• Maximum resistance at 10lux is 4.5kΩ
• Typical resistance at 100lux is 0.7kΩ
• Dark resistance after 1 sec is 0.03MΩ
• Dark resistance after 5 sec is 0.25MΩ

Circuit Diagram:

Code:
// Define LDR pin
const int ldrPin = A0;

// Define LED pins


const int ledAbove1 = 2;
const int ledAbove2 = 3;
const int ledBelow1 = 4;
const int ledBelow2 = 5;

int currentIntensityLevel = 0; // Current intensity level, 0 for below, 1 for above


int previousIntensityLevel = 0; // Previous intensity level

38 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)

void setup() {
// Set LED pins as output
pinMode(ledAbove1, OUTPUT);
pinMode(ledAbove2, OUTPUT);
pinMode(ledBelow1, OUTPUT);
pinMode(ledBelow2, OUTPUT);
}

void loop() {
int ldrValue = analogRead(ldrPin); // Read LDR value (0-1023)

// Check if it's above or below certain intensity level


if (ldrValue > 500) {
currentIntensityLevel = 1; // Above certain level
} else {
currentIntensityLevel = 0; // Below certain level
}

// If intensity level changes, blink all LEDs and reset to initial position
if (currentIntensityLevel != previousIntensityLevel) {
blinkAllLEDs(); // Blink all LEDs
previousIntensityLevel = currentIntensityLevel; // Update previous intensity level
}

// Turn on LEDs based on intensity level


if (currentIntensityLevel == 1) {
39 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
digitalWrite(ledAbove1, HIGH);
digitalWrite(ledAbove2, HIGH);
digitalWrite(ledBelow1, LOW);
digitalWrite(ledBelow2, LOW);
} else {
digitalWrite(ledAbove1, LOW);
digitalWrite(ledAbove2, LOW);
digitalWrite(ledBelow1, HIGH);
digitalWrite(ledBelow2, HIGH);
}
}

// Function to blink all LEDs


void blinkAllLEDs() {
// Blink all LEDs for three times
for (int i = 0; i < 3; i++) {
// Turn on all LEDs
digitalWrite(ledAbove1, HIGH);
digitalWrite(ledAbove2, HIGH);
digitalWrite(ledBelow1, HIGH);
digitalWrite(ledBelow2, HIGH);
delay(500); // Wait for 500 milliseconds
// Turn off all LEDs
digitalWrite(ledAbove1, LOW);
digitalWrite(ledAbove2, LOW);
digitalWrite(ledBelow1, LOW);
digitalWrite(ledBelow2, LOW);
40 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
delay(500); // Wait for 500 milliseconds
}
}
Working Principle:
The Arduino continuously reads the analog voltage from the LDR. Based on the voltage value,
it determines the current intensity level. If the light intensity is below a certain threshold,
indicating darkness, it activates two LEDs connected to indicate this condition. Conversely, if
the light intensity exceeds another threshold, indicating brightness, it activates two different
LEDs to represent this state. Whenever the intensity level changes, all four LEDs blink three
times to indicate the transition before returning to the initial state.
Result: Upon execution of the experiment, observe the LEDs' behavior:
• If the ambient light intensity drops below the predefined threshold, two LEDs indicate
this condition by turning on.
• If the ambient light intensity rises above another predefined threshold, another two LEDs
indicate this by turning on.
• Whenever the intensity level changes, all four LEDs will blink three times to signal the
transition before returning to the initial state.

EXPERIMENT-7
Aim: To study about PIR sensor and its technical specifications and blink led upon detecting
motion.

Theory:
PIR (passive infrared) sensors utilise the detection of infrared that is radiated from all objects
that emit heat. This type of emission is not visible to the human eye, but sensors that operate
using infrared wavelengths can detect such activity. They are sometimes referred to as ‘motion-

41 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
based detectors’, as they sense the presence of people, animals and objects through the
movement of their infrared wavelengths.
They are referred to as “passive” due to the fact that no heat or energy is emitted by the sensor
itself. It is also important to remember that PIR sensors detect the emission of infrared
radiation, and not heat.

The HC-SR501 PIR Motion Sensor is a highly versatile and widely used device in the world of
electronics and home automation. It is a passive infrared sensor that is designed to detect
motion by measuring changes in infrared (heat) radiation levels within its field of view. When a
person or object moves within its range, the sensor will trigger an output signal, which can be
used to control various devices and systems.

The HC-SR501 is simple to use and requires only a few wires to connect to a microcontroller,
such as an Arduino or Raspberry Pi. It is also highly adjustable, with potentiometers that allow
users to adjust its sensitivity, trigger time, and LED indication. This makes it a great choice for
a wide range of projects, including security systems, light automation, and robotics.

PIR Sensor with Pinout


This HC-SR501 PIR sensor module has three output pins Vcc, Output and Ground as shown in
the pin diagram above. Since the output pin is 3.3V TTL logic it can be used with any platforms
like Arduino.

PIR Sensor Module Pinout Configuration

Pin Pin Description


Number Name

42 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)

1 Vcc Input voltage is +5V for typical applications. Can range from
4.5V- 12V

2 High/Low Digital pulse high (3.3V) when triggered (motion detected)


Ouput digital low(0V) when idle(no motion detected
(Dout)

3 Ground Connected to ground of circuit

Features:

1. Infrared Sensor with Control Circuit Board


2. The Sensitivity and Holding Time are adjustable.
3. Blockade time: 2.5s (Default)
4. Sensitive Setting: Turn to Right, Distance Increases (About 7M); Turn to Left, Distance
Reduce (About 3M)
5. Time Setting: Turn to Right, Time Increases (About 200S); Turn to Left, Time Reduce
(About 5S).

Technical Specifications:

• Wide range on input voltage varying from 4.V to 12V (+5V recommended)
• Output voltage is High/Low (3.3V TTL)
• Can distinguish between object movement and human movement
• Has to operating modes - Repeatable(H) and Non- Repeatable(H)
• Cover distance of about 120° and 7 meters
• Low power consumption of 65mA
• Operating temperature from -20° to +80° Celsius
• Distance Measuring Range (cm) from 300 to 700
• Dimensions (mm) LxWxH 32 x 24 x 18
• Detection Angle less than 140°
Working of PIR Motion Sensor
The PIR sensor module can be powered from voltage 4.5V to 20V but, typically 5V is used.
Once the module is powered allow the module to calibrate itself for few minutes, 2 minutes is a
well settled time. Then observe the output on the output pin. Before we analyse the output we
43 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
need to know that there are two operating modes in this sensor such as Repeatable(H) and Non -
Repeatable(L) and mode. The Repeatable mode is the default mode.
The output of the sensor can be set by shorting any two pins on the left of the module as shown
below. You can also notice two orange colour potentiometers that can be used to set the
sensitivity and time which will be explained further below.

Repeatable(H) mode
In Repeatable (H) mode the output pin Dout will go high (3.3V) when a person is detected
within range and goes low after a particular time (time is set by “Off time control”
potentiometer). In this mode the output pin will go high irrespective of whether the person is
still present inside the range or has left the area. The sensitivity can be set using the “sensitivity
control” potentiometer
Non- Repeatable(L) mode
In “I” mode the output pin Dout will go high (3.3V) when a person is detected within range
and will stay high as long as he/she stays within the limit of the Sensors range. Once the person
has left the area the pin will go low after the particular time which can be set using the
potentiometer. The sensitivity can be set using the “sensitivity control” potentiometer

There are two important materials present in the sensor one is the pyroelectric crystal which can
detect the heat signatures from a living organism (humans/animals) and the other is a Fresnel
44 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
lenses which can widen the range of the sensor. Yes the white colour things is just a lense that is
used to widen the range of the sensor, if you remove the lense you can find the Pyroelectric
sensor inside it covered inside a protective metal casing as shown above.
PIR Sensor Applications:
• Automatic Street/Garage/Warehouse or Garden Lights
• Burglar Alarms
• Security cams as motion detectors
• Industrial Automation Control

Circuit Diagram:

CODE:
#define motion_sensor A6
#define relay 5
void setup() {
Serial.begin(9600);
pinMode(motion_sensor, INPUT);
pinMode(relay, OUTPUT);
}
void loop() {
int sensor_value = analogRead(A6);
Serial.println(analogRead(A6));
45 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
if (sensor_value > 300) {
Serial.printIn("Motion detected; lights turned on");
digitalWrite(relay, HIGH)
:
}
Else {
Serial.printIn("Motion not detected\n");
digitalWrite(relay, LOW);
}
}

RESULT: Hence LED blinks when motion is detected.

46 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
EXPERIMENT – 8
Aim: To study about Home Automation and LPG, Smoke and Fire Sensor.
Software: Arduino IDE
Hardware Board: Arduino Uno
Apparatus Required:
Home Automation Kit
MQ6 LPG Sensor
MQ2 Smoke Sensor
MQ6 Fire Sensor
Power source (USB cable or battery)

Theory:

Home automation refers to the integration of smart technologies into residential settings to
automate and control various aspects of the home environment. This includes lighting, heating,
ventilation, air conditioning (HVAC), security systems, entertainment systems, and more. Using
sensors, actuators, and internet connectivity, homeowners can remotely monitor and manage their
homes from anywhere with an internet connection, using smartphones, tablets, or computers.
One of the key benefits of home automation is increased convenience and efficiency. With
automated systems, tasks such as adjusting the thermostat, turning lights on and off, or even
locking doors can be done automatically or with simple voice commands, saving time and effort
for homeowners. Additionally, automation can lead to energy savings by optimizing the use of
utilities and reducing unnecessary consumption.

Moreover, home automation enhances safety and security. Smart security cameras, motion
sensors, and door/window sensors can alert homeowners to potential intruders or hazards, while
smart locks and surveillance systems offer remote access and monitoring capabilities. By
providing real-time alerts and the ability to respond promptly to emergencies, home automation
helps homeowners protect their property and loved ones, offering peace of mind even when they
are away from home.

47 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)

Home Automation Kit

1. MQ-6 LPG Sensor


This is a simple to use LPG Gas Sensor (MQ-6), which can be used to detect the presence of
combustible gases, mainly is propane and butane, in the air. The sensor has a simple analog output
and needs no additional complex circuitry to get it working. Just power the sensor with 5V, add
a load resistor, and you will get an analog output corresponding to the concentration of LPG gas.

MQ-6 LPG Sensor Specifications


• Sensor TypeSemiconductor
• Standard Encapsulation Bakelite, Metal cap
• Target Gas LPG, CH4
• Detection range 300~10000ppm(CH4,C3H8)
48 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
• Standard Circuit Conditions Loop Voltage Vcc 5.0V±0.1V DC
• Heater Voltage VH 5.0V±0.1V AC or DC
• Load resistance RL Adjustable
Sensor character under standard test conditions
• Heater Resistance RH 30Ω±3Ω (Room Temp.)
• Heater consumption PH ≤950mW
• Sensitivity S Rs(in air)/Rs( in 2000ppm C3H8)≥5
• Output Voltage Vs 2.5V~4.0V (in 2000ppm C3H8)
• Concentration Slope α ≤0.6(R3000ppm/R1000ppm C3H8)
• Standard test conditionsTemp. Humidity 20℃±2℃;55%±5%RH
• Standard test circuit Vc:5.0V±0.1V VH:5.0V±0.1V
• Preheat timeNot less than 48 hours
• O2content 21%(No less than 18%) O2 concentration effects initial value,
sensitivity, and repeatability.
• Life span 10 years
• The LPG gas sensor is also used to detect cigarette smoke, toxic gases, combustible,
propane, iso-butane, and LNG.
Description:
Step 1:- Connect a DIN connector from DIN port "A" of Scientech 6205SSG to DIN port "A"
of Scientech 6205SB (for LPG sensor).
Step 2:- Switch on the power button of Scientech 6205 SSG and Scientech 6205 SB and
connect USB cable on Scientech 6205SSG
Step 3:- Open code Assignment_7_LPG_Smoke_Fire_sensor.ino
Step 4:- Select Board Arduino mega from "Tools->Board -> Arduino mega".
Step 5:- Select the COM-port from "Tools->Port -> .
Step 6:- Upload the Code in Arduino board by pressing Right arrow upload button from top
Left Corner.
Step 7:- Open Serial Monitor.

Code:

#define LPG_sensor A0 //define pin for LPG sensor


#define ROOM_LIGHT 2
#define HORN A14
int sensor_value;
int analog_value;
void setup() {
Serial.begin(9600); //set baud rate
//configure pins to be read as input

49 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
pinMode(LPG_sensor, INPUT);
pinMode(ROOM_LIGHT, OUTPUT);
}

void loop() {
int lpg = analogRead(A0);
float analog_value1 = lpg * (5.0 / 1023.0);
Serial.println("LPG concentration in air is");
float converted_value = (analog_value1 * 1000);
Serial.println(converted_value);
delay(2000);
if (converted_value > 3000) {
digitalWrite(ROOM_LIGHT, LOW);
digitalWrite(HORN, HIGH);
} else {
digitalWrite(ROOM_LIGHT, HIGH);
digitalWrite(HORN, LOW);
}
}

2. MQ-2 Smoke Sensor


Smoke Detector is the main sensing device in Fire Alarm Equipment System. To understand the
basic working principle of smoke detector, we should remember Ionization and Photoelectric
structure, smoke detectors are manufactured basically based on these two principles. According
to these rules there are mainly two basic types of Smoke Detector, you will find in the market.
Ionization Smoke Detector Photoelectric Smoke Detector

MQ-2 Smoke Sensor Specifications


50 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
• Operating Voltage: Typically operates at 5V DC.
• Detection Range: Detection range varies depending on the gas being detected. For
example:
LPG: 200-10,000 ppm
Propane: 100-10,000 ppm
Hydrogen: 1-1,000 ppm
Carbon Monoxide: 10-1,000 ppm
• Sensitivity Adjustment: Often equipped with a potentiometer to adjust sensitivity.
• Warm-up Time: Requires a certain warm-up time (usually a few minutes) before accurate
readings can be obtained.
• Operating Temperature Range: Typically operates within a range of -10°C to 50°C.
• Operating Humidity Range: Works within a relative humidity range, commonly around
20%-90% RH.
• Output Signal: Analog output voltage proportional to the concentration of the detected
gas.
• Response Time: Time taken to detect changes in gas concentration.
• Recovery Time: Time taken to return to baseline after exposure to a gas.
• Dimensions: Physical dimensions of the sensor module.
• Power Consumption: Amount of power consumed during operation.
• Operating Principle: Based on the variation of conductivity of its sensing material when
exposed to different gases.
• Cross-Sensitivity: Potential for interference from other gases.
• Lifetime: Typically specified in terms of the number of hours of continuous use.

Description:
Step 1:- Connect a DIN connector from DIN port "B" of Scientech 6205SSG to DIN port "B"
of Scientech 6205SB (for Smoke sensor).
Step 2:- Switch on the power button of Scientech 6205 SSG and Scientech 6205 SB and
connect USB cable on Scientech 6205SSG
Step 3:- Open code Assignment_8_relay_lights.ino
Step 4:- Select Board Arduino mega from "Tools->Board -> Arduino mega".
Step 5:- Select the COM-port from "Tools->Port -> .
Step 6:- Upload the Code in Arduino board by pressing Right arrow upload button from top
Left Corner.
Step 7:- Open Serial Monitor.

51 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
Code:

int lights = 3; //define pin for lights


int smoke = A2; //define pin for smoke sensor

void setup() {
//configure sensor pin as input and lights as output
pinMode(smoke, INPUT);
pinMode(lights, OUTPUT);
Serial.begin(9600); //set baud rate
}

void loop() {
int Sensor = analogRead(A2); //read smoke sensor
Serial.println(Sensor); //print value of sensor
if (Sensor >= 300) {
digitalWrite(lights, HIGH);
Serial.println("Smoke detected"); //if value of sensor is above 250 lights are tuned on
and message is displayed on serial monitor
} else {
digitalWrite(lights, LOW); //if value of smoke sensor is below 400 lights are not turned
on
}
delay(2500);
}

3. MQ-2 Fire Sensor


A flame-sensor is one kind of detector which is mainly designed for detecting as well as
responding to the occurrence of a fire or flame. The flame detection response can depend on its
fitting. It includes an alarm system, a natural gas line, propane & a fire suppression system. This
sensor is used in industrial boilers. The main function of this is to give authentication whether
the boiler is properly working or not. The response of these sensors is faster as well as more
accurate compare with a heat/smoke detector because of its mechanism while detecting the flame.

52 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)

MQ-2 Features
• Photosensitivity is high.
• Response time is fast.
• Simple to use.
• Sensitivity is adjustable
• Detection angle is 600,
• It is responsive to the flame range.
• Accuracy can be adjustable
• Operating voltage of this sensor is 3.3V to 5V
• Analog voltage o/ps and digital switch o/ps
• The PCB size is 3cm X 1.6cm
• Power indicator & digital switch o/p indicator
• If the flame intensity is lighter within 0.8m then the flame test can be activated, if the
flame intensity is high, then the detection of distance will be improved.
Description:
Step 1:- Connect a DIN connector from DIN port "E" of Scientech 6205SSG to DIN port "C"
of Scientech 6205SB (for Smoke sensor).
Step 2:- Connect a patch chord from pin 1 to buzzer pin of Scientech 6205 SSG.
Step 3:- Switch on the power button of Scientech 6205 SSG and Scientech 6205 SB and
connect USB cable on Scientech 6205SSG
Step 4:- Open code Assignment_9_fire_horn.ino
Step 5:- Select the COM-port from "Tools->Port -> .
Step 6:- Upload the Code in Arduino board by pressing Right arrow upload button from top
Left Corner.
Step 7:- Open Serial Monitor.

53 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
Code:

#define fire A8 //define pin for fire sensor


#define lights 20 //define pin for lights
#define alarm A14 //define pin for horn

void setup() {
//configure sensor pin as input and lights and horn as output
pinMode(fire, INPUT);
pinMode(lights, OUTPUT);
pinMode(alarm, OUTPUT);
Serial.begin(9600); //set baud rate
}

void loop() {
int Sensor = digitalRead(A8); //read Fire sensor
Serial.println(Sensor);
if (Sensor == 1) {
digitalWrite(lights, HIGH); //if fire sensor sends a high , turn on the lights
digitalWrite(alarm, LOW); //if fire sensor sends a high , turn on the horn
Serial.println("everything is fine"); //print message
} else {
digitalWrite(lights, LOW); //if fire sensor sends a low turn off lights
digitalWrite(alarm, HIGH); //if fire sensor sends a low turn off horn
Serial.println("FIRE detected"); //print mesage
}
delay(2000);
}

54 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
EXPERIMENT - 9
Aim: To study about Home Automation and PIR, Temperature and CO 2 Sensor.
Software: Arduino IDE
Hardware Board: Arduino Uno
Apparatus Required:
Home Automation Kit
PIR Sensor
LM 35 (Temperature Sensor)
MQ2 Gas Sensor
Power source (USB cable or battery)
Theory:

1) PIR Motion Sensor


Passive infrared (PIR) sensors use a pair of pyroelectric sensors to detect heat energy in the
surrounding environment. These two sensors sit beside each other, and when the signal
differential between the two sensors changes (if a person enters the room, for example), the sensor
will engage. That may mean it triggers an alarm, notifies authorities, or maybe turns on a
floodlight. IR radiation focuses on each of the two pyroelectric sensors using a series of lenses
constructed as the sensor’s housing. These lenses widen the device’s sensing area.

55 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)

PIR Sensor Specifications


• Input Voltage DC 4.5V ~ 20V
• Static Current <50uA
• Output Signal 0V / 3V (Output high when motion detected)
• Sensing Range 7 meters (120-degree cone)
• Delay time 8s ~ 200s (adjustable)
• Operating Temperature -15℃ ~ +70℃
• Dimensions 24mm*32mm*25mm (Height with lens)
• Weight 6.6g
Description:
Step 1:- Connect a DIN connector from DIN port "D" of Scientech 6205SSG to DIN port "D"
of Scientech 6205SB.
Step 2:- Switch on the power button of Scientech 6205 SSG and Scientech 6205 SB and
connect USB cable on Scientech 6205SSG
Step 3:- Open code Assignment_4_PIR_sensor.ino
Step 4:- Select Board Arduino mega from "Tools->Board -> Arduino mega".
Step 5:- Select the COM-port from "Tools->Port -> .
Step 6:- Upload the Code in Arduino board by pressing Right arrow upload button from top
Left Corner.
Step 7:- Open Serial Monitor.

Code:

#define motion_sensor A6
#define relay 5 //define pin on which motion sensor is connected

56 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
void setup() {
Serial.begin(9600); //setting baud rate
pinMode(motion_sensor, INPUT); //setting motion sensor pin as a input
pinMode(relay, OUTPUT);
}

void loop() {
int sensor_value = analogRead(A6); //reading the digital value from
Serial.println(analogRead(A6));
if (sensor_value > 300) //condition
{
Serial.println("Motion detected; lights turned on");
digitalWrite(relay, HIGH);

} else {
Serial.println("Motion not detected\n");
digitalWrite(relay, LOW);
}
}

2) Temperature Sensor (LM 35)


A temperature sensor is a device used to measure temperature. This can be air temperature, liquid
temperature, or the temperature of solid matter. There are different types of temperature sensors
available, and they each use different technologies and principles to take the
temperature measurement.

57 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
Temperature Sensor(LM-35) Specifications
• Range-55°-150°C
• Accuracy < 0,1°C + NTC-spread over 0°...70°C
• Resolution 2 m°C@30°C and 25 m°C@100°C
• No. Sensors1....30
• Type 5 kOhm NTC-resistors
• Max. wire resistance 3,3 Ohm
• Conditioner Wheatstone-bridge with +15 Bits ADC
• Calibration at 0°C and 100°C _ 0,1°C
• Drift 1 m°C/°C with periodic calibration and 5 m°C/°C without calibration
• Scan freq. default max. 10 meas./s
• Amb.temp 0°...60°
• Control Micro-WireTM 5 (Di, Do, Clk en CS)
• Levels 0 and 5 Volt
• Power+12 Volt 3,5 mAmp (+5,5 .... +20 Volt)
• -5 Volt 1 mAmp (-4,5 ....-8 Volt)
• Dimensions 224 x 120 x 60 + 40 mm
Description:
Step 1:- Connect a DIN connector from DIN port "C" of Scientech 6205SSG to DIN port "E"
of Scientech 6205SB.

58 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
Step 2:- Switch on the power button of Scientech 6205 SSG and Scientech 6205 SB and
connect USB cable on Scientech 6205SSG
Step 3:- Open code Assignment_temperature_humidity.ino
Step 4:- Select Board Arduino mega from "Tools->Board -> Arduino mega".
Step 5:- Select the COM-port from "Tools->Port -> .
Step 6:- Upload the Code in Arduino board by pressing Right arrow upload button from top
Left Corner.
Step 7:- Open Serial Monitor.

Code:

#define led = 12;


#define sensorPin A0;

void setup() {
pinMode(led, OUTPUT);
pinMode(SensorPin, INPUT);
Serial.begin(9600);
}

void loop() {
int reading = analogRead(sensorPin);
float voltage = reading * (5.0 / 1024.0);
float tempc = (tempc * 1.8) + 32;

Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");

if (temperature > 25) {


digitalWrite(led, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
} else {
digitalWrite(ledPin, LOW);
}
}

3) CO2 Sensor
CO2 sensor definition is an instrument that is used to detect the CO2 gas content in the air, or its
surroundings is known as a carbon dioxide sensor. Once the instrument detects the CO2 gas
content then it generates an alarm so that appropriate action can be taken by the people. This type
59 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
of sensor plays an essential role in making a good atmospheric situation for the public. The
application areas of CO2 sensors mainly include different industries like carbonated beverage
beer, coal, agricultural planting, agricultural breeding & the daily life of people.

CO2 Sensor Specifications


• Measurement range: 0-5000 ppm
• Accuracy: ±(50 ppm + 3% of reading)
• Response time: <2 minutes (90% step change)
• Warm-up time: <2 minutes
• Operating temperature range: 0-50°C
• Operating humidity range: 0-95% RH non-condensing
• Communication interface: UART (RS-232), I2C, PWM, analog voltage
• Power supply: 4.75-5.25V DC
• Power consumption: <50 mA (continuous operation)
Description:
Step 1:- Connect a DIN connector from DIN port "F" of Scientech 6205SSG to DIN port "F" of
Scientech 6205SB.
Step 2:- Switch on the power button of Scientech 6205 SSG and Scientech 6205 SB and
connect USB cable on Scientech 6205SSG
Step 3:- Open code Assignment_6_CO2_sensor.ino
Step 4:- Select Board Arduino mega from "Tools->Board -> Arduino mega".
Step 5:- Select the COM-port from "Tools->Port -> .

60 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
Step 6:- Upload the Code in Arduino board by pressing Right arrow upload button from top
Left Corner.
Step 7:- Open Serial Monitor.

Code:

#define pwmPin A9
int prevVal = LOW;
long th, tl, h, l, ppm;

void setup() {
Serial.begin(9600);
pinMode(pwmPin, INPUT);
}

void loop() {
long tt = millis();
int myVal = digitalRead(pwmPin);
if (myVal == HIGH) {
// digitalWrite(LedPin, HIGH);
if (myVal != prevVal) {
h = tt;
tl = h - l;
prevVal = myVal;
}
} else {

if (myVal != prevVal) {
l = tt;
th = l - h;
prevVal = myVal;
ppm = 5000 * (th - 2) / (th + tl - 4);
if (ppm > 1000 && ppm < 4800) {
Serial.println("Co2 = " + String(ppm));
}
}
}
}

61 | P a g e

You might also like