Projects / Temperature graph on a graphic LCD

Temperature graph on a graphic LCD

Beginner1.5 hGuided buildReviewed

Build it step by step

0 of 6 done
  1. UNOHelloST7920

    Wire the display

    Connect the ST7920 in serial mode with PSB to GND.

  2. UNOHelloST7920

    Test the display

    Run a U8g2 "HelloWorld" example for the ST7920 128x64 SW SPI.

  3. UNODS18B2027.8°C

    Wire the sensor

    Add the DS18B20 with its pull-up.

  4. UNO

    Upload the graph

    Shorten INTERVAL to one second to test.

  5. UNO

    Watch it plot

    Warm the sensor in your hand to see the line rise.

  6. UNO

    Restore the time

    Set INTERVAL back to 30 seconds for an hour of data.

In short

How do you build a temperature graph on a graphic LCD?

A 128 × 64 LCD plots the last hour of temperature, with the current value and the min and max. You need Arduino Uno R3, 128x64 graphic LCD (ST7920), DS18B20 Temperature Sensor, Resistor 4.7 kΩ, Resistor 220 Ω, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 6 steps and about 90 minutes.

Level
Beginner
Time
About 90 min
Parts
7

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
LCD VCC, GNDUno 5V, GNDPower
LCD RS (CS)Uno D10Chip select
LCD R/W (data)Uno D11Serial data
LCD E (clock)Uno D13Serial clock
LCD PSBGNDSelects serial mode
LCD RSTUno D8Reset
LCD backlight A via 220 Ω resistor, KUno 5V, GNDBacklight
DS18B20 VDD, GND, DQUno 5V, GND, D2, with 4.7 kΩ from D2 to 5VTemperature sensor

Code

Arduino IDE, board "Arduino Uno". Install "U8g2", "OneWire" and "DallasTemperature". The ST7920 module must have its PSB pin on GND to use the serial interface. The ring buffer holds 120 readings (240 bytes) and the graph scales to fit the min and max of what it has. While testing, set INTERVAL to 1000 to see the line grow quickly.

Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <U8g2lib.h>
#include <OneWire.h>
#include <DallasTemperature.h>

U8G2_ST7920_128X64_F_SW_SPI u8g2(U8G2_R0, 13, 11, 10, 8);   // clock, data, cs, reset
OneWire oneWire(2);
DallasTemperature sensors(&oneWire);
const byte N = 120;                         // one pixel column per reading
int readings[N];                            // temperature x 10
byte count = 0, head = 0;
const unsigned long INTERVAL = 30000UL;     // 30 s, so 120 points is one hour
unsigned long last = 0;

void setup() {
  sensors.begin();
  u8g2.begin();
  last = millis() - INTERVAL;
}

void loop() {
  if (millis() - last >= INTERVAL) {
    last = millis();
    sensors.requestTemperatures();
    int t = (int)(sensors.getTempCByIndex(0) * 10);
    readings[head] = t; head = (head + 1) % N; if (count < N) count++;
  }
  if (count > 0) {
    int lo = 9999, hi = -9999;
    for (byte i = 0; i < count; i++) { lo = min(lo, readings[i]); hi = max(hi, readings[i]); }
    if (hi - lo < 20) { hi += 10; lo -= 10; }              // keep a sensible vertical scale
    int newest = readings[(head + N - 1) % N];
    u8g2.clearBuffer();
    u8g2.setFont(u8g2_font_logisoso16_tr);
    u8g2.setCursor(0, 17); u8g2.print(newest / 10.0, 1); u8g2.print(" C");
    u8g2.setFont(u8g2_font_5x8_tr);
    u8g2.setCursor(80, 8);  u8g2.print("H "); u8g2.print(hi / 10.0, 1);
    u8g2.setCursor(80, 18); u8g2.print("L "); u8g2.print(lo / 10.0, 1);
    for (byte i = 1; i < count; i++) {
      int a = readings[(head + N - count + i - 1) % N], b = readings[(head + N - count + i) % N];
      int y1 = 63 - (long)(a - lo) * 40 / (hi - lo), y2 = 63 - (long)(b - lo) * 40 / (hi - lo);
      u8g2.drawLine(i - 1 + (N - count) / 2, y1, i + (N - count) / 2, y2);
    }
    u8g2.sendBuffer();
  }
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Power onCurrent temperature at the top left
Warm the probeLine climbs and H updates
Cool againLine falls and L updates
After an hourFull width graph

If it does not work

Blank screen

Check PSB is on GND and the pin order of E, R/W and RS.

No line

Wait for at least two readings.

Reads -127

DS18B20 not found. Check the pull-up.

Graph looks flat

The minimum scale span is 2 degrees; warm the probe to see change.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the temperature graph on a graphic LCD?

Arduino Uno R3, 128x64 graphic LCD (ST7920), DS18B20 Temperature Sensor, Resistor 4.7 kΩ, Resistor 220 Ω, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).

How long does the temperature graph on a graphic LCD take to build?

About 90 minutes for a beginner maker, in 6 steps.

How do I know the temperature graph on a graphic LCD works?

Power on: Current temperature at the top left. Warm the probe: Line climbs and H updates. Cool again: Line falls and L updates.

Blank screen: what should I check?

Check PSB is on GND and the pin order of E, R/W and RS.

No line: what should I check?

Wait for at least two readings.

Reads -127: what should I check?

DS18B20 not found. Check the pull-up.

Graph looks flat: what should I check?

The minimum scale span is 2 degrees; warm the probe to see change.