1. Kondisi [Kembali]
Berdasarkan percobaan 1 (Ultrasonic ke LCD) membuat rangkaian dengan menggunakan LED dan pada jarak > 200 cm maka LED akan mati.
3. Video [Kembali]
4. Flowchart [Kembali]
5. Listing Program [Kembali]
#include <LiquidCrystal.h>
#define echoPin 11
#define trigPin 12
long ping;
float jarak;
LiquidCrystal lcd(6, 5, 10, 9, 8, 7);
const int led = 4;
void setup() { // put your setup code here, to run once:
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode (led, OUTPUT);
lcd.begin(16, 2);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
ping = pulseIn(echoPin, HIGH);
jarak = ping*0.0345/2;
if (jarak > 200){
digitalWrite (led, LOW);
} else {
digitalWrite (led, HIGH);
}
lcd.setCursor(0, 0);
lcd.print("Jarak = ");
lcd.setCursor(0, 1);
lcd.print(jarak);
}
Tidak ada komentar:
Posting Komentar