Utilize an HC-SR04 ultrasonic sensor with an Arduino to measure the distance of any object.

The basic idea behind an ultrasonic sensor:

An ultrasonic sensor triggers a signal that travels in a straight path, and then if the triggered signal encounters an object, it will be reflected and the echo pin will detect it.

Parts Needed:

1. Arduino Uno microcontroller.

2. Arduino software IDE (I used the 1.6.8 version)

Note: Arduino IDE can be downloaded for free from Arduino software.

3. HC-SR04 ultrasonic sensor.

4. Breadboard.

5. Wires as needed.

Step 1: Schematics

The HC-SR04 has 4 pins: Vcc, trig, echo, GND.

Vcc: input voltage, connect it to +5V.

trig: trigger pin, connect it to any digital pin.

echo: echo pin, connect it to any digital pin.

GND: ground, connect it to GND on the Arduino.

Note: the attached figure shows the schematics for this project.

Step 2: Code

The attached figure shows the code needed. Also, the attached file contains the code used.

After writing the code, you have to:

1. Verify it.

2. Upload it to the board.

3. Open the serial monitor. (Cltr + Shift + M)

Step 3: Results

The embedded YouTube video shows the functionality of the ultrasonic sensor, where it was used to measure the distance of an object.

<p>I keep getting a zero distance reading.</p><p>Any ideas?</p>
<p>You might need to check the GPIO pins you are using.</p><p>The provided code in this instructable uses pins number 11 &amp; 12. </p><p>Hope this helps.</p>
<p>nice and easy ;-) just testing new sensor thx</p>
<p>FYI...Your video is sideways!</p>

About This Instructable




Bio: Inventing the future by turning ideas into reality
More by TalalKhalil:Python Programming Series #1 Arduino: HC-SR04 Ultrasonic Sensor  Arduino: Simple Sequential LED's  
Add instructable to: