// Jorge Javier 2021 reworked from various codes. #include int trigPin=3; int echoPin=2; float pingTime; //time for ping to travel from sensor to target and return float distance; //Distance to Target in cms float speedOfSound=776.5; //Speed of sound in miles per hour when temp is 77 degrees. const int rs = 12, en = 11, d4 = 4, d5 = 5, d6 = 6, d7 = 7; LiquidCrystal lcd(rs, en, d4, d5, d6, d7); void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); lcd.begin(16, 2); } void loop() { // put your main code here, to run repeatedly: digitalWrite(trigPin, LOW); //Set trigger pin low delayMicroseconds(1000); //Let signal settle digitalWrite(trigPin, HIGH); //Set trigPin high delayMicroseconds(15); //Delay in high state digitalWrite(trigPin, LOW); //ping has now been sent delayMicroseconds(10); //Delay in low state pingTime = pulseIn(echoPin, HIGH); pingTime=pingTime/1000000; pingTime=pingTime/3600; distance= speedOfSound * pingTime; //This will be in miles, since speed of sound was miles per hour distance= distance*63360; //Convert miles to inches by multipling by 63360 (inches per mile) Serial.print("Welcome: "); Serial.print(distance); Serial.println(" steps"); delay(100); //delay tenth of a second to slow things down a little. lcd.clear(); lcd.setCursor(0, 0); lcd.print("Welcome: "); lcd.setCursor(0, 1); lcd.print(distance); lcd.print(" steps"); delay(100); //delay tenth of a second to slow things down a little. } void printOut() { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Welcome: "); lcd.setCursor(0, 1); lcd.print(" steps"); }