Then there is a function map(). Which is better to use function map() or to calculate. Thank you in advance for any advice.

0.8V = 163,68 (1..1023@5V)

4.0V = 818,4

map() is integer math, so the formula will look like: ppm = map(analogRead(A0), 164, 818, 0, 2000);

you see at least 2 (small) roundings. Furthermore you have only about 654 steps (steps of 3)

Even if youaverage multiple readings this will stand.

If you calculate you can get more accurate number when you calculate the PPM as float.

in the snippet below you can compare the two methods:

void loop()

{

float value = (analogRead(A0) * 3.0 + previous) / 4.0; // apply low pass filter - weighted average of new reading and prev reading

float ppmF= (value -163.68) * 2000 / (818.4 -163.68); // can be optimized to PPM = (value -163.68) * 3.05474096;

int ppmI = map(value, 164, 818, 0, 2000);

Serial.print("PPM int: ");

Serial.println(ppmI, DEC);

Serial.print("PPM float: ");

Serial.println(ppmF, 1); // 1 decimal place

delay(1000);

}

you might need to check the math, and you must be sure that the Arduino gets 5.00V

as when it gets e.g. 4.95 or 5.05 the readings will be affected of course.

give it a try.