Arduino Tutorial: Ultrasonic Sensor HC SR04 distance meter with a Nokia 5110 LCD display

Arduino Tutorial: Ultrasonic Sensor HC SR04 distance meter with a Nokia 5110 LCD display

Dear friends welcome to another video. Today we learn how to use this Ultrasonic sensor with Arduino and build this simple distance meter with a Nokia LCD display. Let’s start! In this project we use an Arduino Uno, a Nokia 5110 LCD display and the HC SR04 ultrasonic sensor. As you can see in the display, we see the distance that the sensor measure. If I place my hand close to the sensor, the display shows the distance of my hand from the sensor. If I remove it, it shows the distance from the opposite wall. This ultrasonic sensor is a quite interesting device. There ultrasonic module detects the distance of the closest object in front of the sensor. The maximun distance in which it detects an object is 4 meters. It works by sending out a burst of ultrasound and listening for the echo when it bounces off of an object. The module sends a short pulse through pin Trig to trigger the detection. Then, listens for a pulse in the pin Echo. The duration of the second pulse is equal to the time taken by the ultrasound to travel to the object and back to the sensor. Using the speed of sound this time can be converted to distance. Now let’s see how to build this project, it is very simple! The sensor has only 4 pins to connect. Vcc Trigger, Echo and Ground. Let’s connect first Vcc and Ground. Vcc goes to Arduino 5V. Ground goes to Arduino Ground, Trigger goes to digital pin 7 and Echo goes to digital pin 6. Now let’s connect the Nokia 5110 LCD display. I have now connected the Nokia 5110 LCD display. Please check our previous tutorial on how to connect a Nokia 5110 LCD display in your Arduino project. Now if I power on Arduino, let’s see if it is working, OK it is working fine! As you can see it measures distance and it updates the distance if I move my hand close to it. OK perfect! Now let’s go to the computer and see the software side of the project. I have prepared two
programs for you The first one is really simple. It does not use a Nokia 5110 LCD display in case you don’t have one. It does not need any libraries at all. All it does is to display the distance it measures from the sensor to the serial monitor. Let’s see. OK, that’s the distance in centimeters. It is updated every 50 milliseconds. the second program uses the Nokia 5110 LCD display, so we need a library for the display. Check out the Nokia 5110 LCD display tutorials I have prepared in order to see how to
use to display and how to load graphics on it. The code is very simple. We draw the UI bitmap and then we
measure the distance from the sensor. We convert the value we get to a string and then we display that value. As always you can find the code of the project in the description of the video. That’s todays video. An interesting and very easy build project. The distance sensor will be useful to our future projects as well like the autonomous robot. So stay tuned! Thanks for watching the video please press the like button if you like the project and subscribe to our channel in order to watch our future videos.
thank you very much and see you next week!

