TUGAS PRAKTIKUM PERCOBAAN - 15 " Ukur Jarak dengan Ultrasonik"
Nama Kelompok :
1. Riski Ariyanto / 163600047
2. Mufti Maulana Rahman / 163600059
Tujuan : Mengukur jarak dinding dengan komponen Ultrasonik
int terima=5;//echo
int pancar=6;//trigger
void setup() {
Serial.begin(9600);
pinMode(terima,INPUT);
pinMode(pancar,OUTPUT);
}
void loop() {
digitalWrite(pancar,LOW);
delayMicroseconds(2);
digitalWrite(pancar,HIGH);
delayMicroseconds(10);
digitalWrite(pancar,LOW);
int x = pulseIn(terima,HIGH);
x=x/58;
Serial.print("Jarak=");
Serial.print(x);
Serial.println("cm");
delay(500);
}
1. Riski Ariyanto / 163600047
2. Mufti Maulana Rahman / 163600059
Tujuan : Mengukur jarak dinding dengan komponen Ultrasonik
Program :
int pancar=6;//trigger
void setup() {
Serial.begin(9600);
pinMode(terima,INPUT);
pinMode(pancar,OUTPUT);
}
void loop() {
digitalWrite(pancar,LOW);
delayMicroseconds(2);
digitalWrite(pancar,HIGH);
delayMicroseconds(10);
digitalWrite(pancar,LOW);
int x = pulseIn(terima,HIGH);
x=x/58;
Serial.print("Jarak=");
Serial.print(x);
Serial.println("cm");
delay(500);
}
Program menggunakan Library NewPing :
Untuk Library NewPing bisa cari di google atau download disini
Bisa juga Download disini
#include <NewPing.h>
#define terima 7
#define pancar 8
#define jarakmax 40// Jarak maksimal baca 40 cm selain itu akan dianggap 0
NewPing sonar(pancar, terima,jarakmax);
void setup() {
Serial.begin (9600);
}
void loop() {
unsigned int us=sonar.ping_cm();
Serial.print(us);
Serial.println(" Cm ");
delay(500);
}
Program jika menggunakan dua sensor Ultrasonik :
#include <NewPing.h>
#define terima1 7
#define pancar1 8
#define terima2 9
#define pancar2 10
#define jarakmax 40// Jarak maksimal baca 40 cm selain itu akan dianggap 0
NewPing sonar1(pancar1, terima1,jarakmax);
NewPing sonar2(pancar2, terima2,jarakmax);
void setup() {
Serial.begin (9600);
}
void loop() {
unsigned int us1=sonar1.ping_cm();
unsigned int us2=sonar2.ping_cm();
Serial.print(us1);
Serial.println(" Cm ");
delay(500);
Serial.print(us2);
Serial.println(" Cm ");
delay(500);
}
Komentar
Posting Komentar