Arduino Range Finder

This week we used an ultrasonic sensor and an LCD display with our Arduino uno.

The HC-SR04 ultrasonic sensor uses SONAR to determine the distance of an object just like the bats do. It offers excellent non-contact range detection with high accuracy and stable readings in an easy-to-use package from 2 cm to 400 cm or 1” to 13 feet. (https://www.tutorialspoint.com/arduino/arduino_ultrasonic_sensor.htm )

Connect the Ultrasonic Module

Use the supplied cable to connect:-

Ultrasonic module to Arduino

  1. Black Gnd   to    Gnd
  2. Yellow +5V  to    Vcc
  3. Blue Trigger  to    D8
  4. Red Echo  to   D7

I didn’t have enough supplied cable that’s why I had to rewrite the connection codes…

.      

Get the range finder to measure some distances

 

Download an example sketch.

  1. Create a directory in My Documents/Arduino/ named:-Ultrasonic_HCSR04_2020
  2. Download the LCD example sketch from Student Central /XE404/Study Materials/Week 12 – Range fider & Display/ Ultrasonic_HCSR04_2020.ino And place it in: My Documents/Arduino/Ultrasonic_HCSR04_2020 Warning! The browser will probably corrupt the file name again. You will have to remove the (2) from the name.
  3. Open the Arduino IDE and select the correct COM port
  4. Upload the sketch to your Arduino.
  5. Open the serial monitor (right corner)
  6. You should now be able to see the range data on the monitor screen.

Modify the display sketch to display the range data

  • Edit the display sketch software from last time such that it supports the ultrasonic transducer and displays the range.

.      

 

 

Print Friendly, PDF & Email