Thermometer on a Nokia 5110 LCD
Show an LM35's temperature in large digits on a Nokia 5110 LCD, with its backlight, its contrast setting and the minimum and maximum seen.
Displays · Beginner
In a real product: Handheld thermometer (Medical): A low-power LCD shows readings with minimum and maximum.
The Nokia 5110's screen is an 84 × 48 pixel LCD with a PCD8544 controller: cheap, readable in sunlight and very low power. It runs on 3.3 V, so it takes its supply from the 3.3V pin. It shows an LM35's temperature with the lowest and highest seen since start-up.
What you'll learn
- A bit-banged SPI display: the library toggles CLK and DIN on any five pins
- Contrast (the LCD's bias voltage, Vop): too low and nothing shows
- Keeping a minimum and maximum, and drawing large text in a small screen
How it works
display.begin() resets the controller and sets its bias and contrast; setContrast(50) adjusts that. As with the OLEDs, drawing goes into a buffer in RAM (504 bytes) and display() sends it. The LM35 gives 10 mV a degree, so on a 5 V board each ADC step is 0.49 °C. The backlight pin is driven HIGH to light the screen.
Try this
- Drag the LM35's temperature up and down: the reading and the max/min follow.
- Set the contrast to 0 and to 127: one shows nothing, the other a dark screen on a real module.
- Power the LCD from 5V instead and read the warning: a real one could be damaged.
sketch.ino
// An LM35 on A0 shown on a Nokia 5110 LCD (bit-banged: CLK 7, DIN 6, DC 5, CE 4, RST 3; backlight on pin 9), with the
// lowest and highest temperatures seen.
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
Adafruit_PCD8544 display(7, 6, 5, 4, 3);
float lowest = 1000, highest = -1000;
void setup() {
pinMode(9, OUTPUT);
digitalWrite(9, HIGH); // backlight
display.begin();
display.setContrast(50);
}
void loop() {
float celsius = analogRead(A0) * 500.0 / 1023;
lowest = min(lowest, celsius);
highest = max(highest, celsius);
display.clearDisplay();
display.setTextColor(BLACK);
display.setTextSize(1);
display.setCursor(0, 0);
display.print("TEMPERATURE");
display.setTextSize(2);
display.setCursor(0, 14);
display.print(celsius, 1);
display.print("C");
display.setTextSize(1);
display.setCursor(0, 34);
display.print("lo ");
display.print(lowest, 1);
display.setCursor(0, 41);
display.print("hi ");
display.print(highest, 1);
display.display();
delay(500);
}