An Ultrasonic Sensor is a device that measures dis
An Ultrasonic Sensor is a device that measures dis
Arduino Uno
HC-SR04 Module
BreadBorad
Jumper wires
You'll need a laptop or a PC to upload code to the Arduino and view
the Distance on the Serial Monitor.
Operating Voltage: 5V DC
Operating Current: 15mA
Measure Angle: 15°
Ranging Distance: 2cm - 4m
Step 3: The Arduino Serial Monitor
This is very useful when debugging the code, or if you need to give
inputs to the board, This is probably the most useful tool in the IDE.
The more you use it, the better you get at testing complex projects
that takes inputs and provides consequent outputs.
/*
*/
// defining variables
long duration;
int distance;
void setup() {
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
distance= duration*0.034/2;
Serial.print("Distance: ");
Serial.println(distance);