Display

 


  1. /*

  2. Video on Youtube:

  3. https://www.youtube.com/watch?v=tbbZzWrJYdk

  4. Sensor on Banggood:
  5. https://usa.banggood.com/custlink/D3vhOQRuh7


  6. Project on My Website:
  7. https://aeroarduino.com/uncategorized/cool-arduino-ultrasonic-transducer-distance-measurement-with-tinkercad/


  8. */
  9. #include <LiquidCrystal.h> // includes the LiquidCrystal Library
  10. LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LCD object. Parameters: (rs, enable, d4, d5, d6, d7)
  11. const int trigPin = 9;
  12. const int echoPin = 10;
  13. long duration;
  14. int distanceCm, distanceInch;
  15. void setup() {
  16. lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display
  17. pinMode(trigPin, OUTPUT);
  18. pinMode(echoPin, INPUT);
  19. }
  20. void loop() {
  21. digitalWrite(trigPin, LOW);
  22. delayMicroseconds(2);
  23. digitalWrite(trigPin, HIGH);
  24. delayMicroseconds(10);
  25. digitalWrite(trigPin, LOW);
  26. duration = pulseIn(echoPin, HIGH);
  27. distanceCm= duration*0.034/2;
  28. distanceInch = duration*0.0133/2;
  29. lcd.setCursor(0,0); // Sets the location at which subsequent text written to the LCD will be displayed
  30. lcd.print("Distance: "); // Prints string "Distance" on the LCD
  31. lcd.print(distanceCm); // Prints the distance value from the sensor
  32. lcd.print(" cm");
  33. delay(10);
  34. lcd.setCursor(0,1);
  35. lcd.print("Distance: ");
  36. lcd.print(distanceInch);
  37. lcd.print(" inch");
  38. delay(10);
  39. }


No hay comentarios:

Publicar un comentario

Circuitos y programación