Hold peak value from sensor

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
  ;
}

Welcome to the forum

Where are you stuck and what have you tried ?

Holding the max value should be easy. Read the value and if it is greater than the previous highest value save it as the highest value and print it

Resetting the value every 4 seconds involves saving the value of millis() when the period starts, then, every time through loop() testing whether 4 seconds has elapsed by subtracting the start time from the current value of millis().

If the period has not elapsed then just keep going round loop() until it has elapsed. Once the period elapses reset the highest value to zero, save the current value of millis() and off you go again

Thanks for your greets,

Regarding the code: I am not that proficient with arduino code, therefore if you have any practical advice how to actually handle it would be a dream to me. Of course, if you have enough time

thanks

unsigned long timeOfTheThing = 4000;
unsingned long timePast = millis();

voiding loops()
{

if  ( (millis()-timePast) >= timeOfTheThing)
{
//get new highest thing
timePast=millis();
}

}

There are other ways to wait for 4 seconds but this may do. See File|Examples|02.BilinkWithoutDelay

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.