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!

102 comments

Previous Page 1 of 11 Next
  1. Gravatar

    Joop

    26 October 2019

    Excellent!!! 26-10-2019

  2. Gravatar

    Gene R Bussart

    31 August 2019

    I have been trying off and on for a year to make the 1602 work with uno. Could not do it until today I went to your site and had it working in less than an hour. Thank you

  3. Gravatar

    Sion

    24 March 2019

    Very helpful. Saved some hours of research and experimentation. Thank you.

  4. Gravatar

    Holm

    07 March 2019

    Many thanks due to detailed description. Very nice that small project like this works as promise by first try!

  5. Gravatar

    Wesley

    31 January 2019

    This was my first time using an LCD. I had no idea that the doodad I got in my kit was a light sensor. Such a cool experience. Thank you!

  6. Gravatar

    Michael Bean

    14 December 2018

    Excellent!!! Worked on my first attempt

  7. Gravatar

    haleyma

    14 December 2018

    Awesome tutorial. Puzzled me that the lightSensor reading was higher in the dark, but now I get it. Really sweet walk-through. Thanks!

  8. Gravatar

    Vasilis

    03 December 2018

    you made my day . worked on the first try!!

  9. Gravatar

    Moses Lakra

    04 November 2018

    A good tutorial. I was trying other codes but could not get success. The tutorial is simple for all to understad and get started.*****

  10. Gravatar

    Kevin

    04 September 2018

    Works like an absolute charm ! Just mention the resistor value for the light sensor again when you deal with it,(it is mentioned in the beginning,but I missed it first time around,excellent tutorial :)

Previous Page 1 of 11 Next