Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I_Helmet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
21_22-J 62
I_Helmet
Commits
50683c0e
Commit
50683c0e
authored
Apr 27, 2022
by
DESKTOP-95L9KLS\Sandun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MQ8 gas sensor
parent
8eebe9c6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
78 additions
and
0 deletions
+78
-0
IT18203172/MQ-8_Sensor/MQ-8_Sensor.ino
IT18203172/MQ-8_Sensor/MQ-8_Sensor.ino
+78
-0
No files found.
IT18203172/MQ-8_Sensor/MQ-8_Sensor.ino
0 → 100644
View file @
50683c0e
#define MQ_PIN (0)
#define RL_VALUE (10)
#define RO_CLEAN_AIR_FACTOR (9.21)
#define CALIBARAION_SAMPLE_TIMES (50)
#define CALIBRATION_SAMPLE_INTERVAL (500)
#define READ_SAMPLE_INTERVAL (50)
#define READ_SAMPLE_TIMES (5)
#define GAS_H2 (0)
float
H2Curve
[
3
]
=
{
2.3
,
0.93
,
-
1.44
};
float
Ro
=
10
;
void
setup
()
{
Serial
.
begin
(
9600
);
Serial
.
print
(
"Calibrating...
\n
"
);
Ro
=
MQCalibration
(
MQ_PIN
);
Serial
.
print
(
"Calibration is done...
\n
"
);
Serial
.
print
(
"Ro="
);
Serial
.
print
(
Ro
);
Serial
.
print
(
"kohm"
);
Serial
.
print
(
"
\n
"
);
}
void
loop
()
{
Serial
.
print
(
"H2 Concentration:"
);
Serial
.
print
(
MQGetGasPercentage
(
MQRead
(
MQ_PIN
)
/
Ro
,
GAS_H2
)
);
Serial
.
print
(
"ppm"
);
Serial
.
print
(
"
\n
"
);
delay
(
200
);
}
float
MQResistanceCalculation
(
int
raw_adc
)
{
return
(
((
float
)
RL_VALUE
*
(
1023
-
raw_adc
)
/
raw_adc
));
}
float
MQCalibration
(
int
mq_pin
)
{
int
i
;
float
val
=
0
;
for
(
i
=
0
;
i
<
CALIBARAION_SAMPLE_TIMES
;
i
++
)
{
val
+=
MQResistanceCalculation
(
analogRead
(
mq_pin
));
delay
(
CALIBRATION_SAMPLE_INTERVAL
);
}
val
=
val
/
CALIBARAION_SAMPLE_TIMES
;
val
=
val
/
RO_CLEAN_AIR_FACTOR
;
return
val
;
}
float
MQRead
(
int
mq_pin
)
{
int
i
;
float
rs
=
0
;
for
(
i
=
0
;
i
<
READ_SAMPLE_TIMES
;
i
++
)
{
rs
+=
MQResistanceCalculation
(
analogRead
(
mq_pin
));
delay
(
READ_SAMPLE_INTERVAL
);
}
rs
=
rs
/
READ_SAMPLE_TIMES
;
return
rs
;
}
int
MQGetGasPercentage
(
float
rs_ro_ratio
,
int
gas_id
)
{
if
(
gas_id
==
GAS_H2
)
{
return
MQGetPercentage
(
rs_ro_ratio
,
H2Curve
);
}
return
0
;
}
int
MQGetPercentage
(
float
rs_ro_ratio
,
float
*
pcurve
)
{
return
(
pow
(
10
,(
((
log
(
rs_ro_ratio
)
-
pcurve
[
1
])
/
pcurve
[
2
])
+
pcurve
[
0
])));
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment