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
- Black Gnd to Gnd
- Yellow +5V to Vcc
- Blue Trigger to D8
- 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.
- Create a directory in My Documents/Arduino/ named:-Ultrasonic_HCSR04_2020
- 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.
- Open the Arduino IDE and select the correct COM port
- Upload the sketch to your Arduino.
- Open the serial monitor (right corner)
- 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.