Here I wrote code for my weighting scale measurement. In which I added an on/off switch for my LCD display. But in defined delay time my LCD is a blink and I do not want it. I want my LCD switch on/off work on 1000 delay time effectively. How I can do this. please guide and edit my code.

#include "HX711.h"
#include <LiquidCrystal_I2C.h>

HX711 scale(4, 5);//(DT, SCK)
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int buttonPin = 2;
int buttonState = 0;

float calibration_factor = -55;
float units;
float ounces;
float in_kg;

void setup()
  //  Serial.begin(9600);

  lcd.setCursor(0, 0);
  lcd.print("Calculate Weight");
  lcd.setCursor(0, 1);
  lcd.print("Loading...      ");



void loop()
  units = scale.get_units(), 10;
  if (units < 0)
    units = 0.00;
  ounces = units * 0.035274;
  in_kg = units / 1000;
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH)
    lcd.setCursor(0, 1);
    lcd.print("Reading: ");


    // Display the text on the LCD.
  • If this is the same question / project as your earlier arduino.stackexchange post you should delete this post and edit / change your earlier post.
    – st2000
    Feb 13 at 18:11
  • 1
    @st2000 I deleted the previous question. please help me with this. Feb 13 at 18:14
  • I am not sure what you are asking. It appears the code will display the weight value for 3 seconds and then turn off the back-light and blank the LCD. And it sounds like you would like to change that from 3 seconds to 1 second. Then all you have to do is change delay(3000) to delay(1000).
    – st2000
    Feb 13 at 18:28
  • Don't use lcd.backlight() and lcd.noBacklight(), don't use lcd.noDisplay() every time your program runs the main loop() function. Set those things on once and leave them set.
    – Dougie
    Feb 14 at 0:35
  • @Dougie but I want to implement an on/off display and backlight through the switch on running device. SO how I do this? Feb 14 at 3:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.