2 row x 2 row, with Switch - Work Fine !

hello World,

I want to keep track of 4 variables
oil temperature, oil pressure, water temperature, battery voltage, and
because I use 2 line display/16 digits, I by button or switch to turn on the display. I read a lot when you get here, but the program does not work properly.
Able to change the display of variables, but not the text to them.
Ask for assistance. I would be grateful.
??? ????? ???? ?????????, ???? ?? ?????? ? ??? ?? ?????: d_a_f_y_z
I apologize for using the google translator

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 4);
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  
}

  // the loop routine runs over and over again forever:
void loop()
{

// read the value of the key:
  int analogValue = analogRead(A3);
  if (A3<1)
  {
    lcd.setCursor(0, 0);
  // read the input on analog pin 0:
  int sensorValue0 = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue0 * (5.0 / 1023.0);
    lcd.print("Water = ");
    lcd.print(voltage);
    lcd.print(" C");
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
 int sensorValue1 = analogRead(A1);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage1 = sensorValue1 * (5.0 / 1023.0);
  // print out the value you read:
  lcd.print("Oil   = "); 
  lcd.print(voltage1); 
  lcd.print(" C");
  }
 else if(A3 > 4);
{
  lcd.setCursor(0, 0);
  // read the input on analog pin 0:
  int sensorValue2 = analogRead(A7);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage2 = sensorValue2 * (5.0 / 1023.0);
    lcd.print("voltage= "); 
    lcd.print(voltage2); 
    lcd.print(" V");
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  int sensorValue3 = analogRead(A6);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage3 = sensorValue3 * (5.0 / 1023.0);
  // print out the value you read:
   lcd.print("presure= ");
   lcd.print(voltage3);
   lcd.print(" C");

}
}

you have lcd.begin(16,4) in setup but you say it is 2 lines

you have lcd.begin(16,4) in setup but you say it is 2 lines

That will not be a problem.

I think you may be trying to rewrite your display too rapidly. Try putting a delay at the end of your loop().

Don

I tried everything you said, but to no avail ...
values ??of the analog inputs are changed, but not the captions / oil, water, volts, pressure / ...
and the program would be true ...
Fixed display is 16h2 ...
I put a delay (1) ... (10)
no difference ... only variable inputs are changed by pressing the button.
if necessary, could be released clip on youtube for visibility ...

look at the <<<< lines

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() 
{
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);

}

// the loop routine runs over and over again forever:
void loop()
{

  // read the value of the key:
  int analogValue = analogRead(A3);
  
  if (analogValue <100) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  {
    lcd.setCursor(0, 0);
    // read the input on analog pin 0:
    int sensorValue0 = analogRead(A0);
    // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
    float voltage = sensorValue0 * (5.0 / 1023.0);
    lcd.print("Water = ");
    lcd.print(voltage);
    lcd.print(" C");
    // set the cursor to column 0, line 1
    // (note: line 1 is the second row, since counting begins with 0):
    lcd.setCursor(0, 1);
    int sensorValue1 = analogRead(A1);
    // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
    float voltage1 = sensorValue1 * (5.0 / 1023.0);
    // print out the value you read:
    lcd.print("Oil   = "); 
    lcd.print(voltage1); 
    lcd.print(" C");
  }
  else if(analogValue > 100);  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  {
    lcd.setCursor(0, 0);
    // read the input on analog pin 0:  pin0 you say a7???? <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    int sensorValue2 = analogRead(A7);  
    // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
    float voltage2 = sensorValue2 * (5.0 / 1023.0);
    lcd.print("voltage= "); 
    lcd.print(voltage2); 
    lcd.print(" V");
    // set the cursor to column 0, line 1
    // (note: line 1 is the second row, since counting begins with 0):
    lcd.setCursor(0, 1);
    int sensorValue3 = analogRead(A6);
    // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
    float voltage3 = sensorValue3 * (5.0 / 1023.0);
    // print out the value you read:
    lcd.print("presure= ");   <<<<<<<<<<<<<<<  pressure but you write voltage
    lcd.print(voltage3);      <<<<<<<<<<<<<<<<
    lcd.print(" C");

  }
}

tips:

  • CTRL-T does auto formatting
  • keep your comments and code in line...

thank you so mutch !
only one: delay(50); - is missing because display tray type 4 variable together...

// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() 
{
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop()
{
  // read the value of the key:
  int analogValue = analogRead(A3);
  if (analogValue <300)
  {
    lcd.setCursor(0, 0);
    // read the input on analog pin 0:
    int sensorValue0 = analogRead(A0);
    // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
    float voltage = sensorValue0 * (5.0 / 1023.0);
    lcd.print(" Water = ");
    lcd.print(voltage);
    lcd.print(" C");
    // set the cursor to column 0, line 1
    // (note: line 1 is the second row, since counting begins with 0):
    lcd.setCursor(0, 1);
    int sensorValue1 = analogRead(A1);
    // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
    float voltage1 = sensorValue1 * (5.0 / 1023.0);
    // print out the value you read:
    lcd.print(" Oil   = "); 
    lcd.print(voltage1); 
    lcd.print(" C");
    delay(50);      //<<<<<<<<<<< <<<<< <<<<< <<<
  }
   else if(analogValue >100); 
  {
    lcd.setCursor(0, 0);
    // read the input on analog pin 7
    int sensorValue2 = analogRead(A7);  
    // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
    float voltage2 = sensorValue2 * (5.0 / 1023.0);
    lcd.print("voltage= "); 
    lcd.print(voltage2); 
    lcd.print(" V");
    // set the cursor to column 0, line 1
    // (note: line 1 is the second row, since counting begins with 0):
    lcd.setCursor(0, 1);
    int sensorValue3 = analogRead(A6);
    // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
    float voltage3 = sensorValue3 * (5.0 / 1023.0);
    // print out the value you read:
    lcd.print("presure= ");  
    lcd.print(voltage3);   
    lcd.print(" C");
  }
}

now everthing is only calibration sensors :wink:
i'm verry happy !

P.S. Now i`ll try to change Switch with button(triger - on/off). if anybody konw how, i will try. thanks !