Voltage min/max lcd display (cant get min/max to work) :(

Hi!

Im pretty new to this forum but i have heard that its an good place to ask questions :slight_smile:

My problem is, i am trying to display the min and max values from an voltage source.
I wrote/put together this code wich works realy well, exept i cannot get the values to work corectly..
What i am trying to acieve is writing it out like this:

Volt= 0.00
Minv= (min value from volt) Maxv= (max value from volt)
(emty)
Gain xxx%

What i have tryed to implement is different codes from wetherstations (max min temp converted for my volt)
But how i try i cant get it to work propertly..

I guess this is less of an what is wrong and more how do i do it
If anyone would be able to help i would appreciate it alot!

Thanks

The code atm:

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
int analogInput = 0;
float vout = 0.0;
float vin = 0.0;
float R1 = 100000.0; // resistance of R1 (100K) -see text!
float R2 = 10000.0; // resistance of R2 (10K) - see text!
int value = 0;

int potPin = A1; //Potentiometer input pin
int potValue1 = 0;
int potValue2 = 0; // final display variable

void setup(){
pinMode(analogInput, INPUT);
lcd.begin(20, 3);
lcd.setCursor(0,1);
lcd.print("GAIN");

}
void loop(){

// read then divide the input(max 1020 in this case) by 10
potValue1 = analogRead(potPin) / 10;
// divide by 1.02 to get percentage
potValue2 = potValue1 / 1.02;
// set cursor to second row, first column
lcd.setCursor(6, 1);
//display final percentage
lcd.print(potValue2);
//print the percent symbol at the end
lcd.print("%");
//wait 0.1 seconds
delay(20);
//wipe the extra characters
lcd.print(" ");
delay(1);

// read the value at analog input
value = analogRead(analogInput);
vout = (value * 5.0) / 1024.0; // see text
vin = vout / (R2/(R1+R2));
if (vin<0.09) {
vin=0.0;//statement to quash undesired reading !
}
lcd.setCursor(0, 0);
lcd.print("Volt= ");
lcd.print(vin);

delay(400);
}

Welcome,

please use code tags as code might be interpreted as forum mark-up language causing trouble presenting it correctly.

Check this refactored code which includes min and max (you might need to tweak the position on the LCD

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 10, 9, 8, 7);

int analogInput = 0;

float R1 = 100000.0; // resistance of R1 (100K) -see text!
float R2 = 10000.0; // resistance of R2 (10K) - see text!

const int potPin = A1; //Potentiometer input pin

float maxVal = 0;
float minVal = 10;

void setup() 
{
  lcd.begin(20, 3);
  lcd.setCursor(0, 1);
  lcd.print("GAIN");
}

void loop() 
{
  float percentage = analogRead(potPin) / 10.23;
  // set cursor to second row, first column
  lcd.setCursor(6, 1);
  lcd.print(percentage);
  //print the percent symbol at the end
  lcd.print("% ");
  //wait 0.1 seconds
  delay(100);

  float vout = analogRead(analogInput) * 5.0 / 1024.0; // see text
  float vin = vout / (R2 / (R1 + R2));
  if (vin < 0.09) 
  {
    vin = 0.0; //statement to quash undesired reading !
  }
  if (vin < minVal) minVal = vin;
  if (vin > maxVal) maxVal = vin;

  // DISPLAY 
  lcd.setCursor(0, 0);
  lcd.print(vin, 2);  // the extra parameter 2 indicates the decimals
  lcd.print(" ");
  lcd.print(minVal, 1);
  lcd.print("-");
  lcd.print(maxVal, 1);
  delay(400);
}

haha!

Thanks alot!
Will be looking more deeply into this code tomorrow.
Thanks alot for taking the time to sorting out my messy code and helping me with the max/min values.
exacylt how i needed it!

I will uppdate with my results and what its for.