SHARE
TWEET

Untitled

NB52053 Jul 31st, 2019 158 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3.  
  4.  
  5. #include <LiquidCrystal.h> //Load Liquid Crystal Library
  6. LiquidCrystal LCD(11,10,9,2,3,4,5);  //Create Liquid Crystal Object called LCD
  7.  
  8. #define trigPin 13 //Sensor Echo pin connected to Arduino pin 13
  9. #define echoPin 6 //Sensor Trip pin connected to Arduino pin 12
  10.  
  11.  
  12.  
  13. void setup()
  14. {  
  15.   pinMode(trigPin, OUTPUT);
  16.   pinMode(echoPin, INPUT);
  17.  
  18.   LCD.begin(16,2); //Tell Arduino to start your 16 column 2 row LCD
  19.   LCD.setCursor(0,0);  //Set LCD cursor to upper left corner, column 0, row 0
  20.   LCD.print("Distance:");  //Print Message on First Row
  21.   Serial.begin(9600);
  22. }
  23.  
  24. void loop() {
  25.   long duration, distance;
  26.   digitalWrite(trigPin, LOW);
  27.   delayMicroseconds(2);
  28.   digitalWrite(trigPin, HIGH);
  29.   delayMicroseconds(10);
  30.   digitalWrite(trigPin, LOW);
  31.   duration = pulseIn(echoPin, HIGH);
  32.   distance = duration*0.034/2;
  33.   Serial.print("Distance: ");
  34.   Serial.println(distance);
  35.  
  36.   LCD.setCursor(0,1);  //Set cursor to first column of second row
  37.   LCD.print(" "); //Print blanks to clear the row
  38.   LCD.setCursor(10,0);   //Set Cursor again to first column of second row
  39.   LCD.print(distance); //Print measured distance
  40.   LCD.print("cm");  //Print your units.
  41.  
  42.   delay(250); //pause to let things settle
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top