mirror of
https://github.com/miguel5612/MQSensorsLib.git
synced 2025-03-15 05:17:30 +03:00
Updated examples (Issue 26)
This commit is contained in:
parent
a906388c5c
commit
b9a5e62899
@ -31,14 +31,16 @@
|
|||||||
#define type "MQ-309" //MQ309
|
#define type "MQ-309" //MQ309
|
||||||
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
|
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
|
||||||
#define RatioMQ309CleanAir 11 //RS / R0 = 11 ppm
|
#define RatioMQ309CleanAir 11 //RS / R0 = 11 ppm
|
||||||
//#define calibration_button 13 //Pin to calibrate your sensor
|
#define PWMPin 5 // Pin connected to mosfet
|
||||||
|
|
||||||
//Declare Sensor
|
//Declare Sensor
|
||||||
MQUnifiedsensor MQ309(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
|
MQUnifiedsensor MQ309(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
|
||||||
|
unsigned long oldTime = 0;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
//Init the serial port communication - to debug the library
|
//Init the serial port communication - to debug the library
|
||||||
Serial.begin(9600); //Init serial port
|
Serial.begin(9600); //Init serial port
|
||||||
|
pinMode(PWMPin, OUTPUT);
|
||||||
|
|
||||||
//Set math model to calculate the PPM concentration and the value of constants
|
//Set math model to calculate the PPM concentration and the value of constants
|
||||||
MQ309.setRegressionMethod(1); //_PPM = a*ratio^b
|
MQ309.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||||
@ -86,8 +88,28 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
MQ309.update(); // Update data, the arduino will be read the voltage on the analog pin
|
// 60s cycle
|
||||||
MQ309.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
oldTime = millis();
|
||||||
MQ309.serialDebug(); // Will print the table on the serial port
|
while(millis() - oldTime <= (30*1000))
|
||||||
delay(500); //Sampling frequency
|
{
|
||||||
|
// VH 0.9 Volts
|
||||||
|
analogWrite(5, 2); // 255 is 100%, 2.295 is aprox 0.9% of Duty cycle for 60s
|
||||||
|
MQ309.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||||
|
MQ309.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||||
|
MQ309.serialDebug(); // Will print the table on the serial port
|
||||||
|
delay(500); //Sampling frequency
|
||||||
|
}
|
||||||
|
|
||||||
|
// 90s cycle
|
||||||
|
oldTime = millis();
|
||||||
|
while(millis() - oldTime <= (120*1000))
|
||||||
|
{
|
||||||
|
// VL 0.2 Volts
|
||||||
|
analogWrite(5, 1); // 255 is 100%, 0.51 is aprox 0.2% of Duty cycle for 120s
|
||||||
|
MQ309.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||||
|
MQ309.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||||
|
MQ309.serialDebug(); // Will print the table on the serial port
|
||||||
|
delay(500); //Sampling frequency
|
||||||
|
}
|
||||||
|
// Total: 30 + 120s = 2.5 minutes.
|
||||||
}
|
}
|
@ -13,6 +13,10 @@
|
|||||||
modified 26 March 2020
|
modified 26 March 2020
|
||||||
by Miguel Califa
|
by Miguel Califa
|
||||||
|
|
||||||
|
Updated example of MQ-7 AND MQ-309A
|
||||||
|
modified 20 April 2020
|
||||||
|
by Miguel Califa
|
||||||
|
|
||||||
Wiring:
|
Wiring:
|
||||||
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
|
https://github.com/miguel5612/MQSensorsLib_Docs/blob/master/static/img/MQ_Arduino.PNG
|
||||||
Please take care, arduino A0 pin represent the analog input configured on #define pin
|
Please take care, arduino A0 pin represent the analog input configured on #define pin
|
||||||
@ -31,14 +35,16 @@
|
|||||||
#define type "MQ-7" //MQ7
|
#define type "MQ-7" //MQ7
|
||||||
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
|
#define ADC_Bit_Resolution 10 // For arduino UNO/MEGA/NANO
|
||||||
#define RatioMQ7CleanAir 27.5 //RS / R0 = 27.5 ppm
|
#define RatioMQ7CleanAir 27.5 //RS / R0 = 27.5 ppm
|
||||||
//#define calibration_button 13 //Pin to calibrate your sensor
|
#define PWMPin 5 // Pin connected to mosfet
|
||||||
|
|
||||||
//Declare Sensor
|
//Declare Sensor
|
||||||
MQUnifiedsensor MQ7(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
|
MQUnifiedsensor MQ7(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
|
||||||
|
unsigned long oldTime = 0;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
//Init the serial port communication - to debug the library
|
//Init the serial port communication - to debug the library
|
||||||
Serial.begin(9600); //Init serial port
|
Serial.begin(9600); //Init serial port
|
||||||
|
pinMode(PWMPin, OUTPUT);
|
||||||
|
|
||||||
//Set math model to calculate the PPM concentration and the value of constants
|
//Set math model to calculate the PPM concentration and the value of constants
|
||||||
MQ7.setRegressionMethod(1); //_PPM = a*ratio^b
|
MQ7.setRegressionMethod(1); //_PPM = a*ratio^b
|
||||||
@ -87,8 +93,28 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
MQ7.update(); // Update data, the arduino will be read the voltage on the analog pin
|
// 60s cycle
|
||||||
MQ7.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
oldTime = millis();
|
||||||
MQ7.serialDebug(); // Will print the table on the serial port
|
while(millis() - oldTime <= (60*1000))
|
||||||
delay(500); //Sampling frequency
|
{
|
||||||
|
// VH 5 Volts
|
||||||
|
analogWrite(5, 255); // 255 is DC 5V output
|
||||||
|
MQ7.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||||
|
MQ7.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||||
|
MQ7.serialDebug(); // Will print the table on the serial port
|
||||||
|
delay(500); //Sampling frequency
|
||||||
|
}
|
||||||
|
|
||||||
|
// 90s cycle
|
||||||
|
oldTime = millis();
|
||||||
|
while(millis() - oldTime <= (90*1000))
|
||||||
|
{
|
||||||
|
// VH 1.4 Volts
|
||||||
|
analogWrite(5, 20); // 255 is 100%, 20.4 is aprox 8% of Duty cycle for 90s
|
||||||
|
MQ7.update(); // Update data, the arduino will be read the voltage on the analog pin
|
||||||
|
MQ7.readSensor(); // Sensor will read PPM concentration using the model and a and b values setted before or in the setup
|
||||||
|
MQ7.serialDebug(); // Will print the table on the serial port
|
||||||
|
delay(500); //Sampling frequency
|
||||||
|
}
|
||||||
|
// Total: 60 + 90s = 2.5 minutes.
|
||||||
}
|
}
|
@ -29,6 +29,7 @@
|
|||||||
#define Pin7 (A7) //Analog input 7 of your arduino
|
#define Pin7 (A7) //Analog input 7 of your arduino
|
||||||
#define Pin8 (A8) //Analog input 8 of your arduino
|
#define Pin8 (A8) //Analog input 8 of your arduino
|
||||||
#define Pin9 (A9) //Analog input 9 of your arduino
|
#define Pin9 (A9) //Analog input 9 of your arduino
|
||||||
|
#define PWMPin (5) // Pin connected to mosfet
|
||||||
/***********************Software Related Macros************************************/
|
/***********************Software Related Macros************************************/
|
||||||
#define RatioMQ2CleanAir (9.83) //RS / R0 = 9.83 ppm
|
#define RatioMQ2CleanAir (9.83) //RS / R0 = 9.83 ppm
|
||||||
#define RatioMQ3CleanAir (60) //RS / R0 = 60 ppm
|
#define RatioMQ3CleanAir (60) //RS / R0 = 60 ppm
|
||||||
@ -52,6 +53,8 @@ MQUnifiedsensor MQ7(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin7, Type);
|
|||||||
MQUnifiedsensor MQ8(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin8, Type);
|
MQUnifiedsensor MQ8(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin8, Type);
|
||||||
MQUnifiedsensor MQ9(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin9, Type);
|
MQUnifiedsensor MQ9(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin9, Type);
|
||||||
|
|
||||||
|
unsigned long oldTime = 0;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
//Init serial port
|
//Init serial port
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
@ -168,6 +171,27 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
oldTime = millis();
|
||||||
|
while(millis() - oldTime <= (60*1000))
|
||||||
|
{
|
||||||
|
// VH 5 Volts
|
||||||
|
analogWrite(5, 255); // 255 is DC 5V output
|
||||||
|
readAllSensors();
|
||||||
|
delay(500);
|
||||||
|
}
|
||||||
|
// 90s cycle
|
||||||
|
oldTime = millis();
|
||||||
|
while(millis() - oldTime <= (90*1000))
|
||||||
|
{
|
||||||
|
// VH 1.4 Volts
|
||||||
|
analogWrite(5, 20); // 255 is 100%, 20.4 is aprox 8% of Duty cycle for 90s
|
||||||
|
readAllSensors();
|
||||||
|
delay(500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void readAllSensors()
|
||||||
|
{
|
||||||
//Update the voltage lectures
|
//Update the voltage lectures
|
||||||
MQ2.update();
|
MQ2.update();
|
||||||
MQ3.update();
|
MQ3.update();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user