#define trigPin 13
#define echoPin 12
#define kLed 5
#define sLed 4
#define yLed 3
long sure;
long uzaklik;
void setup() {
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
pinMode(kLed,OUTPUT);
pinMode(sLed,OUTPUT);
pinMode(yLed,OUTPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
sure = pulseIn(echoPin, HIGH);
Serial.print("olculen sure");Serial.println(sure);
uzaklik= sure *0.034/2;
Serial.print("Uzaklik");
Serial.print(uzaklik);
Serial.println("CM olarak olculmustur.");
if(uzaklik<20)
{
digitalWrite(kLed,HIGH); digitalWrite(sLed,LOW); digitalWrite(yLed,LOW);
}
else if(uzaklik<40)
{
digitalWrite(kLed,LOW); digitalWrite(sLed,HIGH); digitalWrite(yLed,LOW);
}
else if(uzaklik<80)
{
digitalWrite(kLed,LOW); digitalWrite(sLed,LOW); digitalWrite(kLed,HIGH);
}
else
{
digitalWrite(kLed,LOW); digitalWrite(sLed, LOW); digitalWrite(yLed,LOW);
}
}