I'm currently trying to use a CO2 sensor. It runs with a 5V heating voltage (passed directly from USB) and outputs a test voltage, which is fed into an impedance converter:
I then take its output into my microcontroller, which shows a voltage of around 75mV for an ESP32. However, if I measure it with a voltmeter, I get 200mV - which is an expected value considering the datasheet.
Example code for the ESP32:
void setup() {
Serial.begin(115200);
pinMode(35, INPUT);
}
float voltage = 0;
void loop() {
voltage = (analogRead(35)*3300.0)/4096.0;
Serial.println(voltage);
}
What am I missing here? I'm still a beginner, so please be patient with me
Thanks a lot already!
Off the top of my head, when I look at the code in loop(), you might consider using a delay of sort before making another reading allowing the A:D a larger sampling time. Consider you are not asking the CPU core1 to do very much and the A:D may need more time between readings. I'd try a delay of 100uS using, delayMicroseconds or something like that. If the readings improve then you know you are on the right track.
You might try using the A:D calibration procedure as per the ESP32 AD API.
This matches the results from using the CO2 sensor. In the middle range of ~500mV, the measurements seem to be quite accurate. Could the ADC really be THAT non-linear?