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!

93 comments

Previous Page 1 of 10 Next
  1. 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 :)

  2. Gravatar

    Ming

    26 July 2018

    Very Good Tutorial!

  3. Gravatar

    help

    03 July 2018

    i instead of using arduino pins 7-12, i used 2-7. what do i need to change to display the letters? thanks/

  4. Gravatar

    sarah miller

    21 June 2018

    great explanation of the project. I have made a model of railway controlling system project in my college life, got help from <a href="https://microsoftsupport.co/microsoft-365-support/">microsoft 365 support</a> as I stuck with the Arduino setting. you can follow the site if required.

  5. Gravatar

    Frank M

    25 April 2018

    Did not specify resistor value ? But it works anyway ! I put in a 1K resistor. Great tutorial.

  6. Gravatar

    Basil

    05 April 2018

    Thanks a lot for the explanation, Great work!

  7. Gravatar

    Rautraye R.

    21 March 2018

    Nice explanation Thank you Sir

  8. Gravatar

    hello help pls

    19 March 2018

    it wont show the text
    how do i fix it ?

  9. Gravatar

    Brandon

    04 March 2018

    Hey, thanks alot for the guide!

  10. Gravatar

    davis

    25 February 2018

    nice!
    my second arduino project!

Previous Page 1 of 10 Next