Monday, December 12, 2016

arduino HC-SR04 anti bounching

HC-SR04

unsigned long delay1,delay2;
if (jarak<=30){

if (millis()-delay1>=2000){
digitalWrite(relay,LOW);
}
}
else { delay1=millis();}
if (jaraK>=200){
if (millis()-delay2>=2000){
digitalWrite(relay,HIGH);
}
}
else { delay2=millis();}