It was previously working but then suddenly stopped. I have it in conjunction with a LCD display which is working fine. I have looked up many tutorials and none of them make a difference.
My code:
#include <LiquidCrystal.h>
#define trigPin 8
#define echoPin 9
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
lcd.begin(16, 2);
}
void loop() {
lcd.setCursor(0, 1);
lcd.print(millis()/1000);
int duration, distance;
digitalWrite(trigPin, HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
lcd.print(distance);
Serial.print(distance);
delay(500);
}
I have the serial.print so I could see if it was the LCD, nothing displays their either.
Any suggestions. Thank you.