Connect and use a Character LCD with only 2 pins using the I2C bus
Using a character LCD with an Arduino is nothing new, but let’s make it very simple by using the I2C bus.
By using this little I2C LCD board, we can control the LCD using only 2 wires, and not worry about resistors to adjust the contrast since it’s all included.
To make this tutorial more interesting, we will use the HC-SR04 ultrasonic range finder that we used before and display the results on the LCD.
We are using a 20×4 Character LCD so we have 4 lines of 20 characters each available.
The I2C LCD module is connected to pin A4-SDA and A5-SCL.
The HC-SR04 is connected to pin 11-echo and 12-trigger.
VCC and Ground from the Arduino are connected to the breadboard rails .
We then connect the VCC and Ground to both the I2C module and the HC-SR04.
Before we can use the I2C module, we need to find out it’s HEX address so we can communicate with it.
We find the I2C module address by running this “I2C Scanner” sketch on our Arduino :
*note: Watch the tutorial video to see the code in action and the results.
As you can see in the tutorial video, the address for our I2C module is 0X27, so we will use that value in our Sketch to communicate with it.
We will use the “NewPing” library to communicate with the HC-SR04 ultrasonic range sensor.
We are also using the “NewLiquidCrystal” library in our Sketch, this library unlike the one included with the Arduino IDE is more recent, faster and can use the I2C bus, so might as well use it.
You can download the libraries at the bottom of this tutorial page.
*Rename the original LiquidCrystal folder in the Arduino/Libraries to something like LiquidCrystal_Old before extracting the NewLiquidCrystal library, since the folders have the same name, and the original library will conflict with this new one.
As always, please watch the tutorial video for more information.
Copy and paste the above code(s) in the Arduino IDE to program your Arduino.
Download the NewLiquidCrystal library here: https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
Download the HC-SR04 library here: https://bitbucket.org/teckel12/arduino-new-ping/downloads
Once downloaded, just extract the content of the zip files inside your “arduino/libraries” folder.