water pump pressure switch


first time poster on the forum. Have a background in transmission and distribution and a little experience programming in basic and assembly.

Basically i’m wondering if my code will achieve what i want it to.
It is supposed to take a reading from a pressure transducer (0-5v) convert it to a value between 0-200 psi and display it on an LCD.

if the psi in the water line drops below 30 psi a diaphragm pump will turn on until the line is back to the working pressure (50psi).

a solenoid valve will be on for 5 seconds and off for 5 minutes perpetually.

any words of warning or advice are appreciated. The only reason i’m not testing the code out and troubleshooting through trial and error is because i do not want to risk damage to any equipment.

anyways here is my code

// This is a sketch for controlling an aeroponic growing system.

// int tempReading = analogRead(temperature); //gets the raw reading from the temperature sensor
// float tempVolts = tempReading * 5.0 / 1024.0; //converts to a value between 0-5v
//float tempC = (tempVolts - 0.5) * 100.0; // converts to a reading in Celcius (C)
// const int temperature = 1; // use analog input 1 to meaasure temperature of the growing chamber

#include <LiquidCrystal.h>

const int Solenoid_Pin = 4; //use digital pin 4 to control solenoid
const int pump_Pin = 2; //use digital pin 2 to turn control pump
const int Pressure_Pin = 0; // use analog input 0 to measure the line water pressure

// BS E D4 D5 D6 D7
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);


void setup() {
// put your setup code here, to run once:
pinMode(Solenoid_Pin, OUTPUT);
pinMode(pump_Pin, OUTPUT);

lcd.begin(16, 2);



void loop() {
// calls the main functions
//reads the raw value from pressure transducer and converts it into psi
// prints the psi value to LCD
// if the pressure in the line is under 30 psi then the pump turns on until the pressure is back up to 50 psi then turns off
//the solenoid is turned on opening the valve and activating the misters for 5 seconds and then turns off for 5 minutes

SenseCalibrate ();
lcd ();

if (psi <== 30) {
pumpPressureSwitch(); //this string turns the pump on to fill up the accumulator tank if the pressure in the line drops below 70 psi
mister ();



void SenseCalibrate () {

int reading = analogRead(Pressure_Pin); //gets the raw reading from the pressure sensor
float int psi = reading * 0.2; //converts the raw reading to a value between 0-200 psi

void lcd () {

lcd.setCursor(0, 0);
// ----------------
lcd.print("psi ");
lcd.setCursor(5, 0);

//loop will run when cut-in pressure (30psi) is reached and will stop when working pressure is reached (50psi)
void pumpPressureSwitch() {

while (psi >== 0 && psi <==50) {
digitalWrite(pump_Pin, HIGH);

if (psi >== 50) {
digitalWrite(pump_Pin, LOW); // turn the pump off by making the voltage LOW


void mister () {

digitalWrite(Solenoid_Pin, HIGH); // turn the solenoid on (HIGH is the voltage level)
delay(5000); // opens for a 5 seconds
digitalWrite(Solenoid_Pin, LOW); // turn the solenoid off by making the voltage LOW
delay(300000); // closes for 5 minutes

You have written rather too much code without testing, based on the fact that what you have doesn't compile. I'd suggest you write a new sketch that just reads the pressure gauge and outputs the result to serial. Then add the LCD etc etc.

And a diagram of how things are connected, both plumbing and electrical. Such as what does the solenoid do? and where and how is it connected and controlled.


delay(300000) ; // closes for 5 minutes

Either learn to use millis() to create timing, or get another hobby.



I do not know what it is your concern you can still compile/debug your sketch without connecting it to your equipment. You can plug some values to test if you have any problem in your program logic. When everything run without error then you can test it in your equipment.

delay(300000) ; // closes for 5 minutes

Either learn to use millis() to create timing, or get another hobby.

Ouch! You miss dinner or something?

-jim lee