I am creating a vape sensor for a school project... like a smoke detector but for vapes using the Gas Sensor and HCHO sensor. When the level of HCHO reaches 7 ppm, I want it to go off. Here is my code:
Oh, I'm sorry...from what I read the preferred method was to insert the file. I'll post it here. Apologies.
/* Air quality station example.
* Seeed Inc
* By: Mario De Los Santos
* Date: April 2021
*
* Consider the board to use, this example was done using
* Arduino UNO
*
* Version: 1.0
*/
//Libraries
#include <math.h> //We need some math operations in the code
#include <Wire.h> //I2C Library
#include "MutichannelGasSensor.h"
//Sensors port definitions
//Note: The Multichannel Sensor doesnt need to be declared here, it is I2C
#define MQ3 A0
#define R0_MQ3 -0.02 //Note:Please run the calibrarion MQ3 code before to use this code//define calibration value for MQ3 here
#define HCHO A2 //Note:Please run the calibrarion HCH0 code before to use this code
//From that calibrarion you need to get the R0 value printed
#define Vc 4.95
#define R0_HCH0 -0.02 //Edit this to you own calibration value from the calibration code HCH0
double Get_HCH0(){ //Just call the function to get the value
//Reference: https://wiki.seeedstudio.com/Grove-HCHO_Sensor/
int sensorvalue = analogRead(HCHO);
double Rs = (1023.0/sensorvalue)-1;
delay(500); //Adjust this value to your application
return ppm(0.5)
}
float Get_GasRatio_MQ3()
{
//Reference: https://wiki.seeedstudio.com/Grove-Gas_Sensor-MQ3/
float sensor_volt;
float RS_gas; // Get value of RS in a GAS
int sensorValue = analogRead(MQ3);
sensor_volt=(float)sensorValue/1023*5.0;
RS_gas = (5.0-sensor_volt)/sensor_volt;
return RS_gas;
}
float Get_ratio_MQ3(float RS_gas)
{
//Reference: https://wiki.seeedstudio.com/Grove-Gas_Sensor-MQ3/
float ratio = RS_gas/R0_MQ3;
return ratio;
}
void Multichannel_init()
{
gas.begin(0x04);//the default I2C address of the slave is 0x04
gas.powerOn();
Serial.print("Firmware Version = ");
Serial.println(gas.getVersion());
}
void Multichannel_Data_generation()
//This is going to print the values, if you want to handlee it
//You need to extract the variable C and send whatever you need
{
//Reference: https://wiki.seeedstudio.com/Grove-Multichannel_Gas_Sensor/
float c;
c = gas.measure_NH3();
Serial.print("The concentration of NH3 is ");
if(c>=0) Serial.print(c);
else Serial.print("invalid");
Serial.println(" ppm");
c = gas.measure_CO();
Serial.print("The concentration of CO is ");
if(c>=0) Serial.print(c);
else Serial.print("invalid");
Serial.println(" ppm");
c = gas.measure_NO2();
Serial.print("The concentration of NO2 is ");
if(c>=0) Serial.print(c);
else Serial.print("invalid");
Serial.println(" ppm");
c = gas.measure_C3H8();
Serial.print("The concentration of C3H8 is ");
if(c>=0) Serial.print(c);
else Serial.print("invalid");
Serial.println(" ppm");
c = gas.measure_C4H10();
Serial.print("The concentration of C4H10 is ");
if(c>=0) Serial.print(c);
else Serial.print("invalid");
Serial.println(" ppm");
c = gas.measure_CH4();
Serial.print("The concentration of CH4 is ");
if(c>=0) Serial.print(c);
else Serial.print("invalid");
Serial.println(" ppm");
c = gas.measure_H2();
Serial.print("The concentration of H2 is ");
if(c>=0) Serial.print(c);
else Serial.print("invalid");
Serial.println(" ppm");
c = gas.measure_C2H5OH();
Serial.print("The concentration of C2H5OH is ");
if(c>=0) Serial.print(c);
else Serial.print("invalid");
Serial.println(" ppm");
delay(1000);
}
void setup() {
Serial.begin(9600);
Multichannel_init();
}
//You just need to get focus in this part, the functions works alone, the data handle is
//what you need
void loop() {
double HCH0_sensor = Get_HCH0();
Serial.print("HCH0 ppm = ");
Serial.println(HCH0_sensor);
float MQ3_sensor = Get_GasRatio_MQ3();
Serial.print("MQ3 Gas ratio = ");
Serial.println(MQ3_sensor);
float MQ3_ratio = Get_ratio_MQ3(MQ3_sensor);
Serial.print("MQ3 ratio = ");
Serial.println(MQ3_ratio);
Multichannel_Data_generation(); //Print the values from the Multichannel
delay(1000);
}
I am really just trying to make sense of this code. Thank you so much to anyone who has already helped me... I am very new to this but I am trying to follow the forum rules to the best of my ability.
You code does not contain a function called 'ppm' If you look at the tutorial for that sensor: Grove - HCHO Sensor - Seeed Wiki, they discuss how you would turn these raw sensor readings into a ratio and then how to turn them into actual ppm.
For starters, you could just display the raw values like the tutorial does.
I have worked through the tutorials for both the Grove- HCHO Sensor and MQ3 Gas Sensor v1.5 and am displaying values for them. I have opened the Serial Monitor and have had no problems with the code. I do have one more question- are the values displayed in the serial monitor cumulative between both sensors? By values I really mean ratios. I have attached a screenshot of what I am getting: