49 lines
836 B
Arduino
Raw Normal View History

2023-01-07 15:48:40 +01:00
//
// FILE: MHZCO2_analog.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo MHZ library / sensor
// DATE: 2020-09-01
2023-07-27 16:14:19 +02:00
#include "Arduino.h"
#include "MHZCO2.h"
2023-01-07 15:48:40 +01:00
/*
DATASHEET P.7
Conversion between analog voltage output and concentration,
take 0.4V ~ 2V as an example:
Vo(V) = 0.4V + (2.0V - 0.4V) * C(concentration ppm) / range(ppm)
C = (Vo - 0.4 V ) * range / 1.6;
*/
void setup()
{
Serial.begin(115200);
2023-07-27 16:14:19 +02:00
// Serial.println(__FILE__);
// Serial.print("MHZCO2_LIB_VERSION: ");
// Serial.println(MHZCO2_LIB_VERSION);
2023-01-07 15:48:40 +01:00
}
void loop()
{
2023-07-27 16:14:19 +02:00
uint16_t C = concentration(A0, 2000);
2023-01-07 15:48:40 +01:00
Serial.println(C);
}
2023-07-27 16:14:19 +02:00
uint16_t concentration(int port, uint16_t maxConcentration)
2023-01-07 15:48:40 +01:00
{
float volt = analogRead(port) * (5.0 / 1023.0);
2023-07-27 16:14:19 +02:00
uint16_t C = (volt - 0.4) * maxConcentration / 1.6;
2023-01-07 15:48:40 +01:00
return C;
}
// -- END OF FILE --