Arduino IDE Code
Arduino IDE Code
void setup()
{
Serial.begin(9600); //tells the arduino to get ready to exchange messages with
the serial monitor at a data rate of 9600 bits/sec.
pinMode(trig, OUTPUT); //configures the specified pin to behave as output/input.
pinMode(echo, INPUT);
}
void loop()
{
calculate_distance(trig, echo);
distance=dist; //getting distance of ultrasonic sensor
Serial.println(distance);
delay(1000);
}