Advertisement
ChaOSzz

LCD_UltraSens_Ino

Feb 20th, 2022
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <LiquidCrystal_I2C.h>
  2. LiquidCrystal_I2C lcd(0x27, 20, 4);
  3.  
  4. #define PIN_TRIG 12
  5. #define PIN_ECHO 11
  6.  
  7. long duration, cm;
  8.  
  9. void setup() {
  10. lcd.init();
  11. lcd.backlight();
  12.  
  13. // put your setup code here, to run once:
  14. Serial.begin(9600);
  15.  
  16. pinMode(PIN_TRIG, OUTPUT);
  17. pinMode(PIN_ECHO, INPUT);
  18. }
  19.  
  20. void loop() {
  21. lcd.setCursor(6,0);
  22. lcd.print("Djarvis");
  23. lcd.setCursor(0,1);
  24. lcd.print("distance:");
  25.  
  26. // put your main code here, to run repeatedly:
  27. digitalWrite(PIN_TRIG, LOW);
  28. delayMicroseconds(5);
  29. digitalWrite(PIN_TRIG, HIGH);
  30. delayMicroseconds(10);
  31. digitalWrite(PIN_TRIG, LOW);
  32.  
  33. duration = pulseIn(PIN_ECHO, HIGH);
  34.  
  35. cm = (duration/2) / 29.1;
  36. lcd.setCursor(9,1);
  37. lcd.print(cm);
  38. delay(400);
  39. lcd.clear();
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement