Arduino Sonic Meter / Dynamic Display

5,716

32

9

Introduction: 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 de…

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:

  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:

W I R I N G G U I D E

=== Sonar ===

Arduino Sonar

5V vcc

GND GND

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.

Acknowledgements:

Ping code from: http://playground.arduino.cc/Code/NewPing and http://playground.arduino.cc/Code/NewPing

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!

Microcontroller Contest 2017

Participated in the
Microcontroller Contest 2017

Be the First to Share

    Recommendations

    • Big and Small Contest

      Big and Small Contest
    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge
    • Make It Bridge

      Make It Bridge

    9 Comments

    0
    PC-GUY
    PC-GUY

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

    0
    rafununu
    rafununu

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

    0
    robertbu
    robertbu

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

    0
    edgary777
    edgary777

    Reply 6 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.

    0
    robertbu
    robertbu

    Reply 6 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.

    0
    DanM5
    DanM5

    6 years ago

    Nice work.

    0
    edgary777
    edgary777

    Reply 6 years ago

    Thank you!

    0
    Swansong
    Swansong

    6 years ago

    Looks good :)

    0
    edgary777
    edgary777

    Reply 6 years ago

    Thanks!