Analog Pressure sensor

From Let's Control It
Jump to: navigation, search

In this example we show a solution for measuring oil pressure in an engine.

220px-WPGaugeFace.jpg

Source:Wikipedia

It is not too difficult to connect an analog sensor to the ESP, but there are a number of issues to be addressed.

- The ESP8266 is equiped with an Analog to Digital Converter (ADC)that can measure up to 1 volt.
- The on board ADC has a 10 bit accuracy. This means that a full scale 1 volt reads as 1023.
- In spite of the high accuracy of the ADC, it operates in a very noisy environment. Don't expect high accuracy readings.
- Some board makers like NodeMCU and Wemos add a resistor network (voltage divider) to enhance the maximum voltage reading.
- There are many more considerations. Just take a few minutes to read this posting as an example. [1]

If you want to measure pressure of liquids like oil or water, you could buy one of the pressure sensors on the internet, like this one:

PSI100.jpg PSI100 conn.jpg

PSI.png

All sourced by ebay

Specifications:

Input: 0-100 psi.
Output: 0.5V – 4.5V linear voltage output. 0 psi outputs 0.5V, 50 psi outputs 2.5V, 100 psi outputs 4.5V.
Works for oil, fuel, water or air pressure. Can be used in oil tank, gas tank, etc.
Accuracy: within 1.5% of reading (full scale).
Current draw: less than 4 mA.
Burst (over or max pressure) pressure: minimum 200 psi.
Thread: 1/8”-27 NPT. (see our fitting set for other thread size below).
Wiring connector: water sealed quick disconnect.  Mating connector and wire harness (pigtail) is included.
Wiring: Red for +5V.  Black for ground.  Blue for signal output.
Our material is using top of line 316 stainless steel (not 304) and high temperature auto-graded plastic.
This is a high quality pressure sender, with ceramic pressure chip sensor inside.

The advantages: It is very easy to install, has an analog output and a linear conversion. There are however a number of challenges:

1 If you want to measure pressure in Bar, how is it converted from PSI
  With one of the many freely available converters on the internet, you can easily discover that 1 Bar (100.000 Pascal)    equals to 14,5037737796859 PSI (pound per square inch). This sensor ranges from 0 to 6,89475729 Bar (100PSI).
Besides that, 1 Volt => 25 PSI => 1,723662 etc Bar.
2 How can voltages higher than 1.0 volts be measured with the on-board ADC
  If the output impedance of the sensor is low enough, you can use a simple resistor network to create a voltage divider from let's say 5 volt to 1 volt. If the impedance is high, the output voltage collapses when the output is loaded with a simple resistor network. In these cases a DC amplifier (transistor, FET or Op-Amp) is required.
  Voltage-divider.gif
NodeMCU and Wemos already have a voltage divider in place. They both have a resistor R1=100k/1% and a resistor R2=220k/1%, thus creating a voltages divider of roughly 0.31. This allows for measuring voltages up to 3.3 volts.
In our example we need a divider from 5 to 1 volt which is a 1:5 ratio 1/5=0.20.
After doing some maths, you can prove that in this case R1=0.80R2/0.20. With an R2 of 100k, R1 has to be 400k. With a single resistor of 180k/5% or 182k/1% in series with the analog input, the required divider is made.


3 How can you make sensible readings with ESPEasy
  It takes some physics and math to answer this question and some calculations have to be made, but fortunateley ESPEasy provides just that.
Emperical table
Vin	Bar	Vadc	VALadc	Val-Off	/1000	Correct	Bar
0	0	0	0	0	0	0	0
0,5	0,000	0,1	102,3	0	0	0	0
1	0,862	0,2	204,6	102,3	0,1023	8,4246	0,8618
1,5	1,724	0,3	306,9	204,6	0,2046	8,4246	1,7237
2	2,586	0,4	409,2	306,9	0,3069	8,4246	2,5855
2,5	3,447	0,5	511,5	409,2	0,4092	8,4246	3,4474
3	4,309	0,6	613,8	511,5	0,5115	8,4246	4,3092
3,5	5,171	0,7	716,1	613,8	0,6138	8,4246	5,1711
4	6,033	0,8	818,4	716,1	0,7161	8,4246	6,0329
4,5	6,895	0,9	920,7	818,4	0,8184	8,4246	6,8948
5	7,757	1	1023	920,7	0,9207	8,4246	7,7566
In the table above, you can see it al starts with Vin and the pressures in Bar that goes with it.
Vadc shows the matching voltages after division, whereas VALadc shows the reading of the ADC. (Vadc/1*1023)
Val-Off shows the ADC reading minus 102,3 for 0,5 volt where pressure is still 0.
/1000 shows an extra division to get Bar instead of mBar and in Correction you might find a factor that makes it all work.
Prove of that can be found in the last column.
to make a long story short, just put (%value%-102.3)/1000*8.425 in the formula section of the device et voila, you have nice and understandable readings.
The more mathematical approach dictates the use of formulas.
Pbar=(VALadc*1/(1023*D)-Offset)*Vbar
D=1/5=0.20 Offset = 0.5 and Vbar=dBar/dV=(4.309-2.586)/1=1.724
In the formula section of the ESPEasy, you can now set (%value%*0.004889-0.5)*1.724

This was implemented on a NodeMCU board.

Image.jpeg