Program not entering loop()

I’m totally new to arduino and using it for the first time.
Here is a part of code I’m making for my final year project in Electrical Engineering.
It is supposed to read a voltage at pin 9 when push button is pressed at pin 7.
The maximum and minimum voltage varies from equipment to equipment so push button at pin 8 is there to calibrate it.
I simulated it on proteus and it seems to work fine till the setup loop.
Its not recognizing the two statements:

if (CalibInput == HIGH )
if( buttonState == HIGH )

because it doesnt matter if I press the push buttons the LCD state doesnt change

Any help would be appreciated.

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const int pushButton  = 7;
const int CalibInput = 8;
const int VoltageLine = 9;
int VoltageMin = 1023; 
int VoltageMax = 0;
int Voltage_ADC;
int sensorValue;

void setup() {
  
  Serial.begin(9600);
  delay(50);
  
  pinMode(pushButton, INPUT);
  pinMode(VoltageLine, INPUT);
  pinMode(CalibInput,INPUT);
    
 
  lcd.begin(16, 2);
  
  lcd.print("Fluid Automation");
  lcd.setCursor(0, 1);
  lcd.print("System");
  delay(3000); 
  lcd.clear();
  lcd.println("<1> Calibrate");
  lcd.setCursor(0, 1);
  lcd.println("<2> Check");
}




void loop() {
  
  if (CalibInput == HIGH )
    {   
 
  lcd.clear();            
   lcd.println("Calibrating");
   while (millis() < 10000) {
    sensorValue = analogRead(VoltageLine);

   
    if (sensorValue > VoltageMax) {
      VoltageMax = sensorValue;
    }

    
    if (sensorValue < VoltageMin) {
      VoltageMin = sensorValue;
    }
  }
    Voltage_ADC = map(sensorValue, VoltageMin, VoltageMax, 0, 100); 
  }
       
  int buttonState = digitalRead(pushButton);
    
  while (!Serial.available());  


  if( buttonState == HIGH ) 
    {
  lcd.setCursor(0, 1);
  lcd.print(Voltage_ADC);
  Serial.println(Voltage_ADC);
  } 
  
  delay(50);
}

In the first case you aren’t reading the pin state, just comparing the pin number to high. Look at how you’ve used digitalRead later in the code.

For the second, you’re waiting for serial input before you read the button. Assuming your wiring is right, holding the button down and then sending some serial data should work.

HIGH is 1.
CalibInput is 8.

 if (CalibInput == HIGH )

Will never be true.
Try reading the pin.

Thanks guys it worked :) but now the loop is running only once :(. It only checks for calibration or voltage and then if i change the push button state nothing happens. Any ideas?

Any ideas?

Any code?

Khetran: Any ideas?

Sounds like there may be a bug in your code.

Same one just made the corrections suggested above

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const int pushButton  = 7;
const int CalibInput = 8;
const int VoltageLine = 9;
int VoltageMin = 1023; 
int VoltageMax = 0;
int Voltage_ADC;
int sensorValue;

void setup() {

  Serial.begin(9600);
  delay(50);

  pinMode(pushButton, INPUT);
  pinMode(VoltageLine, INPUT);
  pinMode(CalibInput,INPUT);


  lcd.begin(16, 2);

  lcd.print("Fluid Automation");
  lcd.setCursor(0, 1);
  lcd.print("System");
  delay(3000); 
  lcd.clear();
  lcd.println("<1> Calibrate");
  lcd.setCursor(0, 1);
  lcd.println("<2> Check");
}




void loop() {

  int CalibrationState = digitalRead(CalibInput);
  if (CalibrationState  == HIGH )
  {   

    lcd.clear();            
    lcd.println("Calibrating...");

    sensorValue = analogRead(VoltageLine);


    if (sensorValue > VoltageMax) {
      VoltageMax = sensorValue;
    }


    if (sensorValue < VoltageMin) {
      VoltageMin = sensorValue;

    }
    Voltage_ADC = map(sensorValue, VoltageMin, VoltageMax, 0, 100); 
  }

  int buttonState = digitalRead(pushButton);

  if( buttonState == HIGH ) 
  {
    lcd.clear();   
    lcd.print("Checking...");
    lcd.setCursor(0, 1);
    lcd.print(Voltage_ADC);
    while (!Serial.available()); 
    Serial.println(Voltage_ADC);
  } 

  delay(50);
}

How are the switches wired? You've got pulldown resistors on them?

Why do you wait for serial input when the push button is pressed?

Here it is:

Still can’t see how the switches are wired, but it looks to me like they could be floating.

Check and Calibrate push buttons are connected to power on one end and to the controller on the other or you are talking about some other swithces?

and for +4 volts i’m getting 819 on lcd

made the line voltage analog and did the changes in cct and code

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const int pushButton  = 7;
const int CalibInput = 8;
const int VoltageLine = A0;
int VoltageMin = 1023; 
int VoltageMax = 0;
//int Voltage_ADC;
int sensorValue;

void setup() {

  Serial.begin(9600);
  delay(50);

  pinMode(pushButton, INPUT);
  pinMode(VoltageLine, INPUT);
  pinMode(CalibInput,INPUT);


  lcd.begin(16, 2);

  lcd.print("Fluid Automation");
  lcd.setCursor(0, 1);
  lcd.print("System");
  delay(3000); 
  lcd.clear();
  lcd.println("<1> Calibrate");
  lcd.setCursor(0, 1);
  lcd.println("<2> Check");
}




void loop() {

  int CalibrationState = digitalRead(CalibInput);
  if (CalibrationState  == HIGH )
  {   

    lcd.clear();            
    lcd.println("Calibrating...");

    sensorValue = analogRead(VoltageLine);


    if (sensorValue > VoltageMax) {
      VoltageMax = sensorValue;
    }


    if (sensorValue < VoltageMin) {
      VoltageMin = sensorValue;

    }
  //  Voltage_ADC = map(sensorValue, VoltageMin, VoltageMax, 0, 100); 
  }

  int buttonState = digitalRead(pushButton);
    int Voltage_ADC= analogRead(VoltageLine) ;  
  if( buttonState == HIGH ) 
  {
    lcd.clear();   
    lcd.print("Checking...");
    delay(1000);
    lcd.clear(); 
    lcd.setCursor(0, 0);
    lcd.print(Voltage_ADC,DEC);
    while (!Serial.available()); 
    Serial.println(Voltage_ADC,DEC);
  } 

  delay(50);
}

Check and Calibrate push buttons are connected to power on one end and to the controller on the other

So they're floating. Connect them to ground instead, enable the built-in pullups and reverse your logic, so that they read LOW when pressed.