การวัดระยะทางด้วย Ultrasonic Sensor Module (HC-SR04) แสดงผลผ่านหน้าจอ LCD 16×2 ด้วย Arduino
ตัวอย่าง VDO Test Sourcecode ด้วย Website https://www.tinkercad.com
Sourcecode C++
#include <LiquidCrystal.h> const int pingPin=7; long cal, cm; LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup(){ lcd.begin(16, 2); lcd.clear(); lcd.print("Ready!"); delay(1000); } void loop(){ pinMode(pingPin, OUTPUT); digitalWrite(pingPin, LOW); delayMicroseconds(2); digitalWrite(pingPin, HIGH); delayMicroseconds(5); digitalWrite(pingPin, LOW); pinMode(pingPin, INPUT); cal = pulseIn(pingPin, HIGH); cm = cal / 58; delay(300); lcd.clear(); lcd.print("Distance: "); lcd.print(cm); lcd.print(" cm."); }
Model by :: https://www.tinkercad.com