Arduino Sonic Meter / Dynamic Display




About: Industrial Product Designer by the Tecnologico de Monterrey. I specialize in 3D modeling and CNC design and manufacture. I'm also a silver jeweler, vegetarian, animal rights advocate, entrepreneur, software ...

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.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Materials

This is the list of parts I used:

  1. Arduino Uno R3
  2. HSN-3642BS (4-Digits 7-segments Display)
  3. HC-SR04 (Ultrasonic Module)
  4. USB AB cable
  5. 2 breadboards
  6. 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

Wiring Guide:


=== Sonar ===

Arduino Sonar

5V vcc


13 Trig

A0 Echo

=== 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.


Ping code from: and

With some inspiration and logic from: and

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!

Microcontroller Contest 2017

Participated in the
Microcontroller Contest 2017

Be the First to Share


    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    10 Discussions


    2 years ago

    Great, good job. Now can you tie in a sonic alert that changes pitch withh distance and get it to work as a car back-up alarm? That, as a fender of mine will tell you I need.


    2 years ago

    You do need resistors to save your leds and a lot of energy as well. That's right that due to multiplexing leds aren't fully supplied, there's a calculation to make involving leds forward current, voltage and the time they are on. Anyway, without resistors you should notice differences in the brightnesses, a lot of energy is wasted in heat.


    2 years ago

    For a permanent device I suggest adding buttons that allow calibration:

    2 buttons to adjust speed of sound
    1 button to reset reading to zero


    2 years ago

    edgary777 wrote: 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.

    I too am fairly new to electronics, but I've spent some time learning about and building multiplex displays. Each segment of your red seven segment display will draw it rated current at around 2.0V. You are driving them with 5.0V. What is saving you is that each segment is only on for 1/4 of the time. If you were to continuously display a single segment at 5.0V, it would burn out. You are probably safe since you are pulling "only" a little over twice the current through each lit segment 1/4 of the time, but you would need the datasheet to be sure. Some leds have a lot of leeway...5x to 10x. Others not so much.

    From my reading, one way to reduce the impact would be to increase the frequency. The simplest way for this project would be to drop your delay in your code from 4ms to 1ms. Another way would be to introduce blank "frames". That is, you have four frames, where each frame is lit 1/4 of the time. You would insert between these frames times where no segments are displayed. Of course, the segments will dim a bit.

    Thanks for the instructable.

    2 replies

    Reply 2 years ago

    Thank you very much for the information!

    My display has no documentation so I was a just testing it to see what happened, but I was affraid to burn it so I never left it on for more than a few minutes.

    I did tried to change the frames to 1ms but it actually looks way brighter than it does at 4ms. The idea of the blank frames seems promising though, I will try to implement it later, it might even work as a brightness adjustment!

    I will try and find out more about the display and update the instructable with indications about it.


    Reply 2 years ago

    Your delay(4) occurs when the segments are dark. That is why the display got brighter when you change to delay(1). Try moving the delay() below where you light the segments. Add a second delay() just after you clear the segments. Start with a value of 1 for the first delay and 4 for the second and then adjust from there.