ELEGOO MEGA · LESSON 23
Thermometer
Show an illustrative thermistor temperature on the parallel LCD.
Convert an NTC divider voltage into an approximate temperature using stated coefficients.
Parts List
- ELEGOO Mega 2560 R3 is a 5 V ATmega2560 AVR board with many I/O pins and four hardware UARTs for control systems with several peripherals. Long ELEGOO-branded Mega PCB with USB-B and barrel connector, ATmega2560 marking, extended side headers and a large double-row digital header at the end. Read printed Mega labels; its SPI hardware placement is not the same numeric pins as an Uno.
- A USB-A to USB-B cable carries USB power and, when its data conductors are present, a host/device data link. USB-A plug and square USB-B plug. Inspect the plug shape; micro-USB is not USB-C, and USB-B is the squarer device connector.
- An 830-contact solderless breadboard joins inserted leads through hidden spring strips so circuits can be rebuilt without solder. Full-size rectangular board, center channel, numbered five-hole terminal groups and side power rails. Counted contact holes are not component units.
- A parallel LCD1602 displays two rows of sixteen characters using liquid-crystal cells and a character-controller interface. Long rectangular 16×2 window and carrier PCB. A parallel header row is present; check the back to ensure no backpack has been added.
- A screwdriver-adjusted trimmer forms an adjustable voltage divider for calibration or a user control. Blue square screwdriver-adjusted trimmer shown in the KS3020 source crop and PXL_20260924_195451704.jpg. Identify both track ends and wiper with an unpowered resistance measurement.
- 220 Ω resistor provides a fixed opposition to current. LED current limiting is a common use when its unverified power and tolerance limits fit the circuit. Small axial body with one wire at each end. Find the labeled value compartment and measure an isolated loose part with a meter; the shared inventory image is a form reference.
- Male-to-male jumper leads make removable point-to-point connections for low-current prototype signals. Pins at both ends; count individual leads rather than ribbon groups. Check intact insulation and snug contacts before use.
- A thermistor converts temperature changes into resistance changes for divider-based measurement. Small bead with two leads; 10 kΩ comes from the KS3020 BOM. A bare bead can look like a ceramic capacitor; resistance and response to gentle warming distinguish them.
- 10 kΩ resistor provides a fixed opposition to current. Pull-ups, pull-downs and sensor voltage dividers is a common use when its unverified power and tolerance limits fit the circuit. Small axial body with one wire at each end. Find the labeled value compartment and measure an isolated loose part with a meter; the shared inventory image is a form reference.
Assembly
- Disconnect USB; use the 16-pin parallel display and the original layout, applying the backlight resistor addition in the table.
- Set the contrast trimmer near the ground end; reconnect USB and adjust until text appears.
- Connect the NTC toward +5 V and the fixed 10 kΩ resistor toward GND; A0 reads their junction.

Reviewed connections
| From | To | Note |
|---|---|---|
| Mega D7,D8,D9,D10,D11,D12 | LCD pins 4,6,11,12,13,14 | RS,E,DB4,DB5,DB6,DB7 |
| Mega 5 V / GND | LCD 2 VDD / 1 VSS, 5 R/W and 16 K | Leave LCD DB0–DB3 unconnected |
| 10 kΩ trimmer ends → 5 V/GND; wiper → LCD 3 VO | Contrast | Read the actual trimmer wiper identification |
| Mega 5 V → 220 Ω → LCD 15 A | Backlight limit added | Use this series resistor even if the module has its own resistor; reduced brightness is expected |
| NTC: +5 V → A0; fixed 10 kΩ: A0 → GND | Temperature divider | Do not reverse the two components |
Source-reviewed wiring. Hardware not bench-tested; firmware uploads have not been performed.
Code
Download complete PlatformIO project
ZIP includes platformio.ini, src/main.cpp, and bundled libraries (LiquidCrystal).
Extract the ZIP, then open its lesson-23-project/workspaces/lesson-23 folder in VS Code. Keep the adjacent third-party folder in place.
PlatformIO configuration
[env:mega]
platform = atmelavr@5.3.0
board = megaatmega2560
framework = arduino
monitor_speed = 9600
lib_deps =
file://../../third-party/LiquidCrystal
#include <Arduino.h>
#include <LiquidCrystal.h>
#include <math.h> // log is the NATURAL logarithm used in the example's thermistor equation.
const uint8_t TEMPERATURE_PIN = A0;
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void setup() { lcd.begin(16, 2); }
void loop() {
const int reading = analogRead(TEMPERATURE_PIN);
// The divider has the NTC toward +5 V and a fixed 10 kΩ resistor toward GND.
// Reject rail readings before division/logarithms; these commonly indicate a broken divider.
lcd.setCursor(0, 0);
if (reading == 0 || reading == 1023) {
lcd.print("Check sensor ");
delay(500); return;
}
const double logR = log(10000.0 * (1024.0 / reading - 1.0));
// Preserve ELEGOO's Steinhart-Hart coefficient assumptions, not a calibration for every 10 kΩ NTC.
const double kelvin = 1.0 / (0.001129148 + (0.000234125 + 0.0000000876741 * logR * logR) * logR);
const float celsius = kelvin - 273.15;
lcd.print("Temp C "); // Clear all 16 columns so an old extra digit cannot remain.
lcd.setCursor(6, 0);
lcd.print(celsius); // Celsius is the supplied active view; F = C*9/5+32 is an optional edit.
delay(500);
}
Source: SOURCE_RECONCILED. Compile: COMPILE_VERIFIED. Hardware: NOT_TESTED. Upload: NOT_PERFORMED.
Expected behavior
“Temp … C” updates about twice per second and should rise with gentle finger warming. “Check sensor” means an ADC rail reading. The generic coefficients are not confirmed calibration for the inventory bead.
Experiments & Challenges
- Compare the approximate reading with a reference thermometer; keep the original coefficients unless you have calibration data.
Troubleshooting
- Blocks/no text: check VO contrast and RS/E/DB4–DB7 order; an I2C-backpack library does not fit this circuit.