Electrical – Using digital input pin to read variable resistance from sensor requiring supply voltage

adcraspberry pisensor

I intend to use air contaminants sensor TGS 2602. The internal resistance changes if a given gas is detected. It requires an input voltage V_C = 5V to operate.

According to the specs, the basic measurement circuit is:

schematic

simulate this circuit – Schematic created using CircuitLab

The problem I am facing is I want to read the measurements with digital IO pins, specifically I want to use Raspberry Pi for this. I found a simple solution to a similar problem here:
Reading Analogue Sensors With One GPIO Pin
. Essentially it involves using an RC circuit and measuring time lapsed until "high" voltage occurs on our digital pin.

Reading Analogue Sensors With One GPIO Pin - picture

In this case I would then be inclined to simply switch R_L with a capacitor but by doing this I would quickly cut off the supply voltage for the sensor (it requires V_C). I then thought I should maybe add the capacitor in parallel with R_L. But the R_L voltage drop is low, so I would never reach the "high" voltage on the capacitor to be able to read it with my digital pin. Should I perhaps use op-amp to drive the V_RL up? But is it not over-complicating things?

My question is then how should I measure value of R_S with a digital reader?

Best Answer

First, be aware that your sensor does require a 5v +-0.2 supply, both for the heater and sensor. The RPI should have +5v available.
The capacitor discharge method that you propose is one of very few available to RPI to convert an analog signal to a digital representation. RPI GPIO pins require a voltage range between 0 to +3.3v. Data sheet says load resistor minimum is 450 ohms. No maximum, so a capacitor load might be acceptable:

schematic

simulate this circuit – Schematic created using CircuitLab

This circuit at left might work, if you let the circuit idle with GPIO as output, programming a logic zero forcing R1 to pull down the cell resistor R2 toward ground, until you wish to input a reading. Reading may go quickly enough not to disturb R2 cell resistance too much.


If you are reluctant to disturb cell operation from the prescribed load circuit, the amplifier at right might allow a similar capacitor charging/timing method. A quick run with LTSPICE suggests a timing range between 800 uS for a sensor resistance of 100k ohm, and about one second for sensor resistance of 10k ohm. Cell resistor R4 remains always near 5v.
However, be aware that the GPIO measurement sequence requires a polarity switch: C2 must be discharged by setting GPIO to logic high, then transistor Q1 pulls it down slowly towards logic 0