Sub topic 1
Character LCD or OLED: which one fits your project
Adding a display is usually the first time an Arduino project gets a user interface. You can choose from dozens of modules, but two cheap families cover most hobby projects: the character LCD built on the HD44780 controller, and the small monochrome OLED built on the SSD1306 controller. This chapter gives you a way to choose between them before you wire anything. It uses four criteria: what you need to show, how much power you can spend, how much space you have, and how many pins are free.
Prerequisites
This chapter assumes you can already do the following:
- Upload a sketch to an Arduino board with the Arduino IDE.
- Read the basic sketch structure,
setup()andloop(). - Wire a breadboard with power, ground, and signal jumper wires.
- Install a library with the Arduino Library Manager.
You do not need to know I2C yet. Later chapters cover it. This chapter only needs you to know that I2C is a two-wire bus that several devices can share.
What each display is
Character LCD (HD44780)
A character LCD is a grid of fixed cells. The common 16x2 module has 16 columns and 2 rows, which makes 32 cells. Each cell is a 5x8 pixel block that the controller fills from a built-in font. You do not control individual pixels. You send a character code, and the controller draws the glyph.
The module has a 16-pin header. In 4-bit mode you wire six signal lines (RS, E, D4, D5, D6, D7), plus power, ground, a contrast input, and the backlight pins. Because the cells are fixed, the module is simple to program: lcd.print("Hello") is almost the whole API.
Monochrome OLED (SSD1306)
An OLED (organic light-emitting diode) display makes its own light, so it has no backlight. The usual hobby module is 128x64 pixels, and a 128x32 variant is also common. Unlike the character LCD, you control every pixel. The Arduino keeps a copy of the whole screen in RAM, called the frame buffer. You draw into that buffer with the Adafruit GFX functions, then send the buffer to the screen with display().
Most SSD1306 modules sold for Arduino use I2C and have four pins: VCC, GND, SDA, and SCL. Some are 7-pin SPI modules, but this tutorial uses I2C.
Comparing the two on four criteria
| Criterion | 16x2 LCD, 4-bit parallel | 16x2 LCD with I2C backpack | 128x64 SSD1306 OLED, I2C |
|---|---|---|---|
| Signal pins used | 6 | 2 (SDA, SCL) | 2 (SDA, SCL) |
| What it can show | 32 fixed characters, up to 8 custom glyphs | Same as parallel | Any pixels: text in several sizes, lines, shapes, simple bitmaps |
| Light source | LED backlight, always on unless switched | Same, often switchable with a jumper or by software | Self-lit pixels |
| Typical supply | 5 V | 5 V | 3.3 V or 5 V, depends on the module |
| RAM cost on the Arduino | Very small | Very small | 1024 bytes for the frame buffer |
| Library | LiquidCrystal (built in) | LiquidCrystal_I2C (third party) | Adafruit_SSD1306 and Adafruit_GFX |
Treat the numbers as typical values for the common modules. Always check the datasheet or seller page for your exact part.
Content: what do you need to show?
Start here, because content decides most of the choice.
Choose a character LCD when the screen is a labeled readout. Examples are "Temp: 23.5 C", a menu with a few entries, or a status line. The fixed grid forces a tidy layout, and you cannot make it look wrong by miscalculating a pixel position.
Choose an OLED when you need any of the following:
- A graph, a bar, a gauge, or an icon.
- More than one text size on the same screen.
- Text that is not aligned to a grid, such as a large number in the middle with a small label below.
- More than 2 lines of text. A 128x64 OLED at text size 1 fits about 21 characters per line and 8 lines.
The LCD can fake simple graphics with its 8 custom character slots, and a later chapter shows how. That limit is real, though. Eight glyphs is enough for a heart, a degree sign, or the pieces of a bar graph, but not for a free-form drawing.
Power: what does it cost to run?
An LCD module with the backlight off uses very little current, roughly in the low milliamps. The backlight is the expensive part. A typical LED backlight draws on the order of 20 mA or more, and some modules draw much more. On a USB-powered Arduino this does not matter. On a battery it can dominate the whole project's consumption.
An OLED's draw depends on how many pixels are lit and at what brightness. A mostly black screen with a little white text draws less than a screen filled with white. The range for a small module is typically from a few milliamps to around 20 mA. Because black pixels use almost nothing, an OLED showing sparse content can use less power than a backlit LCD. A full-white OLED screen can use more.
For battery projects, the practical rules are:
- Prefer an OLED with a mostly dark interface.
- If you use an LCD, put the backlight on a transistor or a spare pin so the sketch can switch it off when idle.
- Measure the real current with a multimeter in series with the supply. Modules vary a lot.
Size and readability
A 16x2 LCD module is about 80 x 36 mm, and its characters are large, often around 5 mm tall. You can read them from a few meters away. A 0.96 inch OLED is about 27 x 27 mm with a 22 x 11 mm active area. Its text is small and sharp, but you need to be close. Larger text sizes help, but then you fit fewer characters. The OLED is the better fit for a small enclosure or a handheld device.
Contrast and viewing conditions also differ. An OLED has high contrast and a wide viewing angle, and it works well in a dim room. Many LCD modules look washed out from an angle and need a contrast adjustment, usually a small potentiometer on the contrast pin. Many LCD modules stay readable in bright light when the backlight is off, because they reflect ambient light. An OLED can be hard to read in direct sunlight.
Pins: how many do you have free?
On an Uno, a 4-bit parallel LCD takes 6 digital pins. That is a lot if your project also drives a motor shield or several sensors. An I2C display needs just two lines, SDA and SCL, and those lines are shared. On an Uno R3 they are pins A4 and A5, and they are also broken out on the header near AREF. Any other I2C devices, such as a sensor, can sit on the same two wires as long as their addresses differ.
Pin pressure gives you three practical options:
- Plenty of free pins and a simple readout: wire the LCD in parallel and skip the I2C complexity.
- Few free pins: use an LCD with an I2C backpack or an OLED.
- Several I2C devices already on the bus: check that the display's address does not collide with them. A later chapter covers how to find addresses.
A decision flow
The diagram turns the four criteria into a short sequence of questions. Use it as a starting point, not a rule.
The same message on both displays
The two sketches below show the difference in programming model. Both print a greeting. The LCD sketch is the one used in the later parallel-wiring chapter, and the OLED sketch is the one from the OLED chapter. You do not need to wire them now. Read them side by side.
#include <LiquidCrystal.h>
// RS, E, D4, D5, D6, D7
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
lcd.begin(16, 2);
lcd.print("Hello, world!");
}
void loop() {
lcd.setCursor(0, 1);
lcd.print(millis() / 1000);
}#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 display(128, 64, &Wire, -1);
void setup() {
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
for (;;) {} // display not found: stop here
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println(F("Hello, OLED"));
display.display();
}
void loop() {}Notice three differences:
- The LCD takes its pin list in the constructor. The OLED takes its size, the I2C bus, and a reset pin (
-1means no reset pin is wired). - The LCD writes to the screen immediately. The OLED draws into memory, and nothing appears until
display()runs. - The OLED sketch checks whether the display answered. If it did not, the program stops in an endless loop. That check is useful, but it also means a wrong address or loose wire shows up as a blank screen with no error message.
Edge cases and common mistakes
- Treating the OLED RAM cost as free. The 128x64 frame buffer takes 1024 bytes. An Uno's ATmega328P has 2048 bytes of RAM, so the buffer takes half of it before your own variables and strings. A 128x32 module halves this to 512 bytes. A later chapter works through the budget. If your sketch already uses much RAM, the LCD is the safer choice.
- Forgetting flash use. The Adafruit libraries add several kilobytes of flash on top of your own code. The Uno has about 32 KB, so this is rarely a problem for a small sketch, but check the compile report if you also use other large libraries.
- Assuming all I2C modules share one address. Many I2C LCD backpacks respond at 0x27 or 0x3F, and many SSD1306 modules respond at 0x3C or 0x3D. Some modules ship with a different address, so scan the bus instead of guessing.
- Mixing voltage levels. A 5 V Uno works with 5 V LCD modules directly. If you later move to a 3.3 V board, you need to check whether the display and its backpack are rated for 3.3 V logic. Many OLED modules carry a regulator and accept either supply, but this varies by seller, so read the module's page.
- Leaving a static image on an OLED. OLED pixels age with use. A fixed bright logo shown for months can leave a faint ghost image. If the display stays on all day, change the content now and then or turn it off when idle. An LCD does not have this problem.
- Buying by listing photo. A "1602 LCD" is a 16x2 character display. A "0.96 OLED" could be I2C or SPI, and its pin order may differ between sellers. Count the pins before you order and compare the labels with the wiring you plan.
Putting the choice into practice
Here are three worked examples that apply the criteria.
- A greenhouse thermometer, USB-powered, on a desk. It needs one value and a label. You have plenty of pins and no battery limit. A 16x2 LCD in parallel mode is the simplest option and is easy to read from across the room.
- A pocket sensor logger on a coin cell or small LiPo. It needs a small case and long battery life. A dark OLED, turned off after a few seconds of inactivity, fits. A backlit LCD would drain the battery much faster.
- A robot that already uses 10 digital pins for motors and sensors. You have 4 free digital pins plus the I2C lines. A 4-bit parallel LCD does not fit. Use an LCD with an I2C backpack for text only, or an OLED if you want to show a simple graph of sensor values.
The next chapter covers how to power and wire a display safely, which applies to both types.
Exercise
A project has a 9 V battery pack, runs for days, and needs to show one temperature value updated every minute. The Arduino has 4 free digital pins. Which display would you pick, and what do you do to cut power use?
Show answer
Pick the SSD1306 OLED over I2C (or an LCD with an I2C backpack, since a 4-bit parallel LCD needs 6 pins and only 4 are free). The OLED is a good choice because the content is sparse and mostly dark, so few pixels are lit. Also turn the display off, or clear it, between updates. If you chose an LCD, switch the backlight off with a transistor or a spare pin when nobody is looking.
Exercise
An Uno sketch already uses about 1300 bytes of RAM for variables and strings. Can it also hold a 128x64 SSD1306 frame buffer? What are your options?
Show answer
No. The buffer needs 128 x 64 / 8 = 1024 bytes, and 1300 + 1024 = 2324 bytes is more than the 2048 bytes of RAM on the Uno's ATmega328P. Options are to reduce RAM use elsewhere (for example, store text strings in flash with the F() macro), use a 128x32 display (512 bytes), or switch to a character LCD, which needs almost no extra RAM.