LCD Thermometer
Part of the Displays and Sensors section of Coddy's Arduino journey. Lesson 24 of 24.
A thermometer shows its unit with a degree sign: 24.5°C. The LCD draws letters from its own table of characters, and in that table the degree sign is number 223. Send it with (char)223: (char) tells print() to draw character 223 instead of printing the digits 2, 2, 3.
lcd.print(celsius, 1); // one decimal: 24.5
lcd.print((char)223); // the degree sign
lcd.print("C "); // spaces cover old charactersA ° typed in your text does not work: the editor stores it as two other numbers, and the screen draws the two symbols it keeps at those places.
As with Serial.println(x, 3), a second number in lcd.print(value, 1) sets how many decimals a float shows.
Challenge
MediumThe sketch works out celsius and the top row says Temperature. Show it on the bottom row like 24.5°C:
- the temperature with one decimal
- then the degree sign,
(char)223, thenC - with spaces after, so a shorter value leaves nothing behind
Press Run, change the temperature, then Check.
Try it yourself
#include <LiquidCrystal.h>
// RS, E, D4, D5, D6, D7
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const float BETA = 3950;
void setup() {
lcd.begin(16, 2);
lcd.print("Temperature");
}
void loop() {
int reading = analogRead(A0);
float celsius = 1 / (log(1 / (1023.0 / reading - 1)) / BETA + 1.0 / 298.15) - 273.15;
// show it on the bottom row with one decimal and the degree sign, like 24.5°C
delay(500);
}
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Displays and Sensors
1Seven-Segment Displays
Seven-Segment DisplayDigit Patterns in BytesCount on the DisplayCountdown to ZeroDice RollerPractice on your own: Arduino playground