Hi everyone, am using MG811 CO2 sensor
It gives output voltage between 0-2V. I get the 2 Volt when the CO2 concentration is normal in the rum and the voltage decrease as the CO2 concentration increase. So I want to use the map function as this way
volts=map(volts,1.95,0.2,350,10000);
Serial.println("CO2: ");
Serial.print(volts);
Serial.print("ppm");
Serial.println("");
So if the concentration is 2 volts then the CO2 concen. is 350 ppm and when the output voltage is near 0 volts then the CO2 is near 10000... But the function don't works as it should!! anybody knows why or have some comments about it??
NEED HELP =(
I get the volts number from this function:
float MGRead(int mg_pin) //I give the function the analogRead value on mg_pin
{
int i;
float v=0;
for (i=0;i<READ_SAMPLE_TIMES;i++) //READ_SAMPLE_INTERVAL 50 milliseconds
{
v += analogRead(mg_pin);
delay(READ_SAMPLE_INTERVAL); //READ_SAMPLE_TIMES is 5 milliseconds
}
v = (v/READ_SAMPLE_TIMES) *5/1024 ;
return v;
}