Hello everyone,
I am having an hard time, so any help will be appreciated.
The following code provides a real time values reading out of a pressure sensor.
I would like to hold the max value being captured by the sensor in line 2, while line 1 continue to displays realt time values.
This is a scheme of how the output could look like :
LCD screen ->
line 1 line 2
1 1
2 2
3 3
4 4
2 4
1 4
6 6
3 6
and so on...
More over, i would like to reset the peak value once every 4 seconds.
Thanks in advance for your help!
#include "Wire.h"
#include "LiquidCrystal.h"
#include <SPI.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int pressureInput = A0; //select the analog input pin for the pressure transducer
const int pressureZero = 112.5; //analog reading of pressure transducer at 0psi
const int pressureMax = 1512; //analog reading of pressure transducer at 150psi
const int pressuretransducermaxPSI = 150; //psi value of transducer being used
const int baudRate = 9600; //constant integer to set the baud rate for serial monitor
const int sensorreadDelay = 250; //constant integer to set the sensor read delay in milliseconds
float pressureValue = 0; //variable to store the value coming from the pressure transducer
void setup(){ //setup routine, runs once when system turned on or reset
Serial.begin(baudRate); //initializes serial communication at set baud rate bits per second
lcd.begin(16, 2); //initializes the LCD screen
lcd.setCursor(0,1);
}
void loop() {
const int pressureInput = A0; //select the analog input pin for the pressure transducer
const int pressureZero = 112.5; //analog reading of pressure transducer at 0psi
const int pressureMax = 1512; //analog reading of pressure transducer at 100psi
const int pressuretransducermaxPSI = 150; //psi value of transducer being used
const int baudRate = 9600; //constant integer to set the baud rate for serial monitor
const int sensorreadDelay = 250; //constant integer to set the sensor read delay in milliseconds
float pressureValue = 0; //variable to store the value coming from the pressure transducer
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
pressureValue = analogRead(pressureInput); //reads value from input pin and assigns to variable
pressureValue = ((pressureValue-pressureZero)*pressuretransducermaxPSI)/(pressureMax-pressureZero); //conversion equation to convert analog reading to psi
Serial.print(pressureValue, 1); //prints value from previous line to serial
Serial.println("psi"); //prints label to serial
lcd.setCursor(0,0); //sets cursor to column 0, row 0
lcd.print("Pressure:"); //prints label
lcd.print(pressureValue, 1); //prints pressure value to lcd screen, 1 digit on float
lcd.print("psi"); //prints label after value
lcd.print(" "); //to clear the display after large values or negatives
delay(sensorreadDelay); //delay in milliseconds between read values
;
}