Skip to content

Commit 9ebad25

Browse files
authored
Merge pull request #118 from SenaxInc/copilot/fix-pressure-sensor-calculation
Fix 4-20mA sensor height calculations with native unit conversions
2 parents c6e0dc1 + ea0a8ef commit 9ebad25

File tree

2 files changed

+240
-79
lines changed

2 files changed

+240
-79
lines changed

TankAlarm-112025-Client-BluesOpta/README.md

Lines changed: 77 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -84,74 +84,87 @@ The client creates a default configuration on first boot. You can update configu
8484
- **Low Alarm**: Threshold in inches for low level alert
8585
- **Analog Pin**: Arduino Opta analog input (A0-A7, I1-I8)
8686
- **Sensor Type**: "voltage" (0-10V), "current" (4-20mA), or "digital" (float switch)
87-
- **Min Value**: Minimum sensor value (e.g., 0.0V or 4.0mA)
88-
- **Max Value**: Maximum sensor value (e.g., 10.0V or 20.0mA)
89-
- **Min Inches**: Tank level in inches at minimum sensor value
90-
- **Max Inches**: Tank level in inches at maximum sensor value
9187

9288
### 4-20mA Current Loop Sensor Configuration
9389

94-
For 4-20mA current loop sensors, two mounting options are supported:
90+
For 4-20mA current loop sensors, two mounting options are supported. The implementation uses the sensor's **native measurement range** (sensorRangeMin/Max/Unit) for accurate pressure-to-height conversions.
9591

9692
#### Pressure Sensor (Bottom-Mounted)
9793
Used for sensors like the Dwyer 626-06-CB-P1-E5-S1 (0-5 PSI) mounted near the bottom of the tank.
9894

9995
- **Current Loop Type**: "pressure"
10096
- **How it works**: Measures the pressure of the liquid column above the sensor
101-
- 4mA = Empty tank (0 PSI / no liquid above sensor)
102-
- 20mA = Full tank (max PSI / max liquid height)
103-
- **Sensor Range**: The native measurement range (e.g., 0-5 PSI, 0-2 bar)
104-
- `sensorRangeMin`: Minimum value (typically 0)
105-
- `sensorRangeMax`: Maximum value (e.g., 5 for 0-5 PSI)
106-
- `sensorRangeUnit`: Unit of measurement ("PSI", "bar", etc.)
97+
- 4mA = `sensorRangeMin` (e.g., 0 PSI = no liquid above sensor)
98+
- 20mA = `sensorRangeMax` (e.g., 5 PSI = max liquid height)
99+
- **Sensor Range**: The native measurement range from the sensor datasheet
100+
- `sensorRangeMin`: Minimum pressure at 4mA (typically 0)
101+
- `sensorRangeMax`: Maximum pressure at 20mA (e.g., 5 for 0-5 PSI)
102+
- `sensorRangeUnit`: Pressure unit - "PSI", "bar", "kPa", "mbar", or "inH2O"
107103
- **Sensor Mount Height**: Height of sensor above tank bottom (usually 0-2 inches)
108-
- **Max Value**: Maximum liquid height the sensor can measure (corresponds to 20mA)
109104

