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!
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.
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.
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).