Connecting a 1602A LCD display and a light sensor to Arduino UNO

21 October 2012

This tutorial shows how to connect the 1602A LCD display and a light sensor to your Arduino (UNO) and display the light intensity on the screen. I am using only parts from the Arduino starter kit I got from Deal Extreme.



This is one of the first things I try with the Arduino, but since I could not find one tutorial that covered the combination of using the LCD screen ánd the light sensor, I decided to write one beginner tutorial. Also there are many different versions of the 1602 LCD display with different pinouts and I couldn't really find which the DX version exactly was.

Materials used


1 x Arduino UNO
1 x Breadboard (63 columns)
1 x Light sensor
1 x 50K pot meter
1 x 1602A LCD display
1 x 10K resistor
1 x Connector (16 pins)
1 x USB cable

The LCD display


The LCD display comes with no connector by default. This way you can solder wires to it, solder a connector on it, whatever you want. I choose to solder the connectors to the back so I could press the LCD display on the breadboard. To do this, snap of a row of connectors (16 pieces) and stick them (short pin up) trough the LCD display connectors.




Stick the LCD display in the breadboard, somewhere on the right in the lowest row of holes so you can connect the breadboard wires above and the display rests on the unused rows of the breadboard.

Connecting the display and breadboard


First you need to power the display and its backlight. Connect two wires from +5v and GND to the plus- and min rows of the breadboard.

Connect: Arduino 5v (pin 3) > plus column on breadboard
Connect: Arduino GND (pin 4 or 5) > min column on breadboard


Then connect the LCD power and the backlight power to the plus- and min rows.

Connect: GND row (min) on breadboard > pin 1 on LCD (VSS)
Connect: +5v row (plus) on breadboard > pin 2 on LCD (VDD)
Connect: +5v row (plus) on breadboard > pin 15 on LCD (A)
Connect: GND row (min) on breadboard > pin 16 on LCD (K)


When we power up the Arduino (by plugin in the USB cable connected to the computer) we'll see the LCD screen lighting up:


Next up is the pot meter. We use the potmeter to set the contrast of the display. In most LCD tutorials a 10K pot meter is used, but a 50K is also good. Finetuning gets a little harder because the range is bigger, but that's no problem for this tutorial. Plug the pot meter in the breadboard, somewhere left of the LCD display and connect the three pins.

Connect: first pin of the potmeter > GND of the breadboard
Connect: middle pin of the potmeter > pin 3 of the LCD display (VO)


When you power up the Arduino now, you will see the display having square characters on the first row. Of you don't see them, turn the pot meter slowly from left to right to adjust the contrast. You can finetune this setting when we've got characters on the display later. If your display looks like this, you're doing fine:


In the next few steps we'll connect the display further to the Arduino to let the arduino communicate with the LCD screen and put some characters on it.

Connect: pin 4 of the LCD display (RS) > pin 7 of the Arduino (digital out, PWM, yellow wire)
Connect: pin 5 of the LCD display (RW) > GND row of the breadboard (black wire)



Connect: pin 6 of the LCD display (E) > pin 8 of the Arduino (PWM)
Connect: pin 11 of the LCD display (D4) > pin 9 of the Arduino (PWM)
Connect: pin 12 of the LCD display (D5) > pin 10 of the Arduino (PWM)
Connect: pin 13 of the LCD display (D6) > pin 11 of the Arduino (PWM)
Connect: pin 14 of the LCD display (D7) > pin 12 of the Arduino (PWM)





The code


Now open a new sketch in the Arduino editor, copy-paste this code and upload it to the Arduino:

#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 8, 9, 10, 11 , 12);

void setup() {
  lcd.begin(16, 2);
  lcd.setCursor(0,1);
  lcd.write("LIGHT: ");
}

void loop() { }

When the code is uploaded and running, the LCD will display this text on the second line:


Yay! This is your first "hello world!" on a LCD display. Hooray!

The light sensor


Now lets connect the light sensor and display its value on the LCD screen. Connect three wires to empty columns on the breadboard. Make sure they are a few columns apart to have a little space for the sensor and the resistor.

Connect: GND row of the breadboard > free column 1
Connect: A0 (analog input) on Arduino > free column 2
Connect: +5 row of the breadboard > free column 3


Then bend the legs of the sensor and the resistor and put them in the columns you connected the wires to. Both the sensor and the resistor can be connected to both sides, so it doesn't matter if you put them in left- or rightside first.

Connect: light sensor > column 1 and column 2
Connect: resistor > column 2 and column 3


Now go back to the Arduino sketch program and replace the empty "loop" function with this new lines:

void loop() {
  int sensorValue = analogRead(A0);
  lcd.setCursor(7,1);
  lcd.print(sensorValue);
  delay(100);
}

If you upload it to the Arduino and it runs, you'll see the current measurement of the light sensor:



If you switch your desktop light on and off you'll see the value of the light sensor change.



That's it! You have created a LCD display which displays the current light value in your room!
You must have JavaScript enabled to use this form!

Leave a comment!

  1. Your mail is safe with me. It's only only used to display your Gravatar image!

30 comments

Previous Page 1 of 3 Next
  1. Johan van Tongeren Gravatar

    Gerd

    06 March 2015

    Hallo

    Kompliment - eine wirklich durch und durch gelungene Dokumentation - sowohl bei der Hardware wie auch bei der Software - hier könnten sich viele Entwickler ein Beispiel nehmen !
    5 von 5 Sternen

  2. Johan van Tongeren Gravatar

    Beatriz

    01 March 2015

    Great tutorial, connecting the LCD is made really easy for begginers like me with your explanations and pictures, thank you very much. It is great to see it working!

  3. Johan van Tongeren Gravatar

    Mark

    20 February 2015

    Really excellent tutorial, thank you - very clear, and first class illustration with the photos.
    Like a couple of other people I got stuck half way through. I can get to the part where the LED shows the illuminated rectangles on the top row, but cannot get the LED to show up any text. I've tried a number of different codes from other web based tutorials without any success either.
    Is this likely to be a faulty LED, or is it more likely I've done something wrong? I've checked and rechecked all my connections and the code, and have made no progress.
    My apologies if you've already answered this one several times!

    Thanks again for sharing your knowledge.
    Regards
    Mark Connaughton

  4. Johan van Tongeren Gravatar

    Neil

    31 January 2015

    This is such a good post ! However I am not sure being a Aurdinee Newbie if i have a problem. I cannot get the second row to doing anything. I have the LCD blocks on the POT, but nothing else. Any suggestions .

    Many thanks

  5. Johan van Tongeren Gravatar

    DanO

    25 January 2015

    Pretty well done tutorial!

  6. Johan van Tongeren Gravatar

    MervynB

    14 January 2015

    Excellent and informative tutorial. Thanks very much and keep up the good work.

  7. Johan van Tongeren Gravatar

    Matt D

    11 January 2015

    Thank you SOOOO much for this tutorial. I couldn't get my LCD to work based on the tutorial that came with it. Turns out I needed to hook up 4 more wires. Your tutorial was exactly what I needed. Thanks for saving me from pulling my hair out!

  8. Johan van Tongeren Gravatar

    Malith

    06 January 2015

    thanks !!

  9. Johan van Tongeren Gravatar

    hst

    06 November 2014

    cool shit man! thx!

  10. Johan van Tongeren Gravatar

    Luca

    03 November 2014

    Hey i'm sure this tutorial works perfectly and that's my LCD fault if it's not the same to me. I'm stuck in the white square part with the potentiometer, the print won't work. Guess it's broken cos i tried a lot of times with different algorythms but nothing changed

Previous Page 1 of 3 Next