Picture of Arduino ultrasonic range finder, with I²C lcd display!


in this project i want to show and explain you a range sensor with ultrasonic and a 20x04 lcd screen. I wrote the code for this project myself and added lots of comments, so that everybody can understand it and use it for other projects (maybe a light range sensor?!). It is easy to build and much more easier to program, it just requires a few cheap parts and can run on battery, for a portable rangefinder.

The maximum rated range is 500 cm, the range is measured 20 times per seccond. It is Displayed on a lcd screen which is 20x4 chars big, it has a custom start message, and it can have a custom design while measuring. It will have a backlight LED and can run on every arduino, which has I²C communication. That mean you can run it on an Arduino nano, which is very small. It also requires 5V so it has to be a 5V version of an Arduino.

Step 1: What do you need & Tools

Picture of What do you need & Tools
We dont need much things, the parts should be less then 15$ (without arduino, with arduino may 25-35$):


Arduino (5-55$) , http://tinyurl.com/pk2wdt3
Ultrasonic sensor (2$),  HC-SR04  , http://tinyurl.com/d3ss7tl
A 20x4 Display (6$) , http://tinyurl.com/pbk35ry
A IIC/I2C/TWI/SP​​I Serial Interface Board Module (2$) , http://tinyurl.com/nl2tr2k
Some wires
a Breadboard
A USB cable


Arduino , www.Arduino.cc

wire.h library (should be with the Arduino software)
LiquidCrystal_I2C.h library  for the Display
NewPing.h library for the sensor


what are tools? D:

(no tools needed, yay)


a Case...
minoo.ekrani9 months ago

plz send me ur code

ecozcelik11 months ago

sketch_sep02a.ino:23:53: error: 'POSITIVE' was not declared in this scope,

it gives me this eror how can I fix

Jan_Henrik (author)  ecozcelik11 months ago


my sketch is kind of outdated, I will update it as soon as I can :)

Hariharan. GTH12 months ago

i'm using I2C/TWI 1602 and a 16X2 display , did i wrongly connect the twi interface to the display?

Jan_Henrik (author)  Hariharan. GTH12 months ago

oh, did you change the code for a 16x2 display? I used a 16x4

Hariharan. GTH12 months ago

what is mean by switching sda and scl , is my interface connection is correct.please check it , deadline to submit my project is fast approaching.please reply

Jan_Henrik (author)  Hariharan. GTH12 months ago

thats interresting, has your display the right controller for the i²c interface?

Hariharan. GTH12 months ago

Display showing bars instead of characters .. what's de solution?

Jan_Henrik (author)  Hariharan. GTH12 months ago

switch sda and scl

i 'm getting an error POSITIVE not declared under this scope.Tell me the correct LCD library

Jan_Henrik (author)  Hariharan. GTH1 year ago

Hi, this library is for an I²C Display, but you´re right, it is outdated. I will fix it in the afternoon, Thank you for telling me :)

problem solved i used liquid crystal 1.2.1 downloaded from this site https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads done compling . thanks for ur code.

Jan_Henrik (author)  Hariharan. GTH1 year ago

Awesome! Thanks! :)

Fenex1 year ago

Hey :)

Really cool instructable. I already ordered the parts to build it. Just one question: what's the accuracy of the measurement?

Jan_Henrik (author)  Fenex1 year ago

Hi, the accuracy at 20°C is 3,4% :)