Struck with LCD Display

Im Using HC-SR04 Sensor to calculate the distance and have set the threshold value to 80. The code I have attached is working fine without LCD display part (Commented off) in the terminal port. But with LCD display code output is just showing LCD off, and distance value 0. What might be the reason that Im getting proper output without LCD Display code part and with it improper output? Can anyone help me to fix the problem in my code?

UltrasonicSensor.ino (1.71 KB)

Hi.

Your problem starts from line 4 and is complete at line 9 of your code:

#define trigPin 2
#define echoPin 3

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

You're using pins 2 and 3 for two separate pieces of hardware.
Using either one of those will break the other.

This is the first thing you should check when you try to combine 2 different sketches, and prevent this from happening.

So find out if there's some special reason someone else might have picked these pins, and if not then change pins to some other pins which are free to use.

Hint: analog pins can be used as digital pins, if you don't need the analog part (but i don't think you need to do this here).