//Car-parking IOT app
int echopin = 2; //getting the input of the Ultrasonic sensor.
int trigpin = 3; //starts sending signal from sensor.
int Time;
int Distance;
void setup()
{ // put your setup code here, to run once:
pinMode(trigpin, OUTPUT);
pinMode(echopin, INPUT);
}
void loop()
{// put your main code here, to run repeatedly:
digitalWrite(trigpin, LOW); //stop the functioning of the ultrasonic sensor
digitalWrite(trigpin, HIGH);//starts sending signal
digitalWrite(trigpin, LOW);//stop receiving signal from the arduino.
//pulseIn() used to get time taken by the sound wave to reflect back after hitting the object.
Time = pulseIn(echopin,HIGH);
Distance = Time * 0.0172; //0.0172 is constant(speed of wave-ultrasonic sensor)
if (Distance>30){
digitalWrite(11, HIGH);//Pin 11 producing the output of the green LED.
digitalWrite(13, LOW); //red LED
}
else{
digitalWrite(11, LOW); //green LED
digitalWrite(13, HIGH);//Pin 13 producing the output of the red LED.
}
}
//OUTPUT- Click on sensor and change distance to get output