Analog sensor calibration

Hello everybody!

I would like some help.

I'm making a sensor reader, using the A0 port on the Arduino Mega. And to install this sensor, I need to convert the INT value of the sensor to another.

An example assumption:
When testing an uncalibrated CO (carbon monoxide) sensor by applying standard gas, the sensor should read 0ppm to 100ppm, but it is reading 3 to 98ppm. So I need a button, through a toc, to calibrate the “zero”, and another button to calibrate the 100 ppm.

3ppm, press the button, it converts to 0ppm.

98ppm, press the button, it converts to 100ppm.

Could anyone give me some light on this subject.
Thanks!

Can you provide a link to the data sheet - and the code you are using

A standard straight-line calibration is an offset (addition or subtraction) normally adjusted at zero. This is normally done 1st because it affects all readings.

And a slope (multiplication) normally applied at the maximum or at the expected, or most-common, or most-important reading. Since it's a multiplication factor, it doesn't affect the corrected zero-reading. (If you were calibrating a fever thermometer you'd calibrate the slope at 98.6 degrees F, and you'd adjust the offset as something "more reasonable" than zero.)

So. Subtract 3 from all of your readings to get the zero correction. Now, 100 will read 95 so the slope correction is to multiply by 1.053.

Excellent tutorial on sensor calibration: Why Calibrate? | Calibrating Sensors | Adafruit Learning System


#define CO      A0
int pin_CO      = 0;

int buttonPin1 = 9;
int buttonPin2 = 10;


void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);


void loop(void){

pin_CO = analogRead(CO)/5,11; ////sensor (0 - 200) ppm - Standard gas calibration value - 100ppm.
RMax_CO = pin_CO - XMax_CO;////// RMax_O2 = 210
valor_CO = pin_CO * XMin_CO;// / XMin_O2;

Serial.println( "XMax_CO");
Serial.println( XMax_CO);
Serial.println( " ");
Serial.println( "XMin_CO");
Serial.println( XMin_CO);
Serial.println( " ");
Serial.println( "pin_CO");
Serial.println( pin_CO);

**if (digitalRead(pushbutton1) == LOW) // Se o botão for pressionado**
**  {**
**    Serial.println("ON");**
**    XMax_CO = pin_CO - setMax_CO; **
**}**
**if (digitalRead(pushbutton2) == LOW) // Se o botão for pressionado**
**  {**
**    Serial.println("ON");**
**    XMin_CO = setMin_CO / pin_Co;**
**}**

delay(500);
}

This is a draft of the code. My question is how to make the buttons do these conversions.
Thanks!

For most practical applications, and definitely for hobby applications, I'd be very happy to see such close numbers, call it not just good enough but close to fantastic, and move on. That's just a few % off.

To do better than that, you'll for starters have to be able control your test environment very very closely - how are you making sure that there is actually exactly 100 ppm in the air that the sensor sees? Just opening the door of the container to place the sensor will mess up such concentrations big time, as may air trapped in your project.

Take the reading, put it in a variable, do your calculations with it.

To keep the value between runs, store it in EEPROM.

My page here explains all about two point calibration (of an ADC, but the same principles and method apply) with code to do it.

You WILL need to take multiple readings over a time to make sure the sensor has properly responded to a change in gas concentration. So the averaging in the code on that page will still be needed.
You address the "offset" (the zero error) first, THEN the gain error (full scale).

Thanks John Herrington, it will help me a lot!

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