#include <NewPing.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
#define TRIGGER_PIN 12
#define ECHO_PIN 11
#define MAX_DISTANCE 400
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
void setup()
{
lcd.init();
lcd.backlight();
Serial.begin(9600);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("odleglosc: ");
lcd.setCursor(14, 0);
lcd.print("cm");
}
void loop()
{
delay(50);
unsigned int uS = sonar.ping();
Serial.print("Ping: ");
Serial.print(uS / US_ROUNDTRIP_CM);
Serial.println("cm ");
lcd.setCursor(10, 0);
lcd.print(uS / US_ROUNDTRIP_CM);
lcd.print(" ");
}
To mój kod ale jest pod arduino może da ci to pomysł :D