LAMPIRAN
(LISTING PROGRAM)
Lampiran Listing Program Alat Pendeteksi Jarak Aman Pada Kendaran #include <NewPing.h>
#define TRIGGER_PIN A5 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN A4 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); #include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7, 6);
void setup() {
// put your setup code here, to run once: lcd.begin(16, 2);
pinMode(13,OUTPUT);//buzzer pinMode(5,OUTPUT);// led Serial.begin(9600);
delay(500); lcd.clear();
lcd.setCursor(0,0);
lcd.print("WILLIAM F S "); lcd.setCursor(0,1);
lcd.print("141121011"); delay(1500);
lcd.clear(); }
void loop() {
// put your main code here, to run repeatedly:
int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS). int jarak=(uS / US_ROUNDTRIP_CM);
//Serial.print(uS / US_ROUNDTRIP_CM); // Convert ping time to distance in cm and print result (0 = outside set distance range)
// int tinggi=(32-jarak);
{digitalWrite(13,HIGH); delay(500);
digitalWrite(13,LOW); delay(500);
} else
{lcd.setCursor(0,1); lcd.print("aman"); }
delay(200); lcd.clear(); }