Water pressure sensor and arduino

Thread Starter

Guytas

Joined Apr 29, 2021
32
I have a 10psi pressure sensor. It is connected to 5vdc. Its output is from 0.5v to 4.5v. I have this sensor on a tank. It is hooked up to the analog pin A0 of the arduino to read the voltage and I translate the voltage into pressure, thus, i can calculate how much water there is in the tank.
I have found several p’aces on the net that shows how to hook it up. Actually, it is very simple... the red to vcc 5 volts, the black to ground, and the green to signal A0 of the arduino. They all hook it up that way. But somehow, the reading of the voltage is a bit unstable. With the large tank, it represents several litres difference. But.... when I hook up the voltmeter on it, the voltage becomes stable (in both the voltmeter and in the arduino). I have tried to put a pull down resistor 10k but it made no difference at all. How can I fix this so I wont need to leave the voltmeter on it all the time?
 

dendad

Joined Feb 20, 2016
4,168
You may have noise on the signal read so add a series 10K resistor between the sensor out and A0, then a capacitor 100nF from A0 to GND.
Also, as the Arduino by default used the +5V as the ref voltage, it will be a bit unstable as varoius things switch, so try the intenal Vref instead/

https://www.arduino.cc/reference/en/language/functions/analog-io/analogreference/

This may need a voltage divider in the A0 input to scale it to suit the new Vref value, I don't quite remember.
 

MisterBill2

Joined Jan 23, 2018
12,402
There may also be noise on the supply to the pressure transducer. the common connection arrangement is important, and also shielding the signal wire might be important.
If connecting your meter makes the reading stable, then there may also be a connection issue. That is, there might be a noisy connection.
 

Thread Starter

Guytas

Joined Apr 29, 2021
32
You may have noise on the signal read so add a series 10K resistor between the sensor out and A0, then a capacitor 100nF from A0 to GND.
Also, as the Arduino by default used the +5V as the ref voltage, it will be a bit unstable as varoius things switch, so try the intenal Vref instead/

https://www.arduino.cc/reference/en/language/functions/analog-io/analogreference/

This may need a voltage divider in the A0 input to scale it to suit the new Vref value, I don't quite remember.
Ok I’ll try the resistor capacitor. The internal vref is 2.54 on this micro arduino. I think if the resistor capacitor is enough, Ill keep the 5 volts (5.04 in my case). This will probably be enough. Thanks
 

Thread Starter

Guytas

Joined Apr 29, 2021
32
There may also be noise on the supply to the pressure transducer. the common connection arrangement is important, and also shielding the signal wire might be important.
If connecting your meter makes the reading stable, then there may also be a connection issue. That is, there might be a noisy connection.
The cable is so short, I dont think it will cause an issue there. The cable is less than a meter long. And I have disconnect and reconnect everything several time already. I suspect that doing so will have made some kind of change if the connection would be in trouble. Dont you think so?
i’ll try Dendad’s suggestion and see how it goes. Thanks
 

MisterBill2

Joined Jan 23, 2018
12,402
Keepin mind that ground loops in the wiring will cause problems, and that actually a ground loop section is any portion of a circuit where current other than the signal current flows in a conductor along with the signal current. With that definition you may be able to locate your noise source, if it is from a ground loop. There are also other noise sources, of course.
 

Thread Starter

Guytas

Joined Apr 29, 2021
32
Keepin mind that ground loops in the wiring will cause problems, and that actually a ground loop section is any portion of a circuit where current other than the signal current flows in a conductor along with the signal current. With that definition you may be able to locate your noise source, if it is from a ground loop. There are also other noise sources, of course.
Sadly, dendad’s suggestion did not work. I was sure it would be ok. But it’s not. Not sure what the ground loops is. But here is more info...
I hooked up an oscilloscope on it. It does the same thing... i.e. as soon as it is hooked up, the voltage is stable again. The scope doesn’t even need to be powered. Anyhow, I’m not an expert in oscilloscope but I can see big square wave appearing every once in a while. About the same « while » as the fluctuation (even if I dont see any fluctuation while the scope is hooked up).
So this kind of wave must be coming from the arduino itself. Notsure how but I wouldn’t think static could cause a square wave like that. I’ll clean up my code and put it here in case someone can see something.
 

Thread Starter

Guytas

Joined Apr 29, 2021
32
ok, I think I pinpoint the problem... not 100% sure but hey... looks like it's the old iPhone charger that I was using. I tried to power it up with my car booster (that has an USB output) and it was stable. I used another USB charger and it is less unstable than the iPhone one. It is almost perfect now. So I need to find a better USB charger. Any suggestion anyone?
 

Thread Starter

Guytas