110-
**Example Configuration** (0-5 PSI sensor, 1 PSI per 2.3 ft of water):
105+
**Known Limitation - Blind Spot:** Pressure sensors cannot detect liquid levels below their mount height. When the tank is empty (0 PSI), the reported level will be the sensor mount height (e.g., 2"), not 0". Mount the sensor as close to the tank bottom as possible to minimize this blind spot.
106+
107+
**Pressure-to-Height Conversion:**
108+
The system automatically converts pressure to inches using these factors:
109+
- 1 PSI = 27.68 inches of water
110+
- 1 bar = 401.5 inches of water
111+
- 1 kPa = 4.015 inches of water
112+
- 1 mbar = 0.4015 inches of water
113+
- 1 inH2O = 1 inch of water
114+
115+
**Example Configuration** (0-5 PSI sensor on 120" tank):
111116
- Sensor mounted 2 inches above tank bottom
112-
- Max sensor range = 5 PSI = ~138 inches of water
113-
- Tank height = 120 inches
117+
- Max sensor range = 5 PSI = ~138 inches of water column
114118
- Configuration:
115119
- `currentLoopType`: "pressure"
116120
- `sensorRangeMin`: 0
117121
- `sensorRangeMax`: 5
118122
- `sensorRangeUnit`: "PSI"
119123
- `sensorMountHeight`: 2.0
120-
- `maxValue`: 118.0 (tank height minus mount height: 120 - 2 = 118 inches)
121124

122-
> **Note:** For pressure sensors, set `maxValue` to the tank's usable height minus the sensor mount height. The implementation adds `sensorMountHeight` to the measured value, so `maxValue` should represent the height of liquid *above* the sensor, not the total tank height.
125+
**How It Works:**
126+
1. 4mA → 0 PSI → 0 inches of liquid above sensor
127+
2. Total height = 0 + 2" mount height = 2" (minimum reported value due to blind spot)
128+
3. When tank fills: 12mA → 2.5 PSI → 69.2" + 2" = 71.2" total
123129

124130
#### Ultrasonic Sensor (Top-Mounted)
125131
Used for sensors like the Siemens Sitrans LU240 mounted on top of the tank looking down.
126132

127133
- **Current Loop Type**: "ultrasonic"
128134
- **How it works**: Measures the distance from the sensor to the liquid surface
129-
- 4mA = Full tank (liquid close to sensor)
130-
- 20mA = Empty tank (liquid far from sensor)
131-
- **Sensor Range**: The native measurement range (e.g., 0-10 meters, 0-30 feet)
132-
- `sensorRangeMin`: Minimum distance (typically 0)
133-
- `sensorRangeMax`: Maximum distance (e.g., 10 for 0-10m)
134-
- `sensorRangeUnit`: Unit of measurement ("m", "ft", "in", etc.)
135-
- **Sensor Mount Height**: Distance from sensor to tank bottom when tank is empty
136-
- **Max Value**: Maximum liquid height (tank capacity)
137-
138-
**Example Configuration** (ultrasonic sensor with 0-10m range on 10-foot tank):
139-
- Sensor mounted 124 inches above tank bottom (tank is 120 inches + 4 inch clearance)
140-
- Maximum tank fill level = 120 inches
135+
- 4mA = `sensorRangeMin` (minimum distance, typically a blind spot)
136+
- 20mA = `sensorRangeMax` (maximum measurable distance)
137+
- **Sensor Range**: The native measurement range from the sensor datasheet
138+
- `sensorRangeMin`: Minimum distance at 4mA (e.g., 0.5m for blind spot)
139+
- `sensorRangeMax`: Maximum distance at 20mA (e.g., 10m)
140+
- `sensorRangeUnit`: Distance unit - "m", "cm", "ft", or "in"
141+
- **Sensor Mount Height**: Distance from sensor to tank bottom when tank is empty (in inches)
142+
143+
**Distance Unit Conversion:**
144+
The system automatically converts distance to inches using:
145+
- 1 m = 39.3701 inches
146+
- 1 cm = 0.393701 inches
147+
- 1 ft = 12 inches
148+
149+
**Example Configuration** (ultrasonic sensor with 0.5-10m range on 10-foot tank):
150+
- Sensor mounted 124 inches above tank bottom (tank is 120" + 4" clearance)
141151
- Configuration:
142152
- `currentLoopType`: "ultrasonic"
143-
- `sensorRangeMin`: 0
144-
- `sensorRangeMax`: 10
153+
- `sensorRangeMin`: 0.5 (blind spot in meters)
154+
- `sensorRangeMax`: 10.0 (max range in meters)
145155
- `sensorRangeUnit`: "m"
146156
- `sensorMountHeight`: 124.0
147-
- `maxValue`: 120.0
157+
158+
**How It Works:**
159+
1. 4mA → 0.5m (19.7") → liquid level = 124" - 19.7" = 104.3" (nearly full)
160+
2. 20mA → 10m (393.7") → liquid level = 124" - 393.7" = clamped to 0" (empty/beyond range)
148161

149162
**Calibration Tips for 4-20mA Sensors:**
150163
1. Record the actual mA output at known liquid levels (empty, half-full, full)
151-
2. Verify sensor mount height is accurate
164+
2. Verify sensor mount height is accurate using a tape measure
152165
3. Enter the correct sensor native range (as specified in sensor datasheet)
153-
4. Check for temperature effects on readings
154-
5. Consider the specific gravity of the liquid (for pressure sensors)
166+
4. For pressure sensors: account for specific gravity if not measuring water (multiply PSI by 1.0/SG)
167+
5. Check for temperature effects on readings (cold liquids are denser)
155168

156169
### Float Switch Configuration (Digital Sensors)
157170
Float switches can be configured as either normally-open (NO) or normally-closed (NC):
@@ -165,6 +178,35 @@ Float switches can be configured as either normally-open (NO) or normally-closed
165178

166179
**Wiring Note**: For both NO and NC float switches, connect the switch between the digital input pin and GND. The Arduino uses an internal pull-up resistor, and the software interprets the signal based on your configured switch mode. The wiring is the same for both modes - only the software interpretation changes.
167180

181+
### Analog Voltage Sensor Configuration
182+
183+
For analog voltage sensors (like the Dwyer 626 series with voltage output), the system supports the same native range configuration as 4-20mA sensors. This allows you to specify both the voltage range and pressure range for accurate pressure-to-height conversion.
184+
185+
**Supported Voltage Output Configurations:**
186+
- 0-10V (default)
187+
- 0-5V
188+
- 1-5V
189+
- 0.5-4.5V
190+
- 2-10V
191+
- Any configurable range
192+
193+
**Configuration Parameters:**
194+
- `analogVoltageMin`: Minimum voltage output (e.g., 0.0 for 0-10V, 1.0 for 1-5V)
195+
- `analogVoltageMax`: Maximum voltage output (e.g., 10.0 for 0-10V, 5.0 for 1-5V)
196+
- `sensorRangeMin` / `sensorRangeMax`: Pressure range in native units
197+
- `sensorRangeUnit`: Pressure unit - "PSI", "bar", "kPa", "mbar", or "inH2O"
198+
- `sensorMountHeight`: Height of sensor above tank bottom (inches)
199+
200+
**Example Configuration** (Dwyer 626 with 1-5V output, 0-5 PSI range):
201+
- Configuration:
202+
- `sensorType`: "analog"
203+
- `analogVoltageMin`: 1.0
204+
- `analogVoltageMax`: 5.0
205+
- `sensorRangeMin`: 0
206+
- `sensorRangeMax`: 5
207+
- `sensorRangeUnit`: "PSI"
208+
- `sensorMountHeight`: 2.0
209+
168210
## Operation
169211

170212
### Normal Operation

0 commit comments

Comments
 (0)