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.
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
.
Call the Library.
#include <LiquidCrystal_PCF8574.h>
Define the LCD address.
LiquidCrystal_PCF8574 lcd(0x27); //change "0x27" to "0x3F" accordingly
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!"
}
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);
}