In order to measure the resistance you can measure voltage using ADC (analog) input esp32 pin on a voltage divider circuit.
Voltage divider circuit consists of:
- Resistor of a known resistance
- Sensor's resistor for which resistance is to be measured
- Known reference voltage (3.3v for esp32 case) applied to those two resistors connected in series
Voltage is measured on ADC (analog) input pin of esp32 connected in between those two resistors.
Ohm Law can be used to calculate unknown resistance from voltage drop (knowing reference voltage and reference resistor resistance)
There are two kinds of configurations for this circuit:
Either the variable resistor is close to GND (DOWNSTREAM) or it is closer to VCC (UPSTREAM).
esp32 ADC is not the best:
- The ESP32 has two 12-bit ADCs
- Noisy (can be corrected by statistical sampling which will reduce sampling rate for accurate measurements)
- Non-linear (can be corrected by polynomial approximation)
- Almost ignores ranges < 0.14v and > 2.6v
- The ESP32 ADC can measure voltage levels between 0 V and 3.3 V. The measured voltage is assigned a value between 0 and 4095, with 0 V corresponding to 0 and 3.3 V corresponding to 4095
- ADCs in the esp32 have an attenuator stage at their inputs; the suggested range for 11Db attenuation is 2600mV at best (even though the ADC's range is 0-3.3v)
- However, the output can be made accurate to within 1% on input range of 0.14 to 2.6 volts
Examples:
There are two types of commonly used resistance based sensors:
- European 0-190 ohms range (often 10-180 ohms working range)
- American Standard 240-33 ohms
Examples:
- Fuel level (10-180 Ohm or 0-190 Ohm range)
- Oil pressure
- Rudder position (10-180 Ohms)
- Trim
- Resistive Temperature Sensors
Constraints for selecting a reference resistor size for these types of sensors:
Appropriate sizes are (in Ohms):
Pick up resistor with lower % tolerance.
NMEA 0183 is on USB serial with baud rate of 4800
Example sentences:
$BBXDR,G,135.4,O,Ohms_esp32*6A
$BBXDR,G,137.9,O,Ohms_esp32*65
$BBXDR,G,137.6,O,Ohms_esp32*6A
$BBXDR,G,137.6,O,Ohms_esp32*6A
$BBXDR,G,138.1,O,Ohms_esp32*62
$BBXDR,G,138.3,O,Ohms_esp32*60
There are numerous ready made voltage divider PCBs. Look for
- Grove Voltage Divider with adjustable gain
- DFRobot DFR0051 Voltage Divider
- Phidgets 1121 Voltage Divider