Joined Apr 29, 2021
32
ha... I have declared victory too soon... The fluctuations are back... even with the car booster. :( I'm really not sure what to do next. What is that "ground loops" thing?
 

dendad

Joined Feb 20, 2016
4,168
Just for a test, try running it on batteries.
It is sounding like the noise is capacitivly coupled through your plug pack and the earth from the scope is fixing the noise problem.
Most phone chargers are pretty bad.
An analog power supply, that is an old unregulated plug pack that has a transformer, rectifier and capacitor only may be the way to go. Get a 9V or 12V one and if you need extra 5V, add a 7805 reg on a heat sink, with a 10uF cap on the input and output pins to 0V. But the Arduino reg is probably enough.
Just note, a 12V unregulated supply may output 18V with no load.
Or just connect an external Earth to the 0V line.
 

Thread Starter

Guytas

Joined Apr 29, 2021
32
Just for a test, try running it on batteries.
It is sounding like the noise is capacitivly coupled through your plug pack and the earth from the scope is fixing the noise problem.
Most phone chargers are pretty bad.
An analog power supply, that is an old unregulated plug pack that has a transformer, rectifier and capacitor only may be the way to go. Get a 9V or 12V one and if you need extra 5V, add a 7805 reg on a heat sink, with a 10uF cap on the input and output pins to 0V. But the Arduino reg is probably enough.
Just note, a 12V unregulated supply may output 18V with no load.
Or just connect an external Earth to the 0V line.
wow, yes these sounds all good things to try. Thanks. Please note that the scope was running from battery so no earth.
Right now I just finished testing with the internal ref but still same problem.
OK, I'll try with a 9v battery on Vin. right?
 

Thread Starter

Guytas

Joined Apr 29, 2021
32
OK, I've checked on internet and the Vin was the right pin for external 9v battery so I did try it. Sadly, the problem is still present. In one minute, I can get about 4 to 6 bad reading (at the rate of one reading per second).
While the voltmeter (or the scope) was connected, I didn't get any error in 2 days. My program consider a bad reading if the voltage is more different than 0.2 volts in 1 second.
It is a big question in my head that a high impedance meter can fix this problem...
Considering that the battery is still doing the problem, I don't think trying to find a better power supply at this moment is not of any help.
hum... Thinking of another possible source...
This arduino is connected to a raspberry pi via the tx and rx pins (and of course GND). May be this is a conflict... (but I have another similar situation elsewhere in the house and that one runs smoothly).

From your suggestions, the only one left to try was to put GND to earth. Are you sure I should try that considering the arduino and raspberry pi linked together?
 

MisterBill2

Joined Jan 23, 2018
12,402
I explained what a a ground loop is in detail in post #6. But now if connecting a scope stops the instability then it is probably an issue in the "ground" (common) part of the circuit.
Seeing neither the assembly nor the actual circuit I can not even guess beyond that.
 
Last edited:

Thread Starter

Guytas

Joined Apr 29, 2021
32
89639E98-71AB-466D-8BCB-CD406D8D21FC.jpeg
You will not believe what I’ve found. I’m looking at it and don’t believe it myself.... but I sure hope someone here can explain it to me so I can fix it the right way.

this morning I unplug the scope but left the wires hooked up to the arduino. Amazingly the problem didn’t come back... the voltage was stable.waited a couple of hours and still had no issue.

I then remove the ground wire; still no problem.
I then remove the signal wire (the one attached to A0). Then it was unstable again. Reading about one faulty voltage every 5 seconds.
I then attached a 50cm jumper wire on A0. The problem was reduced to about one faulty reading every 30 to 40 seconds.
I added another 50cm at the end of the jumper cable. The problem went away completly. Absolutely no error after 3000 reading.

so at the end, leaving a meter long cable on A0 line is not so bad, but what the heck is happening here? I would imaging that this cable would act as an entenna and make the problem worst... but in the contrary it solves the issue.

I never saw something like this before. And to tell you the truth, I’m kind of afraid that the problem comes back again one day. Unless someone can explain to me what is really happening...

looking forward to hear from you guys....
 

MisterBill2

Joined Jan 23, 2018
12,402
It is indeed an uncomfortable feeling when a "magic fix" happens and there is no clue what I did to make it happen. If there is a terminal strip soldered to a PCB, I suggest that a solder joint has become intermittent because of screw torque breaking the solder. And certainly if a repair or change is not made, the problem will return at an inconvenient time.
 

dendad

Joined Feb 20, 2016
4,168
And you need to mount it all on a soldered proto board to get rid of those plug in wires. they are not known for reliability. Also, the lead lengths can cause trouble.
I have made quite a few designs that just use the Arduino Nano an another component.

TrackerVFO4.JPG
For example, this is a VFO installed in a Tracker HF transceiver.
So, once you get the design worked out, the next step is to construct it better.
 
Last edited:

Reloadron

Joined Jan 15, 2015
6,701
I have a 10psi pressure sensor. It is connected to 5vdc. Its output is from 0.5v to 4.5v. I have this sensor on a tank. It is hooked up to the analog pin A0 of the arduino to read the voltage and I translate the voltage into pressure, thus, i can calculate how much water there is in the tank.
I have found several p’aces on the net that shows how to hook it up. Actually, it is very simple... the red to vcc 5 volts, the black to ground, and the green to signal A0 of the arduino. They all hook it up that way. But somehow, the reading of the voltage is a bit unstable. With the large tank, it represents several litres difference. But.... when I hook up the voltmeter on it, the voltage becomes stable (in both the voltmeter and in the arduino). I have tried to put a pull down resistor 10k but it made no difference at all. How can I fix this so I wont need to leave the voltmeter on it all the time?
Poor connections aside for a moment. My best guess here is since you mention using a pressure sensor with a range of 0 to 10 PSI and the conversion for water in a tank is 1.0 PSI = 27.7076 inches of water column. So a 0 t0 10 PSI would be 0 to 277.076 inches of water column. Your full scale would be about a 24.0 foot tall tank. Simply put a 0 to 10 PSI becomes 0.5 to 4.5 volt signal.

Typical DVM meters have a typical 10 Meg Ohm input impedance. While, other than poor connection I see no reason for what you are seeing but you could place a 10 Meg Ohm load across the sensor output. This would simulate your DMM being out there and again I see no reason for this. Not with good solid connections anyway,

On your input you map your code. For example using a 10 bit Arduino having a 5.00 volt analog reference 0.0 to 5.0 Volts full scale becomes 0 to 1023 quantization levels as to bit counts. That's about 4.882 mV per bit. So starting with your 0.0 PSI input being 0.5 Vout sensor the 0.0 PSI becomes 0.5 / .004882 = 104,166 bits and your 4.5 volts becomes 4.5 / .004882 = 933.609 bits. Then you just MAP your A0 analog input in your code. Just know your Arduino actual Vreference.

Your sensor can be mounted at the bottom of the tank or use a bubbler design. a simple Google of bubbler level sensor.

Ron
 

MisterBill2

Joined Jan 23, 2018
12,402
More considerations here: Because the pressure transducer only has three leads, it comes with a built in ground loop that is unavoidable. (See the ground loop definition in post #6). Also, since the transducer is a ratiometric device, every bit of power supply noise is transferred to the output, along with the pressure signal. So there are two noise sources already.
 

k1ng 1337

Joined Sep 11, 2020
584
View attachment 270650
You will not believe what I’ve found. I’m looking at it and don’t believe it myself.... but I sure hope someone here can explain it to me so I can fix it the right way.

this morning I unplug the scope but left the wires hooked up to the arduino. Amazingly the problem didn’t come back... the voltage was stable.waited a couple of hours and still had no issue.

I then remove the ground wire; still no problem.
I then remove the signal wire (the one attached to A0). Then it was unstable again. Reading about one faulty voltage every 5 seconds.
I then attached a 50cm jumper wire on A0. The problem was reduced to about one faulty reading every 30 to 40 seconds.
I added another 50cm at the end of the jumper cable. The problem went away completly. Absolutely no error after 3000 reading.

so at the end, leaving a meter long cable on A0 line is not so bad, but what the heck is happening here? I would imaging that this cable would act as an entenna and make the problem worst... but in the contrary it solves the issue.

I never saw something like this before. And to tell you the truth, I’m kind of afraid that the problem comes back again one day. Unless someone can explain to me what is really happening...

looking forward to hear from you guys....
By adding jumpers, I think you basically added a decoupling capacitor.

I have been following your topic, since you still have problems, I suggest:

1) Post a schematic, datasheet and code

2) Adding several decoupling capacitors, try different positions. I have one module that needed a cap across the power pins and from VCC/GND to OUT. IIRC it was from VCC to OUT. The datasheet said nothing about decoupling OUT

3) Ensure the reference voltage is stable under load, your module could be pulling power from it making it unstable

4) Confirm your module(s) are not defective, measure some currents

4) From the photo, your board is hanging in the air. Get it flat and stable so the jumpers are not being stressed

5) Average your readings in the code and offset any error

6) Try another module / verify the ADC is operating normally

7) Confirm you are properly implementing the ADC reading as suggested by the manufacturer(s)


These steps (in no specific order) got rid of all my ADC problems. I haven't found the need for adding resistors though you could try a few arrangements with caps to form a filter.
 
Top