Aplikasi ini digunakan untuk mengukur 4 jarak sekaligus menggunakan 4 sensor ultrasonik dan Arduino UNO sebagai pengolah data dari sensor tersebut. Senosor yang digunakan yaitu HC-SR04 dan hasilnya ditampilkan pada LCD.
Kebutuhan Hardware
- 4 Modul Sensor Ultrasonik HC-SR04
- Modul LCD 2x16
- Modul Arduino UNO
- Power supply +5Volt
Sensor HC-SR04 | Source
Diagram Blok
Schematics
Koneksi Arduino UNO dengan LCD
Koneksi Sensor Ultrasonic
Source Code/Sketch
#define TRIG1 8
#define ECHO1 9
#define TRIG2 10
#define ECHO2 11
#define TRIG3 12
#define ECHO3 13
#define TRIG4 A0
#define ECHO4 A1
#include <LiquidCrystal.h>
LiquidCrystal lcd(2,3,4,5,6,7);
unsigned int j1, j2, j3, j4, timer;
void setup(){
lcd.begin(16, 2);
lcd.print(" 4 ULTRASONIC");
lcd.setCursor(0, 1);
lcd.print(" RANGE METER");
delay(2000);
pinMode(ECHO1, INPUT);
pinMode(TRIG1, OUTPUT);
pinMode(ECHO2, INPUT);
pinMode(TRIG2, OUTPUT);
pinMode(ECHO3, INPUT);
pinMode(TRIG3, OUTPUT);
pinMode(ECHO4, INPUT);
pinMode(TRIG4, OUTPUT);
}
void loop(){
//-------------sensor 1
digitalWrite(TRIG1, LOW);
delayMicroseconds(2);
digitalWrite(TRIG1, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG1, LOW);
timer = pulseIn(ECHO1, HIGH);
j1= timer/58;
//-------------sensor 2
digitalWrite(TRIG2, LOW);
delayMicroseconds(2);
digitalWrite(TRIG2, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG2, LOW);
timer = pulseIn(ECHO2, HIGH);
j2= timer/58;
//-------------sensor 3
digitalWrite(TRIG3, LOW);
delayMicroseconds(2);
digitalWrite(TRIG3, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG3, LOW);
timer = pulseIn(ECHO3, HIGH);
j3= timer/58;
//-------------sensor 4
digitalWrite(TRIG4, LOW);
delayMicroseconds(2);
digitalWrite(TRIG4, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG4, LOW);
timer = pulseIn(ECHO4, HIGH);
j4= timer/58;
lcd.setCursor(0,0);
lcd.print("J1= J2=");
lcd.setCursor(0, 1);
lcd.print("J3= J4=");
lcd.setCursor(3, 0);
lcd.print(j1);
lcd.print("cm ");
lcd.setCursor(12, 0);
lcd.print(j2);
lcd.print("cm ");
lcd.setCursor(3, 1);
lcd.print(j3);
lcd.print("cm ");
lcd.setCursor(12, 1);
lcd.print(j4);
lcd.print("cm ");
delay(100);
}
#define ECHO1 9
#define TRIG2 10
#define ECHO2 11
#define TRIG3 12
#define ECHO3 13
#define TRIG4 A0
#define ECHO4 A1
#include <LiquidCrystal.h>
LiquidCrystal lcd(2,3,4,5,6,7);
unsigned int j1, j2, j3, j4, timer;
void setup(){
lcd.begin(16, 2);
lcd.print(" 4 ULTRASONIC");
lcd.setCursor(0, 1);
lcd.print(" RANGE METER");
delay(2000);
pinMode(ECHO1, INPUT);
pinMode(TRIG1, OUTPUT);
pinMode(ECHO2, INPUT);
pinMode(TRIG2, OUTPUT);
pinMode(ECHO3, INPUT);
pinMode(TRIG3, OUTPUT);
pinMode(ECHO4, INPUT);
pinMode(TRIG4, OUTPUT);
}
void loop(){
//-------------sensor 1
digitalWrite(TRIG1, LOW);
delayMicroseconds(2);
digitalWrite(TRIG1, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG1, LOW);
timer = pulseIn(ECHO1, HIGH);
j1= timer/58;
//-------------sensor 2
digitalWrite(TRIG2, LOW);
delayMicroseconds(2);
digitalWrite(TRIG2, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG2, LOW);
timer = pulseIn(ECHO2, HIGH);
j2= timer/58;
//-------------sensor 3
digitalWrite(TRIG3, LOW);
delayMicroseconds(2);
digitalWrite(TRIG3, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG3, LOW);
timer = pulseIn(ECHO3, HIGH);
j3= timer/58;
//-------------sensor 4
digitalWrite(TRIG4, LOW);
delayMicroseconds(2);
digitalWrite(TRIG4, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG4, LOW);
timer = pulseIn(ECHO4, HIGH);
j4= timer/58;
lcd.setCursor(0,0);
lcd.print("J1= J2=");
lcd.setCursor(0, 1);
lcd.print("J3= J4=");
lcd.setCursor(3, 0);
lcd.print(j1);
lcd.print("cm ");
lcd.setCursor(12, 0);
lcd.print(j2);
lcd.print("cm ");
lcd.setCursor(3, 1);
lcd.print(j3);
lcd.print("cm ");
lcd.setCursor(12, 1);
lcd.print(j4);
lcd.print("cm ");
delay(100);
}
Jalannya Alat
1. Tampilan pertama pada LCD
2. Setelah 2 detik menapilkan pengukuran ultrasonik
3. Berikutnya Anda bisa beri penghalang didepan Ke-4 sensor tersebut.
Video Project II - 10. Mengukur 4 Jarak dengan Sensor Ultrasonic berbasis Arduino Uno
KAMI MELAYANI JASA PEMBUATAN HARDWARE ATAU SOFTWARE BERBASIS ARDUINO
KONTAK KAMI 085743320570 (adi sanjaya)
No comments:
Post a Comment