with Arduino Uno
Components/Equipment Required:
Following Components/Equipment are
required to perform task.
2.
UltrasonicSensor (https://piees.pk/product/ultrasonic-sensor/)
3.
Breadboard
4.
JumperWires (https://piees.pk/product-category/jumper-wires/)
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