Perancangan Alat Ukur Kecepatan Benda Bergerak menggunakan Sensor Infra Red Berbasis Arduino Uno

LAMPIRAN
// include the library code:
#include

const int sen1 = A0;
const int sen2 = A1;
const int tombol = 8;

int dt1;
int dt2;
boolean Sensor1;
boolean Sensor2;
int proses=0;
long dlyTime;
long timeStart;
long timeEnd;
float waktuTempuh;
float tempSpeed=0;
//float hasilSpeed;

// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

Universitas Sumatera Utara

void cekSensor(){
dt1 = analogRead(A0);
dt2 = analogRead(A1);
if (dt1 < 400) Sensor1 = false; else Sensor1 = true;
if (dt2 < 400) Sensor2 = false; else Sensor2 = true;

//lcd.clear();
//lcd.print(Sensor1);
//lcd.print(" ");
//lcd.print(Sensor2);

}

void setup() {

Serial.begin(9600);

pinMode(tombol,INPUT_PULLUP);

// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("SPEED DETECTOR");
Serial.println("START");

Universitas Sumatera Utara

delay(1000);
}

void loop() {
//float hasilSpeed;
cekSensor();
switch(proses){
case 0:
proses = 5;
lcd.clear();

lcd.print("READY..");
break;

case 5:
proses = 10;
Serial.println("Tunggu Sensor 1");
break;

case 10:
if (Sensor1) {
Serial.println("Tunggu Sensor 2");
lcd.clear();
lcd.print("tunggu..");
timeStart = millis();

Universitas Sumatera Utara