Introduction: Arduino Nano: Ultrasonic Ranger(Ping) Distance I2C 2 X 16 LCD Display With Visuino

In this Instructable, I will show you how easy it is to connect Ultrasonic Sensor to Arduino and display the distance on a LCD Display.

Step 1: Components

  1. One Arduino compatible board (I use Arduino Nano, because I have one, but any other will be just fine)
  2. One Ultrasonic Ranger Sensor Module - I used HC-SR04, but US-015, or very much any other will also work
  3. One I2C 16x2 LCD Display (Back side of the LCD with the I2C adapter showed on Picture 2)
  4. One small Breadboard (Any breadboard can be used, or any other way to connect 3 wires together)
  5. 3 Female-Male (Red) jumper wires
  6. 6 Female-Female jumper wires

Step 2: Connect the LCD Module to the Arduino

  1. Connect Female-FemaleGround(Black wire), SDA(Green wire), and SCL(Yellow wire) to the LCD Module (Picture 1)
  2. Connect the Female end of a Female-MalePower(Red wire) to the VCC/Power pin of the LCD Module (Picture 1) , and leave the Male end unconnected
  3. Connect the other end of the Ground wire(Black wire) to Ground pin of the Arduino board(Picture 2)
  4. Connect the other end of the SDA wire(Green wire) to SDA/Analog pin 4 of the Arduino Nano board(Picture 2)
  5. Connect the other end of the SCL wire(Yellow wire) to SCL/Analog pin 5 of the Arduino Nano board(Picture 2)
  6. Connect another Female-Male Power wire(Red wire) to the 5V Power pin of the Arduino board(Picture 2), and leave the Male end unconnected
  7. Picture 3 shows where are the Ground, 5V Power, SDA/Analog pin 4, and SCL/Analog pin 5 pins of the Arduino Nano

Step 3: Connect the Ultrasonic Ranger to Arduino

  1. Connect Ground(Black wire), Power(Red wire), Trigger(Brown wire), and Echo(Purple wire) to the Ultrasonic Ranger Sensor Module (Picture 1)
  2. Connect the Male ends of the 3 Power wires(Red wires) - from the Display, the Ultrasonic Ranger Module, and the Arduino together as example with the help of a Breadboard (Picture 2) - In my case I used a small Breadboard
  3. Connect the other end of the Ground wire(Black wire) to Ground pin of the Arduino board(Picture 3)
  4. Connect the other end of the Trigger wire(Brown wire) to Digital pin 2 of the Arduino board(Picture 3)
  5. Connect the other end of the Echo wire(Purple wire) to Digital pin 3 of the Arduino board(Picture 3)
  6. Picture 4 shows in Red where are the Ground, Digital 2, and Digital 3 pins of the Arduino Nano(In Blue are shown the connections made in the previous step)

Step 4: Start Visuino, and Select the Arduino Board Type

To start programming the Arduino, you will need to have the Arduino IDE installed from here: http://www.arduino.cc/ .

Please be aware that there are some critical bugs in Arduino IDE 1.6.6.

Make sure that you install 1.6.7 or higher, otherwise this Instructable will not work!

The Visuino: https://www.visuino.com also needs to be installed.

  1. Start Visuino as shown in the first picture
  2. Click on the "Tools" button on the Arduino component (Picture 1) in Visuino
  3. When the dialog appears, select Arduino Nano as shown in Picture 2

Step 5: In Visuino: Add and Connect Ultrasonic Ranger Component

  1. Type "sonic" in the Filter box of the Component Toolbox then select the "Ultrasonic Ranger(Ping)" component (Picture 1), and drop it in the design area
  2. In the Object Inspector set the value of the "PauseTime" property of the UltrasonicRanger1 to 1000 (Picture 2) This will give 1 second period between the measurements, so the LCD display will not be updated too often
  3. Connect the "Ping(Trigger)" pin of the UltrasonicRanger1 component to the "Digital" input pin of the Digital[ 2 ] channel of the Arduino component (Picture 3)
  4. Connect the "Out" pin of the Digital[ 3 ] channel of the Arduino component to the "Echo" input pin of the UltrasonicRanger1 component (Picture 4)

Step 6: In Visuino: Add LCD Component, and Text Field in It

  1. Type "lcd" in the Filter box of the Component Toolbox then select the "Liquid Crystal Display (LCD) - I2C" component (Picture 1), and drop it in the design area
  2. Click on the "Tools" button (Picture 2) to open the "Elements" editor (Picture 3)

We will add a Text field with the description of the value:

  1. Add Text field for the Distance description text by select the "Text Field" in the right window of the "Elements" editor, and clicking on the "+" button on the left (Picture 3)
  2. In the Object Inspector set the "Initial Value" property of the element to "Distance:" (Picture 4) - This will specify the text to be displayed

Step 7: In Visuino: Add, and Setup Analog Value Element to Display the Distance

  1. Add Analog field for the Distance value by selecting the "Analog Field" in the right window of the "Elements" editor, and clicking on the "+" button on the left (Picture 1)
  2. In the Object Inspector set the "Precision" property of the element to "2" (Picture 2)
  3. In the Object Inspector set the "Row" property of the element to "1" (Picture 2) - This will specify that the field will be shown in the second row of the Display
  4. In the Object Inspector set the "Width" property of the element to "6" (Picture 2)

Step 8: In Visuino: Add, and Setup Text Element to Display the Units

  1. Add Text field for the Units text selecting the "Text Field" in the right window of the "Elements" editor, and clicking on the "+" button (Picture 1)
  2. In the Object Inspector set the "Column" property of the element to "7" (Picture 2)
  3. In the Object Inspector set the "Initial Value" property of the element to "CM" (Picture 3)
  4. In the Object Inspector set the "Row" property of the element to "1" (Picture 3)
  5. Close the Elements editor

