I use an ultrasonic distance sensor hc-sr04 to display distance on an i2c lcd monitor, in general the business works fine but at certain distances it displays not so correct numbers. For example in the picture above he brings the number 1198 at a distance of 30 cm from the wall. This lie happens at different distances and in different numbers on the monitor. It is important for me to note that on the serial screen the numbers shown are correct and the forgery only appears on the LCD screen.
This is very detrimental to the whole project ...
The problem with the program (attached) or the problem with the component?
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define trigPin 13
#define echoPin 12
double duration, distance;
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance >= 30 || distance <= 0)
Serial.println("out of range");
lcd.print ("out of range");
lcd.print ("be careful ");