Arduino Ultrasonik 013204
Arduino Ultrasonik 013204
Arduino Ultrasonik 013204
void setup() {
Serial.begin (9600); // Seriap port
pinMode(TRIG_PIN, OUTPUT); // Trig pin sebagai output
pinMode(ECHO_PIN, INPUT); // Echo pin sebagai input
pinMode(LED_PIN, OUTPUT); // pin led sebagai out
}
void loop() {
// generate 10-microsecond pulse to TRIG pin
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
// measure duration of pulse from ECHO pin
duration_us = pulseIn(ECHO_PIN, HIGH);
// calculate the distance
distance_cm = 0.017 * duration_us;