int ECHO_PIN = 2;
int TRIG_PIN = 3;
int led1 = 6;
int led2 = 5;
int led3 = 4;
void setup(){
Serial.begin(9600);
pinMode(ECHO_PIN,INPUT);
pinMode(TRIG_PIN, OUTPUT);
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
}
float ultrasonik(){
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(10);
digitalWrite(TRIG_PIN,HIGH);
int duration = pulseIn(ECHO_PIN, HIGH);
return duration * 0.034 / 2;
}
void loop(){
float val = ultrasonik ();
if (val > 200) {
digitalWrite(led1, HIGH);
digitalWrite(led2,HIGH);
digitalWrite(led3,LOW);
Serial.println("Hi");
Serial.println("Bye");
delay(1000);
}
}