Sunday, May 3, 2020

Ultrasonic Sensor Interfacing with Arduino Uno By Engr.Habib Ur Rehman


Ultrasonic Sensor Interfacing
 with Arduino Uno
    By Engr.Habib Ur Rehman


Components/Equipment Required:
            Following Components/Equipment are required to perform task.
3.    Breadboard
Circuit Diagram:
Arduino Program:
const int trigPin = 9;
const int echoPin = 10;
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(trigPin, LOW);
delay(200);
digitalWrite(trigPin, HIGH);
delay(1000);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance= duration*0.034/2;
Serial.print("Distance");
Serial.println(distance);
}          

No comments:

Post a Comment