Water pressure gauge on an Arduino Uno
A 0.5 to 4.5 V stainless pressure transducer on a water line and a 16x2 I2C LCD: the pressure in psi and bar, with a warning when it drops. The whole build, an Arduino Uno and 2 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Beginner Runs in your browser. Free, and no account needed.
The parts retail for about $46. On Mokxi they're free.
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// Water pressure gauge: a 0 to 100 psi stainless pressure transducer on a
// water line, and the pressure on a 16x2 I2C LCD in psi and bar.
//
// A0 the transducer's SIG (yellow; red to 5 V, black to GND)
// LCD SDA -> A4 SCL -> A5 VCC -> 5 V GND -> GND
//
// The transducer puts out 0.5 V at no pressure and 4.5 V at full scale, and
// it is ratiometric: 10% and 90% of its supply. The Uno's converter measures
// against the same 5 V, so the sketch works in fractions of the supply and a
// supply a little off cancels out: no 0.5 V or 4.5 V constant appears below.
//
// Each reading is the average of 32 conversions, which smooths the one-step
// jitter a converter has. One step is 0.12 psi on the 100 psi model.
//
// A house supply is 40 to 80 psi; under 20 the sketch says LOW, which is a
// burst pipe or a pump that has stopped.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const float FULL_SCALE_PSI = 100.0; // the model printed on the body
const float PSI_PER_BAR = 14.5038;
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
Serial.begin(115200);
Serial.println("Mokxi Arduino Uno: water pressure gauge");
lcd.init();
lcd.backlight();
}
float readPsi() {
long sum = 0;
for (int i = 0; i < 32; i++) sum += analogRead(A0);
float fraction = sum / 32.0 / 1023.0; // of the supply
float psi = (fraction - 0.1) / 0.8 * FULL_SCALE_PSI;
return psi < 0 ? 0 : psi;
}
void loop() {
float psi = readPsi();
float bar = psi / PSI_PER_BAR;
lcd.setCursor(0, 0);
lcd.print(psi, 1);
lcd.print(" psi ");
lcd.setCursor(0, 1);
lcd.print(bar, 2);
lcd.print(" bar ");
lcd.print(psi < 20 ? "LOW " : " ");
Serial.print("psi: ");
Serial.print(psi, 1);
Serial.print(" bar: ");
Serial.println(bar, 2);
delay(250);
}
Parts list
4 parts, plus the jumper wires. They retail for about $46; on Mokxi they're free.
How it is wired
5 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- Arduino Uno R3 pin 5V; Pressure sender, 0.5-4.5 V pin VCC; Character LCD with I2C backpack pin VCC
- Ground: Arduino Uno R3 pin GND; Pressure sender, 0.5-4.5 V pin GND; Character LCD with I2C backpack pin GND
- Arduino Uno R3 pin A0; Pressure sender, 0.5-4.5 V pin SIG
- Arduino Uno R3 pin A4; Character LCD with I2C backpack pin SDA
- Arduino Uno R3 pin A5; Character LCD with I2C backpack pin SCL
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.