Step 9: In Visuino: Connect the LCD Component

  1. Connect the "Out" pin of the UltrasonicRanger1 component (Picture 1) to the "In" pin of the "Elements.AnalogField1" element of the LiquidCrystalDisplay1 component (Picture 2)
  2. Connect the "Out" pin of the LiquidCrystalDisplay1 component to the to the "In" pin of the I2C channel of the Arduino component (Picture 3)

Step 10: Generate, Compile, and Upload the Arduino Code

  1. In Visuino, Press F9 or click on the button shown on Picture 1 to generate the Arduino code, and open the Arduino IDE
  2. In the Arduino IDE, click on the Upload button, to compile and upload the code (Picture 2)

Step 11: And Play...

Congratulations! You have completed the project.

Picture 1 shows the connected and powered up project. As you can see on the picture the Display will show the Distance to the nearest object from the Ultrasonic Ranger.

On Picture 2 you can see the complete Visuino diagram.
Also attached is the Visuino project, that I created for this Instructable. You can download and open it in Visuino: https://www.visuino.com

Comments

author
halilcinar51 made it!(author)2016-09-17

#include <Visuino_LiquidCrystal_I2C.h>

bro there's a problem about this library. used other i2c libraries but still not working

author
SnorkY2K made it!(author)2016-10-23

I would check your install. I just had to reinstall my Arduino IDE and Windows 10 added a little confusion.

author
halilcinar51 made it!(author)2016-10-24

my dearest friend, could you send the library

author
BoianM made it!(author)2016-10-24

It should be part of the install, but I have also uploaded it here:

www.mitov.com/Visuino_LiquidCrystal.zip

author
Fabricio+JoseB made it!(author)2017-07-05

amigo el link quebro, podrias pasarme uno alterno en el q lo hayas subido porfavor? te lo agradeceria mucho

author
BoianM made it!(author)2016-09-18

What is the problem? I use it all the time. At the moment I am in Cologne for a conference, but will be back in the office later in the week, and will be able to help you more if you have problems.

author
SnorkY2K made it!(author)2016-10-23

I purchase the program and the one year subscription. I am not putting the hardware together as a hobby and I feel that this software did save me time at accomplishing what I want to do and that the price was an outright bargain. I needed a quick and inexpensive sonic measurement device and this software helped me do that quickly. Now, time to add a PIR, atm pressure, humidity, CO2, smoke, and temp. Thanks for working on this. I am sure that it will help with the rest.

SAM_1226.JPG
author
BoianM made it!(author)2016-10-24

Congratulations! Looks good :-)

Thank you for purchasing, and for the kind words :-) . I think it will do the rest well. The smoke/gas type sensors are usually analog sensors, and you can easily read them in Visuino, but even better, I am expecting a set of sensors to arrive soon, and will see o even add components doing the computations for them so you will get the values properly calculated, and not need to do your own calculation on Visuino :-) Hope they will arrive soon.

author
RushiD1 made it!(author)2016-06-11

Hey Guy i have done the same project with the help of the above guidance. But by Compiling the program an error is coming about the wire.h file missing in the library, so plz anyone help me out for this it's urgent for as its one of my project.

so plz reply me fast as possible

author
BoianM made it!(author)2016-06-12

This means that you probably have a bad Arduino IDE installation. The wire.h is part of the standard Arduino IDE Installation. What version of Visuino you use and what version of Arduino IDE ?

author
MoniCris made it!(author)2016-02-28

Nice. But Visuino is not freeware.

author
BoianM made it!(author)2016-02-28

Thank you!
The Atmel processors and the Ultrasonic sensors are not free either :-( . The Atmel is also proprietary.
It is up to you to decide if something is worth paying or not ;-) .
And Visuino can be used for 5 minutes every time you run it for free which is more than enough for very much all the projects I posted and more ;-) .
So I am actually giving some small part of my hard work for free, while actually this is my only income, so it is up to you to decide if my work has any value. Unfortunately unless I make some money, I can't buy even food, and as I said, this is a full time job. I work on Visuino and the rest of my products ~100H a week, with only bathroom and sleep brakes. If it was free, it would be of the quality and the functionality of the Arduino IDE. You decide if you want something of the level of the Arduino IDE for free, or something of the level of Visuino for $9.99 ;-)

author
MoniCris made it!(author)2016-02-29

Sorry! Your work and your time have a very big value. Reading your instructable, means that I appreciate it. I was just amazed because most of the instructable are DIY and preferably low cost. I will give a look at this software; seems not bad.

P.S.: sensors can be free when you reuse old electronic. ;)

Again, please accept my apologies.

author
BoianM made it!(author)2016-02-29

Thank you MonyCris, No problem, I hope that the $9.99 is not that high of a cost. I actually wanted to price it lower, but at that level the payment processors take most of the money :-( . I did a survey last year, and the lowest suggested price was $20, I decided to half it to make it as affordable as I can :-) . I am sorry for probably overreacting. I am trying my best to make it affordable for everyone ;-)

Enjoy :-)

author
amjadpksbp made it!(author)2016-02-19

I am interested in digital vernier cliper to send signal to pc. This project can be converted to send signal to pc.

author
BoianM made it!(author)2016-02-19

Yes, it can easily be changed. Here is one such Instructable:

https://www.instructables.com/id/Arduino-Nano-Ultra...

I have more Instructables posted with more information on connection to PC ;-)

author
sbud made it!(author)2016-02-16

Hi. Nice project. How about the tolerance?

author
BoianM made it!(author)2016-02-16

Thank you!

What tolerance you have in mind? Different sensors have different tolerances, but if you have something other than the sensor measurement tolerance in mind, please let me know.