Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

session 4 arduino

The document discusses gas sensors, specifically the MQ2 and MQ5 types, highlighting that MQ2 is superior due to its ability to detect gases like smoke. It explains the working principles, properties, and internal structure of the MQ2 gas sensor, as well as its applications and how to interface it with Arduino. Additionally, it covers ultrasonic sensors, particularly the HC-SR04, detailing its functionality and usage in distance measurement.

Uploaded by

anasmostafa801
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

session 4 arduino

The document discusses gas sensors, specifically the MQ2 and MQ5 types, highlighting that MQ2 is superior due to its ability to detect gases like smoke. It explains the working principles, properties, and internal structure of the MQ2 gas sensor, as well as its applications and how to interface it with Arduino. Additionally, it covers ultrasonic sensors, particularly the HC-SR04, detailing its functionality and usage in distance measurement.

Uploaded by

anasmostafa801
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Prepared by:

Esraa taha ali


Gas sensors
There are a two type of gas sensor that was
commonly used
1- MQ2
2-MQ5
Note:
MQ2 is better than MQ5 because it sense gases that can’t be
sensed by MQ5 like smoke .
What is MQ2 Gas Sensor?
MQ2 is one of the commonly used gas sensors in MQ sensor
series.
It is a Metal Oxide Semiconductor (MOS) type
Gas Sensor also known as Chemiresistors as the detection is
based upon change of resistance of the sensing material when
the Gas comes in contact with the material. Using a simple
voltage divider network, concentrations of gas can be detected.
Properties of MQ2
MQ2 Gas sensor works on 5V DC and
draws around 800mW. It can
detect LPG, Smoke, Alcohol, Propane,
Hydrogen, Methane and Carbon
Monoxide concentrations anywhere
from 200 to 10000ppm.
What is 1 ppm equal to?
When measuring gases like carbon dioxide, oxygen, or methane, •
the term concentration is used to describe the amount of gas by
volume in the air.
The 2 most common units of measurement are parts-per-million, •
and percent concentration.
Parts-per-million is the ratio of one gas to another. For example, •
1,000ppm of CO means that if you could count a million gas
molecules, 1,000 of them would be of carbon monoxide and
999,000 molecules would be some other gases
Internal structure of MQ2 Gas Sensor

when outer mesh is removed. •


The star-shaped structure is formed by the sensing element and six •
connecting legs .
Out of six, two leads (H) are responsible for heating the sensing element •
and are connected through Nickel-Chromium coil.
The remaining four leads (A & B) responsible for output signals are •
connected using Platinum Wires. These wires are connected to the body of
the sensing element and convey small changes in the current that passes
through the sensing element
How does a gas sensor work?
When tin dioxide (semiconductor particles) is heated in air at high •
temperature, oxygen is adsorbed on the surface.
In clean air, donor electrons in tin dioxide are attracted toward •
oxygen which is adsorbed on the surface of the sensing material.
This prevents electric current flow.
In the presence of reducing gases, the surface density of adsorbed •
oxygen decreases as it reacts with the reducing gases. Electrons
are then released into the tin dioxide, allowing current to flow freely
through the sensor .
MQ2 Gas Sensor Module
Since MQ2 Gas Sensor is not breadboard compatible, we do
recommend this handy little breakout board. It’s very easy to use and
comes with two different outputs. It not only provides a binary
indication of the presence of combustible gases but also an analog
representation of their concentration in air.
NOTE :
The analog output voltage provided by the
sensor changes in proportional to the
concentration of smoke/gas. The greater the
gas concentration, the higher is the output
voltage; while lesser gas concentration
results in low output voltage.
MQ2 Gas Sensor Module
The analog signal from MQ2 Gas sensor is further fed to
LM393 High Precision Comparator to digitize the signal.
Along with the comparator is a little potentiometer you can turn
to adjust the sensitivity of the sensor.
You can use it to adjust the concentration of gas at which the
sensor detects it.
MQ2 Gas Sensor Module Pinout

VCC supplies power for the module. You can connect it to 5V output •
from your Arduino.
GND is the Ground Pin and needs to be connected to GND pin on •
the Arduino •
provides a digital representation of the presence of combustible •
D0 gases.
A0 provides analog output voltage in proportional to the concentration •
of smoke/gas
First project

The first project is to Read a various


