4002A LCD display with Arduino

FunduinoPublished on

Zwei Zeilen mit je 40 Zeichen am Arduino

Das 4002A ist doppelt so breit wie das klassische 16×2-LCD und zeigt 40 Zeichen pro Zeile. Dafür braucht es deutlich mehr Leitungen als ein I²C-Display.

In dieser Anleitung verkabelst du das Display mit Kontrastregler und Hintergrundbeleuchtung und lässt mit der Bibliothek LiquidCrystal Text erscheinen.

The 4002A LCD displays two lines of text across its full width

You need this

10 kOhm rotary potentiometer - carbon film, 6 mm shaft, up to 30 V 10 kOhm rotary potentiometer - carbon film, 6 mm shaft, up to 30 V 0,90 € *Item no. F23106608About the product — 10 kOhm rotary potentiometer - carbon film, 6 mm shaft, up to 30 V
Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino 11,12 € *Item no. F23107480About the product — Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino
Breadboard Cables Male-to-Male - 40 Pieces, 20 cm Breadboard Cables Male-to-Male - 40 Pieces, 20 cm 1,74 € *Item no. FUN-1010558About the product — Breadboard Cables Male-to-Male - 40 Pieces, 20 cm
Breadboard cables male-female - 40 pieces, 20 cm Breadboard cables male-female - 40 pieces, 20 cm 1,74 € *Item no. FUN-1010554About the product — Breadboard cables male-female - 40 pieces, 20 cm

All 4 parts together 15,50 € *

* All prices include statutory VAT, plus shipping costs.

The LCD 4002A

The 4002A is a particularly wide LCD with two lines of 40 characters each. It is well suited for displaying sensor readings or microcontroller status messages.

In this guide, you’ll display a specified text on the screen.

The 4002A LCD displays two lines of text across its full width

The wiring

The rotary control on the separate breadboard adjusts the contrast. The LED backlight is powered with 3.3 V, as shown in the diagram. The display in the example actually needs 4.2 V - if you want exactly this value, use a series resistor to get it from the 5 V supply.

The wiring is challenging because it requires a lot of connections and the display has no sockets. It’s best to solder on an angled socket strip or solder the wires directly to the display; a ribbon cable makes things clearer. It’s difficult to get good results without soldering.

The contact numbers shown in the image correspond to those in the datasheet and circuit diagram. Count the cable positions on the display to avoid mistakes - for example: the first cable from the right goes to GND, the second from the right to 5V, and so on.

You can find the pin assignments in the schematic.

Circuit diagram: LCD 4002A with Arduino and potentiometer for contrast
The numbering of the pins on the LCD 4002A
1 / 2

The program

For the 4002A, you need the LiquidCrystal library, which is already included in the Arduino IDE.

In the sketch, you specify which pins the display is connected to and indicate in lcd.begin() how many characters and lines it has - here, 40 and 2. Then you set the starting position with setCursor() and write the text with print().

Two lines of text on the 4002A
```cpp
#include <LiquidCrystal.h> //Load the LCD library
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //This line specifies which pins on the microcontroller board are used for the LCD (it's best not to change this initially).
void setup()
{
lcd.begin(40, 2); //In setup, specify how many characters and lines are used. Here: 16 characters in 2 lines.
}
void loop()
{
lcd.setCursor(0, 0); //Set the starting position for the display on the LCD. lcd.setCursor(0,0) means: first character on the first line.
lcd.print("www.funduino.de"); //The text "www.funduino.de" should appear here. The microcontroller board knows the lcd.setCursor command because the library was included.
lcd.setCursor(0, 1); //lcd.setCursor(0,1) means: first character on the second line.
lcd.print("Good luck"); //The text "Good luck!!!" should appear here.
}
```

Alternating top and bottom

In this variation, “Top” appears at the top and “bottom” at the bottom in alternation. Every two seconds, lcd.clear() clears the display before the next text appears.

setCursor(5, 1) positions the text at the sixth character because counting starts at 0.

Alternating top and bottom
#include <LiquidCrystal.h> // LiquidCrystal
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
lcd.begin(40, 2);
}
void loop()
{
lcd.setCursor(0, 0);
lcd.print("Top"); //Start at the first character in the first line with the text "Top".
delay (2000); //Wait two seconds.
lcd.clear(); //Clear the display.
lcd.setCursor(5, 1);
lcd.print("bottom"); //Start again at the fifth character in the second line with the text "Bottom".
delay (2000); //Wait two seconds.
lcd.clear(); //Clear the display.
}
Rate the instructions

Comments

Ask a question or share an experience

Contact us if something doesn’t work. Please include your board and the error message.

We review every comment before publication. Your email address remains with us.