38 thoughts on “Arduino Tutorial: Ultrasonic Sensor HC SR04 distance meter with a Nokia 5110 LCD display

  1. Great tutorial! Hade you ever tried the NewPing library. It simply consists of creating an object which takes the trigger and Echo pin as well as the maximum distance as parameters and then it's just a matter of calling the ping function, or if you want it in centimetres, ping_cm(). Otherwise it is a great video, you always explain very well!

  2. I'm freaking out I was thinking of how you could build one of the robots from fallout and had the idea to use an ultrasound sensor then you upload a video that does exactly that !!!

  3. Good tutorial ☺, and the tutorial of the robot car? Good channel

  4. Very educational video, thank for providing the code and library link. More presenters should follow your format. I do have one question, in the Distance_Sensor_Nokia was is the ui.c file for, could you please explain?

  5. Hello friend, how can I use this project with Arduino Nano?

  6. Thankyou – great tutorial

  7. thanks you are doing a great job i have seen your all videos all the videos are clear and detail so i like so much thanks for this projects and codes because without the codes we cannot do any things

  8. can you also make it watertight and use it as a sonar unther the surface?

  9. Please mail me a schematic diagram of the connections it would really help!! And it is a great tutorial mail me at [email protected]

  10. thank you for the tutorial, can you help me how to display 3 output ultrasonic sensor in 5110 nokia LCD?

  11. Can we obtain a sonograph ,like the one used in diagnostics using this sensor??

  12. help me, i need file ui.c in inches please, my email is [email protected]

  13. Nice Tutorial, btw I have a question. Lets say, i plan to measure a depth of a Well, can the color of the water affect the measurement? or can the turbidity of the water affect the ultrasonic wave? I plan to use a JSN-B02 waterproof ultrasonic sensor and submerge the probe underwater.

  14. Hello, Can you make a data logger project for sonar ? I cant find it.

  15. Πως μπορούμε να έχουμε μεγαλύτερη μέγιστη απόσταση ;
    Υπάρχει τρόπος να χρησιμοποιήσουμε κάποιο λέιζερ για την απόσταση ;

  16. Can you modify your code to measure millimeters?

  17. I'm wondering how accurate is that sensor in measuring distance?

  18. hello, i need to know how to record the files into an sd card?
    i tried but it did not work, would you like to help? thanks;)

  19. Our need is for a remote sensor to measure the depth of an earth auger drill which is typically in the 40' to 50' range. Is ultrasonic viable at this distance. There are very few commercially available devices available for the drilling industry.

  20. Hi, I made it! But my screen is too dark, how can i fix it?

  21. Hi,correct me if i'm wrong but it seems the 5110 library won't work with actual IDE 1.6.12 or above.Got the following error message when compiling:C:UserspscAppDataLocalTempccSdueVw.ltrans0.ltrans.o: In function `main':

    C:temparduino-1.6.12portablesketchbooklibrariesLCD5110_Graph/LCD5110_Graph.cpp:828: undefined reference to `ui'

    C:temparduino-1.6.12portablesketchbooklibrariesLCD5110_Graph/LCD5110_Graph.cpp:828: undefined reference to `ui'

    collect2.exe: error: ld returned 1 exit status

    exit status 1
    Fehler beim Kompilieren für das Board Arduino Nano

  22. sir, in my ultrasonic sensor hc-sr04 there is no crystal oscillator.
    is any disadvantage of not having 4mhz crystal oscillator in the sensor

  23. Hi, what is the splash file? because i add only ui.c and its error

    ui.c:3: error: conflicting declaration 'const unsigned char ui []'

    const unsigned char ui [] PROGMEM = {


    C:UsersoemDocumentsArduinonokiawithsensornokiawithsensor.ino:9:16: note: previous declaration as 'uint8_t ui []'

    extern uint8_t ui[];

  24. Hi! Really god video my friend! Really like this and many more of this channel!
    I was kinda curious about this project. What should I change in order to use an oled display, besides the 1 inch oled display itself? Also to be able to measure over 999 distances (in CM). Maybe I should use a different sensor which can measure longer distances. Something between 0 and 15 meters

    Thanks 🙂

  25. can you hack mobile display like other key pad cellphones please

  26. 0:18 did you say supersonic! ?

  27. Hii..i have an Arduino Uno instead of Arduino Mega and wired up things as you did but my display shows nothinga(not even garbage) just blue screen..pls help me sir asap…and my backlight is also working differently than yours i.e turns off when grounded and turns on when connected to to the display i am using is given below..

  28. Very nice Video. (1) Instead of showing the distance in cm or otherwise, how can we rather display a .bmp image of a water tank (1000Ltr) and depending on the distance measured by HC SR04, show the Fill level graphically e.g. 10%, 20%, 30% and so one with Buzzer on for 30 Seconds when level is below 20% and buzzer on for 10 Second when 100%. Full Tank

    (2) Also can you help make a video in which the output of this can be seen on the Android Phone via a reliable but cheap trans-receiver so that we do not have to walk up to the device but monitor the level on the Android phone itself. Many thanks in advance. Cheers !!

  29. Good day sir, can i have the schematic of this project? Thank you and advance sir, have a great day ?

  30. Thank you Nick!

  31. Hello sir. ThAnk u for sharing ur knowledge with us again
    I did the project successfully but am facing one problem some time the sensor fluctuate I don’t know why is that happening I would appreciate ur answer


  33. Hi sir ….
    great fan of your work …love your tutorials.

    I have made a project of data collection in which i used ds3231 and one FRAM to store data and time when power goes off.
    I used arduino mega. Every thing working .
    Now i come to know that STM32 Blue pill is way better as it has a battery backup mode .
    Can you please tell me how to switch between battery back mode and regular mode and does SRAM remains the same when power go off and it run on battery back up ………….
    Ravi Prakash

  34. Sir can I use an i2c oled display?

  35. what is the maximum distance?

  36. Send me file.ino for this connection ??? [email protected] Thank you

  37. Sir we can do this by nodmcu esp8266 with this same program?

  38. Hi. This is a very good tutorial. it would be good to have the code for others screen like 1602, oled 0.96, … Or both cm and inch. Or if we can have the code to mesure precisely like 239.7cm. So we can easely learn diference between the code. Just an idea. Anyway the tutorial is great easy to understand.Thnx!

Leave a Reply

Your email address will not be published. Required fields are marked *