loading

When I first started playing with Arduinos, this was the first little set up I created. The video orientation is a little poor. This was my first go at things so I apologize that I was not up to snuff back then. Anyway, very simple set up. What we are doing is using an ultrasonic distance sensor to determine the distance of an object in front of the sensor. The sensor works by sending out a sound wave through one of its nodes, and measuring the reflected sound wave with its other node. Using the time it takes for the sound wave to bounce off the nearest object and return to the senor, we can calculate the distance of the object in front of the sensor.

Secondly, we are also wiring up an LCD display to the Arduino. Using a few commands, we can print messages onto the display. In this case, we are printing the distance of the closest object as determined by the ultrasonic distance sensor and we are printing a warning message in the event an object gets too close. The LCD monitor has a module at the back of it that allows it to communicate with the Arduino via I2C. This also makes the wiring for the display much easier.

The attached video summarizes what our little setup does. Hope you enjoy!

Step 1: Gather Up Your Tools

For this Instructable, you will need

1 x Arduino
1 x LCD Screen
1 x Ultrasonic Distance Sensor
1 x Breadboard
4 x Male-to-male jumper wires
4 x Female-to-male jumper wires

I purchased the LCD screen here
I purchased the ultrasonic distance sensor here

Step 2: Wire Up the LCD Display to the Arduino

The LCD display that I am using has a module at the back that allows it to communicate with the Arduino via I2C. This makes the wiring much easier. The pins located on the left of the "-" are located on the LCD display module. The pins located on the right of the "-" are located on the Arduino. The pin out is as follows:

GND - GND
VCC - 5 V
SDA - A4
SCL - A5

Step 3: Downloading the LCD Library

The LCD library is an upgrade to the library that comes with the Arduino download. It was written by F Malpartida and can be downloaded here with some descriptions here. The zip folder that I have linked to contains a library for Mac users and Windows users. Only extract the one that works with your machine. Instructions for using this library can be found by following a few instructions listed here and here.

Step 4: Find the I2C Address for Your LCD Display

This LCD monitor communicates via I2C. So, we need to find the I2C address associated with the device. It will be different for each device. The documentation for the device is not very good, but luckily, other people have solved this problem for us. Upload the "i2c_scanner" sketch to the Arduino and open up the serial monitor. The address should be printed in the monitor.

Step 5: Type Your Address Into the Appropriate Place in the Code

Type the address into the following line of the LCD_display_and_distance_sensor.ino code

#define I2C_ADDR ***type address here and remove stars**** // Define I2C Address where the PCF8574A is

Step 6: Wire Up the Ultrasonic Distance Sensor

The ultrasonic distance sensor has 4 pins: VCC, Trig, Echo, GND. Connect Vcc to 5 V on the Arduino, Trig to digital pin 12, Echo to digital pin 8, and GND to GND.

Step 7: Upload the LCD_display_and_distance_sensor.ino Code

Upload the code and watch it work!

The code is written so that if an object comes 15 cm or closer to the distance sensor, the LCD display will print "STEP AWAY!!!" and blink the built in LED on the Arduino on pin 13. If an object is further than 15 cm, the LCD display will print the distance the closest object is from the distance sensor and it will also print "Safe Zone :)."

If you have any trouble with anything, please feel free to ask. If you enjoyed the tutorial, please consider voting for it in the Teach It! Contest. Alright everyone, until next time.

You can find all the codes in the project's GitHub repository or just click the links on each step.

<p>Hello...if anyone can help, that would be amazing. I have a problem with &lt;.../wire.wire.h&gt;. The thing is is that i do not have that written down on the code yet an error keeps on showing up.</p><p>THIS IS AS FOLLOWS: </p><p>fatal error: ../Wire/Wire.h: No such file or directory</p><div><p>arduino-builder/arduino-builder -compile -core-api-version 10611 -build-path /tmp/223813405 -hardware arduino-builder/hardware -hardware arduino-builder/packages/cores -tools arduino-builder/tools -tools arduino-builder/packages/tools -built-in-libraries arduino-builder/latest -libraries /tmp/724635763/pinned -libraries /tmp/724635763/custom -fqbn arduino:avr:uno -build-cache /tmp -verbose=false /tmp/724635763/5_FINAL</p><p>/tmp/724635763/custom/LiquidCrystal/I2CIO.cpp:35:26: fatal error: ../Wire/Wire.h: No such file or directory</p><p>#include &lt;../Wire/Wire.h&gt;</p><p>============================================================</p><p>What should I do. please provide me with any help and instructions. This is what i am using for my technology project and it is worth a FINAL GRADE WHICH IS DUE THIS COMMING WEDNESDAY. PLEASE HELP !!!!!!!</p></div>
<p>I'm stuck, I have uploaded the 12c address but my display has come up with nill. Anything that i have missed? </p>
<p>I made this project and it worked, but I had to change the LCD address to 0x27, identical to the one pictured here. The code is the same as the Sketch presented here but the only difference is the I2C address. If your LCD looks blank but lit, then you have the address incorrect. Nice work here!!! Thanks</p>
<p>Glad it worked out for you!</p>
<p>Cool! Thanks for sharing this.</p>
<p>You're welcome and thank you!</p>
<p>I still dont understand where the #define I2C_ADDR ***type address here and remove stars**** // Define I2C is, as well is it possible that my arduino already had liquid crystal installed because it says it does? Thank you so far for the post has been really helpful</p>
<p>Wait I see it but there is a 0x3F in the middle of it</p>
<p>0x3F is the I2C address. For the code to work, you have to specify the address of your specific LCD monitor.</p><p>You can find the address by running the I2Cscanner.ino code</p>
Thank you for the response haha was surprised you answered as this is nearly two years old! I did get it to work my adress was 0x27 and for some reason i left the f at the end as 0x27F and that was what caused the error. Thank you for the extremely useful tutorial!
<p>Yeah dude for sure. I do try to respond (thought it can be fairly delayed as you can see ;) ). Though, I need to get better at responder more quickly -_-</p><p>Glad it helped. Good luck with everything.</p>
<p>I just purchased a I2C LCD with a expander chip (Says PCF8574T on the expander board chip). No I2C address was given from the seller so I was stuck trying the standard address of 0x20 which didn't work. I just ran your i2c_scanner.ino sketch and then opened the serial monitor to see what happens. After finding the correct baud rate of 115200 it displayed that it found my device and the address was 0x27 . I plugged that new address into my &quot;Hello World&quot; sketch and it worked! AWESOME sketch - I'am keeping that sketch handy! Thank you Ohoilett!</p>
<p>Glad you got it working. I can't take credit for that code though. I found it on the internet. Lol. I had the same problem you did when I first put this thing together. It is a handy sketch for sure.</p>

About This Instructable

46,372views

52favorites

Bio: Graduate student at Purdue University, biomedical engineer, electronics enthusiast, educator, trying to learn a little about engineering and programming
More by ohoilett:Super Simple Electrocardiogram (ECG) Circuit PulseSim - Photoplethysmograph (Heartbeat) Analog Simulator Team Valor Light Up Badge for Pokemon GO 
Add instructable to: