In this project I’ve been trying to make the lcd screen say one thing, but once something comes in front of the ultrasound I want it to say another thing once. However it just adds the second comment repeatedly over and over again. I’m a beginner at this(just to let you know). Here’s the code:

#define trigPin 4
#define echoPin 2
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print(“What’s my name?”);

void loop() {
long duration, distance;
digitalWrite(trigPin, LOW); //Hehe
digitalWrite(trigPin, HIGH);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance < 4) { //this is where the LED turns on/off

You are aware that the loop function repeats over and over but setup only runs once right? So as long as something is in front of the sensor and that if statement is true it's going to keep writing that word to the screen over and over as the loop function repeats. Once you remove the object that word will stay on the screen because you never tell it to do anything differently when the distance is greater than 4.