The AD input of ESP's works from 0..1 V, dividing this into values from 0..1023.
So 0,5V will give an output of 512 from the AD.
Further info in my "Basics" at ESPEasy Wiki:
https://letscontrolit.com/wiki/index.ph ... Converters
I'll try to make up an example. Please keep in mind that this is not tested,
it's just based on the datasheet, it definitely will need fine tuning.
This assumes you're using a bare ESP.
Testboards like WeMos or nodeMCU often have a built-in voltage divider
raising the range to 0...3 V. In this case another circuit with other resistor
values is necessary.
As datasheet says they use 4,7KOhm for the external resistor.
For connecting to ESP I'd use a voltage divider 3,3KOhm/1,2KOhm.
This should give about 0,93V for the AD input at 150ppm CO.
0,93V * 1023 steps gives an outpout from the AD of 951.
Now we have to take care of the zero offset. Due to the diagrams
in the datasheet the sensor gives about 0,4V at 0 ppm CO, the voltage divider
cuts this down to about 0,1V
0,1V * 1023 steps gives an output of about 102.
So first step of formula is subtracting 102 from the given Value from the AD.
Now, for 150 ppm CO we have a raw value of 849.
849 corresponds with 150 ppm CO so we can calculate a factor.
150 / 849 = 0,177.
So at last the formula is:
CO value = (<AD output> - <Zero Offset> ) * 0,177
Some hints:
Heating period:
I won't use PWM for the low voltage as it might cause some problems.
Try easier this way:
5V --> Sensor Heating --> 100 Ohm Resistor --> Ground.
Then use the NPN or a small FET to short circuit the 100 Ohm Resistor.
No PWM, just a GPIO: GPIO on = Heating, Resistor short circuited and
GPIO off: Resistor reduces heating voltage, measuring period.
Calibrating zero offset:
At very first: Let the sensor heating periods work for at least 48 hours to "burn in" the sensor.
Put the circuit into free air or open Windows for some minutes, to make sure the air is clean.
After some measuring periods the raw output from the AD gives the zero value.
Put the value into the formula shown above.
Calibration:
Basically a calibration is possible, but i assume it is out of reach for most DIYer.
It would need a small clima chamber and a defined test gas, that's a bit much.
The way shown above gives a value back that most likely isn't very exact, it relies
on a lot of datasheet data and such that may vary in practice.
Anyways it's the thing we can do with home equipment.
Another point: The zero offset may vary over time, driven by temperature
and/or aging. So a recalibration now and then might be usefull.
I'd prefer calculating in rules, this might be a bit much for the formula field.
Suggestion: Use rules and a dummy variable for storing interim values.
This on top gives the advantage of more control over the values if something goes wrong.