loading

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!

<p>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.</p>
<p>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. </p>
<p>For a permanent device I suggest adding buttons that allow calibration:</p><p>2 buttons to adjust speed of sound<br>1 button to reset reading to zero</p>
<p><a href="https://www.instructables.com/member/edgary777/" rel="nofollow">edgary777</a> 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.</p><p>I too am fairly new to electronics, but I've spent some time learning about and building multiplex displays. Each segment of your <strong>red</strong> 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 &quot;only&quot; 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. </p><p>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 &quot;frames&quot;. 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.</p><p>Thanks for the instructable.</p>
<p>Thank you very much for the information!</p><p>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.</p><p>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!</p><p>I will try and find out more about the display and update the instructable with indications about it.</p>
<p>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.</p>
<p>Nice work.</p>
<p>Thank you!</p>
<p>Looks good :)</p>
<p>Thanks!</p>

About This Instructable

1,662views

26favorites

License:

Bio: 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 ... More »
More by edgary777:Arduino Sonic Meter / Dynamic Display 
Add instructable to: