This is my first instructable and my first arduino project so bear with me.
I got my first arduino and a bunch of sensors and parts a few days ago and I was fooling around with everything to start learning, I had succesfully gotten the HC-SR04 sonic sensor to work after struggling to find a library (You can find it here) and I was able to write to the console the values but I wanted to get them out of the computer and display them with a screen or something. So I decided to display them with a 4-digit 7-segment display. I searched for an instructable or something else to do it but couldn't find anything, the best I got was in this forum, but, at least for me, it wasn't working. so I rewrote the code and got it working.
This is my first contribution to instructables and to the arduino community, I hope someone finds it useful.
Step 1: Materials
This is the list of parts I used:
- Arduino Uno R3
- HSN-3642BS (4-Digits 7-segments Display)
- HC-SR04 (Ultrasonic Module)
- USB AB cable
- 2 breadboards
- 16 m-m dupont connectors
Step 2: Wiring It Up
Depending on the display you've got the wiring might be different. Attached in this segment is the pin diagram for the display I'm using.
I used the arduino digital pins from 2 to 8 for the segments and from 9 to 12 for the digits, I didn't use the dot so I left that pin unused.
for the Sonic Module I used the 5V for VCC, GND for GND, the pin A0 for echo and pin 13 for trig
W I R I N G G U I D E
=== Sonar ===
=== Common Cathode digits ===
Arduino Display Digit
9 12 1 Leftmost
10 9 2
11 8 3
12 6 4 Rightmost
=== Anode Segments ===
Arduino Display Segment
2 11 A
3 7 B
4 4 C
5 2 D
6 1 E
7 10 F
8 5 G
** I'm not exactly an expert with electronics so I'm not sure if I should have used resistors, browsing some forums I read that you probably should, but I didn't and nothing has burned or exploded so far.
Step 3: Code
You can find the git for the code here.
The code was written to take data from the sonic module and print it to the display as numbers, but it can be easily customized to write data from any other input (as long as the data is 4 digits or less).
If you use the sonic module you will need to download the library for it because it does not comes preinstalled with the arduino IDE, you can find it here.
With some inspiration and logic from: https://create.arduino.cc/projecthub/SAnwandter1/... and https://create.arduino.cc/projecthub/SAnwandter1/...
Step 4: The End
If you wired everything correctly now you just have to load the arduino with the code and, hopefully, it will display the distance measurement in cm.
I hope I was able to help you!