Skema Pengkabelan
Alat yang di butuhkan adalah :
Listing Programnya adalah seperti di bawah ini :
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int backLight = 13; // pin 13 will control the backlight
int signal=40;
int vol=42; // Untuk Mensuply tegangan 5 Volt
int gron=44; // Untuk Mensuply Ground
int distance;
unsigned long pulseduration=0;
void setup()
{
// bagian display
pinMode(backLight, OUTPUT);
digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with'LOW' to turn it off.
lcd.begin(16,2); // columns, rows. use 16,2 for a 16x2 LCD, etc.
// bagian ultrasonik
pinMode(signal, OUTPUT);
pinMode(vol,OUTPUT);
pinMode(gron,OUTPUT);
Serial.begin(9600);
}
void measureDistance()
{
// set pin as output so we can send a pulse
pinMode(signal, OUTPUT);
// set output to LOW
digitalWrite(signal, LOW);
digitalWrite (vol,HIGH ); // memberikan suply tegangan 5 Volt
digitalWrite (gron,LOW ) ; // memberikan suply tegangan 0 volt(ground)
delayMicroseconds(5);
// Mengirim fulsa 5uS pulse out to activate Ping)))
digitalWrite(signal, HIGH);
delayMicroseconds(5);
digitalWrite(signal, LOW);
// mengganti modus ultrasonik menjadi membaca data pantulan sinyal
pinMode(signal, INPUT);
pulseduration=pulseIn(signal, HIGH);
}
void loop()
{
// get the raw measurement data from Ping)))
measureDistance();
// divide the pulse length by half
pulseduration=pulseduration/2;
// now convert to centimetres. We're metric here people...
distance = int(pulseduration/2.9);
// Display on serial monitor
Serial.print(" Hasil Pengukuran : ");
Serial.print(distance);
Serial.println(" mm");
// Menampilkan hasil di LCD display
lcd.setCursor(0,0);
lcd.clear();
lcd.print("Hasil Pengukuran");
lcd.setCursor(1,1);
lcd.print ("Jarak :");
lcd.setCursor(9,1);
lcd.print (distance);
lcd.setCursor(14,1);
lcd.print ("mm");
delay(333);
}
*******************************************************************
**** Terima Kasih Atas Kunjungannya.... Selamat Berlatih.. Semangaaath ********
*******************************************************************
Tidak ada komentar:
Posting Komentar