MiCS-6814 / CJMCU-6814 gas sensor reading conversion

Hello, I'm using this gas sensor to measure CO, NO2, and NH3 for my university project.
I used these as reference to program the sensor:

And this is my results:


The reading I received was in volts, so I'm wondering how to convert the reading to ppm or ug/m3?
(the datasheet does not specify the conversion)
Datasheet: https://www.sgxsensortech.com/content/uploads/2015/02/1143_Datasheet-MiCS-6814-rev-8.pdf

Code:

#include <dht.h>

dht DHT;

#define DHT11_PIN 7
const float max_volts = 5.0;
const float max_analog_steps = 1023.0;

void setup() 
{
  Serial.begin(9600);
  delay(1000);
  Serial.println("Setup initializing");

  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(A2, INPUT);
}

void loop() 
{
  int a0_read = analogRead(A0);
  int a1_read = analogRead(A1);
  int a2_read = analogRead(A2);
  int chk = DHT.read11(DHT11_PIN);
  
  Serial.print("Temperature = ");
  Serial.println(DHT.temperature);
  Serial.print("Humidity = ");
  Serial.println(DHT.humidity);
  Serial.print("CO (a0): ");
  Serial.println(a0_read * (max_volts / max_analog_steps));
  Serial.print("NH3 (a1): ");
  Serial.println(a1_read * (max_volts / max_analog_steps));
  Serial.print("NO2 (a2): ");
  Serial.println(a2_read * (max_volts / max_analog_steps));
  

  delay(30000);
}

You start with getting a voltage
value = analogRead(A0);
voltage = value * 5.0/1023;

Pretty much what you have. Rather than getting a voltage if you want PPM consider using a MAP function.

Ron

Thank you for your response, but I don't understand how I could implement this function in my code, since I am measuring 3 different gases

You are reading 3 analog channels, each channel has a value between 0 and 1023 bits. Each channel value represents a value in PPM (Parts Per Million) of the measured gas sample. Your sensor outputs 3 analog signals proportional to the PPM of the sampled gas. Now from the link.
So start with the example:

```
void loop() {
  int val = analogRead(0);
  val = map(val, 0, 1023, 0, 255);
  analogWrite(9, val);
}
```

You modify the example:

```
void loop() {
  int val1 = analogRead(0);
  val1 = map(val1, 0, 1023, 0, some ppm value);
  int val2 = analogRead(1);
  val2 = map(val2, 0, 1023, 0, some ppm value);
//repeat for val3
}
```

The PPM values have a span which corresponds to the bit count. Example 0 to 1023 bits = 0 to some number of PPM.

Ron

I think I'm starting to understand what you mean, according to the datasheet, the sensor has different detecting ranges for each gas:
image
Since I am targeting CO, NO2, and NH3, should the range of detectability be included in the map function in my code?
example:

void loop()
{
int val1 = analogRead(A0);
val1 = map(val1, 0, 1023, 1, 1000); // CO range 1-1000 ppm
}

would that be correct?

Yes, that is where you want to go. This also assumes the analog input is 0.0 to 5.0 volts using an Arduino UNO for example with a 5.0 VDC analog reference and your sensor is a 0 to 5.0 volt output.

So it's like saying 0.0 to 5.0 volts = 0 to 1023 bits = 1 to 1,000 PPM.

Ron

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.