Understanding A Gas Sensor - Jaycon Systems
Understanding A Gas Sensor - Jaycon Systems
Even though the sensor has six pins in total, pins A and
pins B are connected together, leaving us with four
connections.
Calculations
V = I x R
I = V / R
I = VC / (RS+RL)
V = I x R
VRL = [VC / (RS + RL)] x RL
VRL = (VC x RL) / (RS + RL)
RS / R0 = 4.4 ppm
First of all, we will treat the lines as if they were linear. This
way we can use one formula that linearly relates the ratio
and the concentration. By doing so, we can find the
concentration of a gas at any ratio value even outside of
the graph’s boundaries. The formula we will be using is the
equation for a line, but for a log-log scale. The formula for
a line is:
y = mx + b
Where:
y: X value
x: X value
m: Slope of the line
b: Y intercept
log(y) = m*log(x) + b
m = log(y/y0) / log(x/x0)
m = log(0.75/2.6) / log(10000/200)
m = -0.318
log(y) = m*log(x) + b
b = log(y) - m*log(x)
b = log(0.9) - (-0.318)*log(5000)
b = 1.13
log(x) = [log(y) - b] / m
x = 10 ^ {[log(y) - b] / m}
If you are not sure how logarithms work, you can refer to
this link:
•
http://www.rapidtables.com/math/algebra/Logarithm.
htm
Materials
• 10 Kohm Resistor
• Red LED
• Buzzer
• Wires
• Protoboard
Wiring
Solder some wires to the gas sensor’s pins and add heat
shrinking tubing:
A VCC
B Pin A0
H VCC
H GND
SDA Pin 4
SCL Pin 5
RES Pin 11
GND GND
VCC VCC
Code to Calculate R0
Code to Calculate R0
void setup() {
Serial.begin(9600); //Baud rate
}
void loop() {
float sensor_volt; //Define variable for sensor
float RS_air; //Define variable for sensor resis
float R0; //Define variable for R0
float sensorValue; //Define variable for analog
for(int x = 0 ; x < 500 ; x++) //Start for loop
{
sensorValue = sensorValue + analogRead(A0); //
}
sensorValue = sensorValue/500.0; //Take average
sensor_volt = sensorValue*(5.0/1023.0); //Conver
RS_air = ((5.0*10.0)/sensor_volt)-10.0; //Calcul
R0 = RS_air/4.4; //Calculate R0
Code Explanation
void setup() {
Serial.begin(9600); //Baud rate
}
void loop() {
float sensor_volt; //Define variable for sensor
float RS_air; //Define variable for sensor resis
float R0; //Define variable for R0
float sensorValue; //Define variable for analog
void setup() {
Serial.begin(9600); //Baud rate
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //Ini
display.setTextColor(WHITE); //Set text color
display.setTextSize(3); //Set text size
pinMode(led, OUTPUT); //Set LED as output
digitalWrite(led, LOW); //Turn LED off
pinMode(buzzer, OUTPUT); //Set buzzer as output
digitalWrite(buzzer, LOW); // Turn buzzer off
pinMode(gas_sensor, INPUT); //Set gas sensor as
}
void loop() {
display.clearDisplay(); //Clear display
display.setCursor(0,5); //Place cursor in (x,y)
float sensor_volt; //Define variable for sensor
float RS_gas; //Define variable for sensor resis
float ratio; //Define variable for ratio
float sensorValue = analogRead(gas_sensor); //Re
sensor_volt = sensorValue*(5.0/1023.0); //Conver
RS_gas = ((5.0*10.0)/sensor_volt)-10.0; //Get va
ratio = RS_gas/R0; // Get ratio RS_gas/RS_air
Code Explanation
• https://github.com/adafruit/Adafruit-GFX-Library
• https://github.com/adafruit/Adafruit_SSD1306
void setup() {
Serial.begin(9600); //Baud rate
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //Ini
display.setTextColor(WHITE); //Set text color
display.setTextSize(3); //Set text size
pinMode(led, OUTPUT); //Set LED as output
digitalWrite(led, LOW); //Turn LED off
pinMode(buzzer, OUTPUT); //Set buzzer as output
digitalWrite(buzzer, LOW); // Turn buzzer off
pinMode(gas_sensor, INPUT); //Set gas sensor as
}
void loop() {
display.clearDisplay(); //Clear display
display.setCursor(0,5); //Place curson in (x,y)
float sensor_volt; //Define variable for sensor
float RS_gas; //Define variable for sensor resis
float ratio; //Define variable for ratio
float sensorValue = analogRead(gas_sensor); //Re
sensor_volt = sensorValue*(5.0/1023.0); //Conver
RS_gas = ((5.0*10.0)/sensor_volt)-10.0; //Get va
ratio = RS_gas/R0; // Get ratio RS_gas/RS_air
Results
Gas Sensor
○ https://jayconsystems.com/blog/basic-5v-
power-supply
From every file, forum, document, datasheet, article, etc, over the internet
about MQ4 sensor, here (in this page) was the first place where most
information is treated with respect. Now I can definitely come to a
procedure to calibrate this MQ4 sensor. Thank you very much for the
contribution. Keep working hard!
PREVIOUS NEXT
Motion Sensor Detector Making a Mold
Tutorials Tutorials