ultrasonic sensor value in lcd display with arduino
![](https://cdn.xingosoftware.com/elektor/images/fetch/dpr_1,w_90/https%3A%2F%2Fwww.elektormagazine.nl%2Fassets%2Fupload%2Fimages%2F42%2F20210303092533_logo-Elektor-JumpStarter-horizontal.png)
![4712](https://cdn.xingosoftware.com/elektor/images/fetch/dpr_1,w_200/https%3A%2F%2Fwww.elektormagazine.com%2Fassets%2Fupload%2Fimg%2Fpublic%2Foriginal%2Fultrasnic-sensor-in-lcd.png)
ultrasonic sensor value in LCD display with Arduino
code:
// C++ code // include the library code: #includeby mohamed hashir// initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); int ultrasonic = 0; long readUltrasonicDistance(int triggerPin, int echoPin) { pinMode(triggerPin, OUTPUT); // Clear the trigger digitalWrite(triggerPin, LOW); delayMicroseconds(2); // Sets the trigger pin to HIGH state for 10 microseconds digitalWrite(triggerPin, HIGH); delayMicroseconds(10); digitalWrite(triggerPin, LOW); pinMode(echoPin, INPUT); // Reads the echo pin, and returns the sound wave travel time in microseconds return pulseIn(echoPin, HIGH); } void setup() { lcd.begin(16, 2); } void loop() { ultrasonic = 0.01723 * readUltrasonicDistance(A0, A1); lcd.setCursor(0, 1); // print the number of seconds since reset: lcd.print(ultrasonic); delayMicroseconds(100); }
Discussion (0 comments)