Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrouch committed Dec 21, 2024
1 parent 7948271 commit f9bfdc5
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
128 changes: 128 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,134 @@ is the maximum recommended by the EPA. Water with a TDS level above 1,000 ppm
is not considered safe to drink, and levels above 2,000 ppm may
require a filtration system.


### Resistance sensor with M5Stack AtomS3-Lite

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).


![image](img/VoltageDivider.png)


$$
\begin{flalign}
\text{ Downstream: } \newline \newline
& \large {V _{ref} \over {R _{ref} + R _{sensor}}} = {V _{meas} \over {R _{sensor}}} \text{ } \Rightarrow \text{ }
R _{sensor} = {R _{ref} {V _{meas} \over {V _{ref} - V _{meas}}}} &
\end{flalign}
$$



$$
\begin{flalign}
\text{ Upstream: } \newline \newline
& \large {V _{ref} \over {R _{ref} + R _{sensor}}} = {V _{meas} \over {R _{ref}}} \text{ } \Rightarrow \text{ }
R _{sensor} = {R _{ref} {{V _{ref} - V _{meas}} \over V _{meas}}} &
\end{flalign}
$$


#### esp32 ADC

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


#### For precise measurements use external ADC

Examples:
- ADS1115 https://docs.m5stack.com/en/unit/vmeter
- INA219 https://www.adafruit.com/product/904

#### Resistive boat sensors

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:

$$
\begin{flalign}
& V _{ref} = 3.3 \newline &
8 \lt R _{sensor} \lt 240 \newline &
0.14 \lt V _{meas} \lt 2.6 &
\end{flalign}
$$

Appropriate sizes are (in Ohms):

$$
\begin{flalign}
& \text{ Upstream: } \newline &
15 \lt R _{ref} \lt 33 &
\end{flalign}
$$

$$
\begin{flalign}
& \text{ Downstream: } \newline &
68 \lt R _{ref} \lt 220 &
\end{flalign}
$$

Pick up resistor with lower % tolerance.

#### NMEA 0183 XDR Sentences for resistance

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
````

#### Ready made voltage divider PCBs

There are numerous ready made voltage
divider PCBs. Look for

- Grove Voltage Divider with adjustable gain
- DFRobot DFR0051 Voltage Divider
- Phidgets 1121 Voltage Divider


### INA219 Voltage and Current sensors (up to four on secondary i2c bus)

Load and your sensor need to share common ground.
Expand Down
Binary file added img/VoltageDivider.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f9bfdc5

Please sign in to comment.