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!

20 comments

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

    Born

    13 September 2014

    Well done !
    I think it is useful to most of these who read the article !
    Thanks for your excellent work !

  2. Johan van Tongeren Gravatar

    Urs Gysler

    10 September 2014

    Hi
    This is the first tutorial covering LCD and Potmeter THAT WORKS.
    Great job. absolutly percect explained. Greetings from Switzerland

  3. Johan van Tongeren Gravatar

    Gregor

    02 May 2014

    nice it worked :)
    high value no light, low value to much light.
    good explained tutorials.
    greetings from Denmark

  4. Johan van Tongeren Gravatar

    Tashrif Billah

    11 April 2014

    Very helpful

  5. Johan van Tongeren Gravatar

    Mathijs

    27 January 2014

    Pls add also the schematic diagram to a project.

  6. Johan van Tongeren Gravatar

    kamran

    26 January 2014

    are you sure 5V+ to back light? i freakng love my sweet little lcd and i dont want to damage it :( its so awesome!

  7. Johan van Tongeren Gravatar

    Liviu Rachita

    14 January 2014

    tks, Liviu, Romania

  8. Johan van Tongeren Gravatar

    Sam Delaney

    02 January 2014

    Thanks for your article, for some reason the Arduino example didn't work for me but yours did.

  9. Johan van Tongeren Gravatar

    roberto

    22 October 2013

    very good ! easy under your instruction, casually finded, please have a site with more esamples?
    tks
    ciao
    roberto
    roma

  10. Johan van Tongeren Gravatar

    76N

    26 August 2013

    Could you help me for lcd library? Thanks before.

Previous Page 1 of 2 Next