Robotics and Embedded Systems

Lesson 8: Displays: LEDs, Seven-Segment and LCDNew-age

A project that cannot show you what it is doing is hard to use and harder to debug. Displays solve that: they turn a number inside the microcontroller into something a person can read. This lesson covers the three displays you will meet most often — a single LED used as an indicator, a seven-segment display for digits, and a character LCD for text — and shows how each is wired, driven and used well.

The lesson is also about a design question: how much should a project display? A single LED can say “on” or “error”; a seven-segment display can show a temperature; an LCD can show a menu. Choosing the right display is part of designing the project, not an afterthought, and the cheapest display that does the job is usually the right one.

Key Terms.
  • Seven-segment display — a display of seven LED bars that can show the digits 0–9.
  • Common cathode — a seven-segment display whose segment cathodes share one ground pin.
  • LCD — liquid-crystal display: a flat panel that shows characters, usually 16 columns by 2 rows.
  • I2C — a two-wire communication protocol used by many displays and sensors.
  • Contrast — the difference between lit and unlit parts of an LCD, set by a potentiometer.
  • Multiplexing — driving several digits in turn so quickly that they appear lit together.
  • Indicator — a single LED that shows a state, such as power on or an error.
  • Backlight — a light behind an LCD that makes it readable in the dark.

One LED, used well

A single LED is the simplest display, and it is surprisingly expressive. Use one LED for power, one for “working”, and one for “error”, in different colours, and a user can tell the state of a project at a glance. Blink patterns add meaning: a slow blink for “waiting”, a fast blink for “error”, a steady light for “ready”. Keep the meanings consistent and write them on the project’s label — a blink code nobody can decode is worse than no blink at all.

Drive an LED from a digital pin through a 220 Ω resistor, as in Lesson 5. For brightness control, use PWM on a pin that supports it (marked with ~ on an Arduino): analogWrite(pin, 128) gives half brightness. Remember that an LED is a current device — the resistor is not optional, and an LED wired directly across 5 V will burn out in seconds.

Seven-segment displays

A seven-segment display is seven LED bars arranged as a figure of eight, plus a decimal point. By lighting different bars you can show any digit: 0 lights all but the middle bar, 1 lights two bars on the right, 8 lights them all. Each segment needs its own current-limiting resistor — one resistor per segment, not one for the whole display, or the brightness will change with the digit.

A display has either a common cathode (all segment cathodes joined to ground; you drive a segment HIGH to light it) or a common anode (all anodes joined to 5 V; you drive a segment LOW). Check the datasheet before wiring, because the two types are wired oppositely and a mistake will light the wrong segments. For several digits, displays are multiplexed: each digit is lit in turn for a few milliseconds, fast enough that the eye sees them all lit at once.

Character LCDs

A 16×2 character LCD shows two rows of sixteen characters — enough for a temperature and a status, a menu, or a short message. It is wired either directly, using six or seven pins, or through an I2C backpack, which needs only two wires (SDA and SCL) plus power. The I2C version is worth the small extra cost: it frees pins for sensors and motors, and the wiring is far simpler.

Choosing and using a display

Choose the display by the job. An indicator LED is enough for “on” and “error”. A seven-segment display suits a single number — a temperature, a count, a score — that must be readable from a distance. An LCD suits text, menus and several values at once. A project that shows a temperature on an LCD is wasting money and pins; a project that shows a menu on seven-segment displays is fighting its own hardware.

Worked example — a temperature display

A temperature sensor on A0 gives a reading that converts to degrees: temp = (reading × 5.0 / 1023 − 0.5) × 100 for a common TMP36 sensor. Show it on a 16×2 LCD with the I2C library, updating only when the temperature changes by at least 0.5 °C.

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
float last = -100;
void loop() {
  float t = (analogRead(A0) * 5.0 / 1023 - 0.5) * 100;
  if (abs(t - last) >= 0.5) {
    last = t;
    lcd.setCursor(0, 0);
    lcd.print("Temp: "); lcd.print(t, 1); lcd.print(" C");
  }
  delay(500);
}

Common mistakes

  • Wiring an LED without a resistor. It will light brightly, briefly, and then burn out.
  • Using one resistor for a whole seven-segment display, so the brightness changes with the digit.
  • Setting the LCD contrast wrong and concluding the display is broken when it is only invisible.
  • Rewriting an LCD every loop, causing flicker. Update only when the value changes.

Discussion questions

  1. A project has three LEDs: green for ready, amber for working, red for error. What could go wrong with this scheme for a colour-blind user? How would you fix it?
  2. Multiplexing lights each digit in turn, yet we see them all at once. What does that tell you about human vision — and about what a display really is?
  3. When is a display a distraction rather than a help? Think of a project where showing less would be better.

Practice questions

  1. Why does each segment of a seven-segment display need its own resistor? Answer: Because the current through each lit segment must be limited separately. One shared resistor would split the current between the lit segments, so brightness would change with the digit. Explanation: One resistor per segment.
  2. Your LCD shows nothing, but the backlight is on. What is the first thing to check? Answer: The contrast potentiometer. Turn it slowly until the characters appear — a wrong contrast makes a working display look blank. Explanation: Contrast first.
  3. What is multiplexing, and why is it used for multi-digit displays? Answer: Lighting each digit in turn for a few milliseconds, fast enough that the eye sees them all lit. It saves pins and resistors. Explanation: Fast switching looks steady.
  4. A TMP36 sensor reads 154 on a 5 V Arduino. What temperature is that? Answer: About 25.0 °C: 154 × 5 ÷ 1023 ≈ 0.75 V, minus 0.5 V is 0.25 V, × 100 = 25 °C. Explanation: Convert, don’t guess.
  5. Why should you update a display only when the value changes? Answer: Rewriting every loop causes flicker and wastes time. Checking for a change first is a one-line fix. Explanation: Update on change only.

✅ Check your understanding

Quick recall check, generated from this lesson’s key terms. It is practice only and is not graded.

Keep reading to complete this lesson