The LCD screen (Liquid Crystal Display screen) is used to display a text/numeric message.

It has 16 columns and 2 rows, as it is a 16x2 LCD.

Examples:

  1. To a person who switches off lights and fans when not in use, LCD displays "You are wonderful for saving 3W of energy by switching off light when not in use!".
  2. To a person who uses more water than required, LCD displays "Please turn off the tap. Save water."

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/a087c1e8-0930-4760-877c-313c00c41835/Output_LCDScreen-01.jpg

LCD Address:

Every LCD screen has an address which will help the LCD communicate with the Arduino.

Find a sticker on the LCD screen of your kit that says either 0 x 27 or 0 x 3F.

Code

  1. Call the Library.

    #include <LiquidCrystal_PCF8574.h>
    
  2. Define the LCD address.

    LiquidCrystal_PCF8574 lcd(0x27); //change "0x27" to "0x3F" accordingly
    
  3. Begin.

    void setup() {
      Serial.begin (9600); //this is baud rate-it tells the Arduino at what speed to send signals
      lcd.begin(16, 2); //this begins the LCD screen cursor
      lcd.setBacklight(255); //this brightens up the LCD screen backlight
      lcd.home(); //this positions the cursor at upper left corner
      lcd.print("Hi Solve Ninjas!"); //this prints text "Hi Solve Ninjas!"
     }
    
  4. Loop

    void loop() {
      delay(100);
      int timetaken, dist;
      digitalWrite(trigPin, HIGH);
      delayMicroseconds(1000);
      digitalWrite(trigPin, LOW);
      timetaken = pulseIn(echoPin, HIGH);
      dist = (timetaken / 2) * 0.034049 ;
      lcd.setCursor(0, 0);
      lcd.print("Distance in CM:");
      lcd.setCursor(0, 1);
      lcd.println(dist);
      delay(100);
      
    }
    

Get Creative