Skip to content

Commit c233734

Browse files
authoredOct 3, 2018
Add files via upload
1 parent 9b2d2ae commit c233734

File tree

3 files changed

+426
-0
lines changed

3 files changed

+426
-0
lines changed
 

‎LE_SUPER_PROGRAMME.ino

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
uint32_t SLEEP_TIME = 30000;
2+
float Ro = 10000.0;
3+
int val = 0;
4+
float valMQ =0.0;
5+
float lastMQ =0.0;
6+
float LPGCurve[3] = {2.3,0.21,-0.47};
7+
float COCurve[3] = {2.3,0.72,-0.34};
8+
float SmokeCurve[3] = {2.3,0.53,-0.44};
9+
10+
11+
void setup()
12+
{
13+
Ro = MQCalibration(
14+
A2); //Calibrating the sensor. Please make sure the sensor is in clean air
15+
}
16+
17+
void loop()
18+
{
19+
uint16_t valMQ = MQGetGasPercentage(MQRead(A2)/Ro,GAS_CO);
20+
Serial.println(val);
21+
22+
Serial.print("LPG:");
23+
Serial.print(MQGetGasPercentage(MQRead(A2)/Ro,GAS_LPG) );
24+
Serial.print( "ppm" );
25+
Serial.print(" ");
26+
Serial.print("CO:");
27+
Serial.print(MQGetGasPercentage(MQRead(A2)/Ro,GAS_CO) );
28+
Serial.print( "ppm" );
29+
Serial.print(" ");
30+
Serial.print("SMOKE:");
31+
Serial.print(MQGetGasPercentage(MQRead(A2)/Ro,GAS_SMOKE) );
32+
Serial.print( "ppm" );
33+
Serial.print("\n");
34+
35+
if (valMQ != lastMQ) {
36+
send(msg.set((int16_t)ceil(valMQ)));
37+
lastMQ = ceil(valMQ);
38+
}
39+
40+
sleep(SLEEP_TIME); //sleep for: sleepTime
41+
}
42+
43+
44+
float MQResistanceCalculation(int raw_adc)
45+
{
46+
return ( ((float)RL_VALUE*(1023-raw_adc)/raw_adc));
47+
}
48+
49+
50+
float MQCalibration(int mq_pin)
51+
{
52+
int i;
53+
float val=0;
54+
55+
for (i=0; i<CALIBARAION_SAMPLE_TIMES; i++) {
56+
val += MQResistanceCalculation(analogRead(A2));
57+
delay(CALIBRATION_SAMPLE_INTERVAL);
58+
}
59+
val = val/CALIBARAION_SAMPLE_TIMES;
60+
61+
val = val/RO_CLEAN_AIR_FACTOR;
62+
return val;
63+
}
64+
float MQRead(int mq_pin)
65+
{
66+
int i;
67+
float rs=0;
68+
69+
for (i=0; i<READ_SAMPLE_TIMES; i++) {
70+
rs += MQResistanceCalculation(analogRead(A2));
71+
delay(READ_SAMPLE_INTERVAL);
72+
}
73+
74+
rs = rs/READ_SAMPLE_TIMES;
75+
76+
return rs;
77+
}
78+
79+
80+
int MQGetGasPercentage(float rs_ro_ratio, int gas_id)
81+
{
82+
if ( gas_id == GAS_LPG ) {
83+
return MQGetPercentage(rs_ro_ratio,LPGCurve);
84+
} else if ( gas_id == GAS_CO ) {
85+
return MQGetPercentage(rs_ro_ratio,COCurve);
86+
} else if ( gas_id == GAS_SMOKE ) {
87+
return MQGetPercentage(rs_ro_ratio,SmokeCurve);
88+
}
89+
90+
return 0;
91+
}
92+
93+
int MQGetPercentage(float rs_ro_ratio, float *pcurve)
94+
{
95+
return (pow(10,( ((log(rs_ro_ratio)-pcurve[1])/pcurve[2]) + pcurve[0])));
96+
}

‎Mh_Z19b.ino

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//The pulseIn Function
2+
byte PWM_PIN = 3;
3+
4+
int pwm_value;
5+
6+
void setup() {
7+
pinMode(PWM_PIN, INPUT);
8+
Serial.begin(115200);
9+
}
10+
11+
void loop() {
12+
pwm_value = pulseIn(PWM_PIN, HIGH);
13+
Serial.println(pwm_value);
14+
delay(1000);
15+
16+
}

0 commit comments

Comments
 (0)
Please sign in to comment.