voltage from gas sensor and monitor
the out put values on a Serial monitor
If the digital value is greater than 300
“Print smoke is detected”.
Code
#define MQ2pin A0
float sensorValue;
void setup() {
Serial.begin(9600); }
void loop() {
sensorValue = analogRead(MQ2pin);
Serial.print("Sensor Value: ");
Serial.println(sensorValue);
if(sensorValue > 300) {
Serial.println(" | Smoke detected!"); }
delay(200);}
Proteus design
loops

a loop is used to repeat a block of code


until the specified condition is met
Types of loops
1-specific iterations As for loop
2- until event as while and do while
3-infinite loop
loops

1-For loop
2-While loop
3-do while loop
the syntax of for loop

For(initial value ;condition ;change in value ){


Statement ;
}
For loop flow chart
Initialization counter

Test
Expression

For loop body

Updatecounter
Second task

Code to display numbers from 0 to


1000 on serial monitor using for loop
Code

void setup() {
Serial.begin ( 9600);
for ( int i = 0 ; i <= 1000 ; i++ ){
Serial.println( i ) ;}
}
void loop() {
}
While loop
The syntax of While loop

While (condition){
Statement ;
}
While loop
Flow chart for while

Test •
Expression

While loop body


Application to use while

Arduino code

#define sw 6
#define led 5
int i=0 ;
void setup() {
Serial.begin (9600);
pinMode(sw,INPUT_PULLUP);
pinMode(led,OUTPUT);
}
void loop() {
while(digitalRead (sw)==LOW ){
digitalWrite (led,HIGH);}
digitalWrite (led,LOW);
Serial.println(i);
i++;}
Proteus design
Ultrasonic Sensor
HC-SR04 Ultrasonic Distance Sensor that can report the range
of objects up to 13 feet away( between 2 cm to 400). Which is
really good information to have if you’re trying to avoid your
robot driving into a wall!
They are low power.
HC-SR04 Hardware Overview
the HC-SR04 Ultrasonic distance sensor consists of •
two ultrasonic transducers. The one acts as a transmitter
which converts electrical signal into 40 KHz ultrasonic sound
pulses. The receiver listens for the transmitted pulses. If it
receives them it produces an output pulse whose width can
be used to determine the distance of the pulse travelled
What is Ultrasound?
Ultrasound is high-pitched sound waves with frequencies •
higher than the audible limit of human hearing.
Human ears can hear sound waves that vibrate in the range •
from about 20 times a second to about 20,000 times a
second.
HC-SR04 Ultrasonic Sensor Pinout

VCC VCC is the power supply for HC-SR04 Ultrasonic distance sensor •
which we connect the 5V pin on the Arduino.
Trig
(Trigger) pin is used to trigger the ultrasonic sound pulses. •

Echo
ECHO pin produces a pulse when the reflected signal is received. •
The length of the pulse is proportional to the time it took for the
transmitted signal to be detected.
GND
GND should be connected to the ground of Arduino
How Does HC-SR04 Ultrasonic Sensor Work

at all starts, when a pulse of at least 10 µS (10 microseconds)


in duration is applied to the Trigger pin. In response to that the
sensor transmits a sonic burst of eight pulses at 40 KHz.
The eight ultrasonic pulses travel through the air away from the
transmitter. Meanwhile the Echo pin goes HIGH to start forming
the beginning of the echo-back signal.
How Does HC-SR04 Ultrasonic
Sensor Work
In case, If those pulses are not reflected back
then the Echo signal will timeout after 38 mS
and return low. Thus a 38 mS pulse indicates
no obstruction within the range of the sensor.
.
ultrasonic calculation

speed of sound, of course! Its 350m/s


Fuction “pulseIn(echo,HIGH);”
Will return the time that the echo signal
stay high.
By using
Distance = Speed x Time
We can calculate the Distance.
Application to use Ultrasonic Sensor
#define trig 11
#define echo 12
int distance=0,t=0;
void setup() {
Serial.begin(9600);
pinMode(trig,OUTPUT);
pinMode(echo,INPUT);}
void loop()
{digitalWrite(trig,LOW);
delayMicroseconds(5);
digitalWrite(trig,HIGH);
delayMicroseconds(10);
digitalWrite(trig,LOW);
t=pulseIn(echo,HIGH);
distance=t/57;//Distance = (Speed of Sound * Time/2) = t/(1/((350*0.0001)/2))
Serial.println(distance);
delay(50);
Proteus design

You might also like