Hey Guys,
First time poster, and new to Arduino generally speaking.
So for a fun project I decided to make a distance measurer using HC-SR04 with my UNO.
So using a Serial Monitor I have been able to get my code to work, so decided to try an better this by incorporating an LCD...
To my dismay I have not been able to get the code to function for it to display my results i.e. distance in CM onto the LCD...
Could anyone with knowledge on this please help me... Code below.
#include <NewPing.h>
#include <LiquidCrystal.h>
#define PIN_ECHO 4
#define PIN_TRIG 5
#define MAX_DIST 500
NewPing sensor(PIN_TRIG, PIN_ECHO, MAX_DIST);
LiquidCrystal lcd(8,9,2,3,6,7);
int BackLitPin = 10;
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);
pinMode(BackLitPin,OUTPUT); //(Old) Back light Pin
digitalWrite(BackLitPin,HIGH); //(Old) Turn Back light on
}
void loop()
{
delay(50);
int time_taken=sensor.ping();
Serial.println(time_taken/US_ROUNDTRIP_CM);
lcd.setCursor(1,0); // Set where it starts to write
lcd.print(time_taken/US_ROUNDTRIP_CM);
lcd.print(" cm "); // add cm after the distance
}