How to connect 2.8 inch TFT display to Arduino for temperature monitor?
How to connect 2.8 inch TFT display to Arduino for temperature monitor
You connect a 2.8 inch TFT display to an Arduino for a temperature monitor by wiring the display's SPI interface to the Arduino's hardware SPI pins, then using a temperature sensor like the DS18B20 or DHT22, and coding the display to show real-time readings. The most common TFT module for this is the ILI9341-based 240x320 pixel display, which runs on 5V logic (many modules include a voltage regulator) and communicates over SPI, requiring only 5-6 digital pins plus power. For a reliable setup, you need the display, a temperature sensor, a breadboard, jumper wires, and the Arduino board—typically an Uno or Mega. The SPI pins on the Uno are: SCK (pin 13), MOSI (pin 11), and MISO (pin 12), plus you need a chip select (CS) and data/command (DC) pin, often set to pins 10 and 9. The reset pin can be tied to Arduino reset or a digital pin. For the temperature sensor, the DS18B20 uses the OneWire protocol, needing only one digital pin (like pin 2) with a 4.7kΩ pull-up resistor. The DHT22 uses a simpler single-wire protocol but requires a 10kΩ pull-up. Power both the display and sensor from the Arduino's 5V and GND pins. The display draws around 80-120mA when active, so the Uno's 5V regulator (500mA max) handles it fine, but avoid powering servos or motors from the same rail. You can get a 2.8 inch tft display module for arduino that includes the ILI9341 driver and a microSD slot, which is useful for logging temperature data. The wiring is straightforward: connect display VCC to 5V, GND to GND, CS to digital pin 10, RESET to digital pin 8 or Arduino reset, DC to digital pin 9, MOSI to pin 11, SCK to pin 13, and LED backlight to 3.3V or 5V via a 100Ω resistor (to limit current to about 20mA). The MISO pin is optional for reading from the display, but it's needed if you use the SD card slot. For the DS18B20, connect its VDD to 5V, GND to GND, and data pin to digital pin 2 with a 4.7kΩ resistor between data and VDD. The DHT22 connects VCC to 5V, GND to GND, and data to digital pin 3 with a 10kΩ resistor between data and VCC. The display's resolution is 240x320 pixels, which is enough to show temperature values in large fonts, a simple graph, and a color-coded background (e.g., blue for cold, red for hot). The ILI9341 library by Adafruit (version 1.5.13) and the TFT_eSPI library by Bodmer (version 2.5.43) are the most stable for SPI communication. The TFT_eSPI library is faster because it uses direct register writes and supports frame buffering, achieving up to 30 frames per second for simple text updates. For the DS18B20, use the OneWire library (version 2.3.8) and DallasTemperature library (version 3.9.0). For the DHT22, use the DHT sensor library (version 1.4.4) by Adafruit. The code structure is: initialize the display at 240x320, set rotation to 1 (landscape mode), initialize the temperature sensor, then in the loop(), read the sensor every 2 seconds (DS18B20 takes 750ms for 12-bit conversion, DHT22 takes 2 seconds), clear the display area for the temperature value, draw a background color based on the temperature range, and print the value in large text. For example, if the temperature is below 20°C, set background to blue (RGB 0,0,255) and text to white; if between 20-30°C, green background with black text; if above 30°C, red background with white text. The font size can be set to 4 (16x32 pixels) for the main value, which fits "25.5°C" easily. You can also draw a simple bar graph: a rectangle that fills proportionally from 0 to 100% based on the temperature range (e.g., 0-50°C). The display's SPI clock speed can be set to 40MHz in the library, but 20MHz is safer for longer wires (over 20cm). The Arduino Uno's SPI clock is 16MHz divided by 2, 4, or 8, so 8MHz is typical. For faster updates, use the TFT_eSPI library with the SPI frequency set to 40MHz in the User_Setup.h file: #define SPI_FREQUENCY 40000000. The display's response time is about 10ms for a full screen fill, so updating just the text area takes under 5ms. The temperature sensor accuracy: DS18B20 is ±0.5°C from -10°C to +85°C, with 9-12 bit resolution (0.5°C to 0.0625°C steps). The DHT22 is ±0.5°C from -40°C to +80°C, with 0.1°C resolution. For a monitor, the DS18B20 is better for precision, but the DHT22 also gives humidity. If you use the DHT22, you can display both temperature and humidity on the 240x320 screen: temperature on the left half, humidity on the right, each with a 120x200 pixel area. Use the TFT_eSPI library's setTextDatum() function to align text to the center: TL_DATUM for top-left, TC_DATUM for top-center, etc. For example, setTextDatum(TC_DATUM) centers the text horizontally at the cursor's x position. The display's color depth is 16-bit (65,535 colors), so you can use 565 format: color565(255,0,0) for red. The background can be drawn with fillScreen(color565(0,0,255)) for blue. The temperature value can be displayed with setCursor(120, 160) for center of the screen in landscape mode. The font files are included in the library: Fonts/FreeSans12pt7b.h for 12-point sans-serif, or use the built-in GLCD font (5x7 pixels) for small labels. For a professional look, use the FreeSans18pt7b.h font for the temperature value (about 24x36 pixels). The code for reading the DS18B20: sensors.requestTemperatures(); float tempC = sensors.getTempCByIndex(0); if (tempC == -127.00) { display error message; } else { display tempC; }. For the DHT22: dht.readTemperature(); float tempC = dht.readTemperature(); float humidity = dht.readHumidity(); if (isnan(tempC) || isnan(humidity)) { display error; } else { display both; }. The display's backlight can be controlled with PWM on a digital pin (e.g., pin 6) to dim the screen at night. Connect the LED pin to a transistor (2N2222) base through a 1kΩ resistor, collector to display LED, emitter to GND, and apply PWM from Arduino. The frequency should be 500Hz or higher to avoid flicker. The power consumption with backlight on is about 120mA at 5V (0.6W), which is fine for USB power. If you use a battery, consider a 3.3V version of the display (the 5V module has a regulator that drops 1.2V, so it works down to 6.2V input). The SPI wiring can be extended up to 1 meter with twisted-pair wires and 10pF capacitors to ground at the display end to reduce noise. The temperature sensor wire can be extended up to 10 meters for the DS18B20 (it uses parasitic power mode if you connect VDD to GND, but normal mode is better). The data pin for the DS18B20 should have a 4.7kΩ pull-up resistor to 5V, and the wire should be shielded if near motors. The display's microSD slot uses SPI on the same bus but with a separate CS pin (usually pin 4). You can log temperature data to a microSD card with the SD library (version 1.2.4). The file format can be CSV: timestamp, temperature. Use the RTC module (DS3231) for accurate timestamps, connected via I2C (SDA pin A4, SCL pin A5 on Uno). The DS3231 has a built-in temperature sensor with ±3°C accuracy, but it's not as precise as the DS18B20. For a standalone monitor, you can add a button to toggle between Celsius and Fahrenheit, or a potentiometer to set the alarm threshold. The button connects to a digital pin with internal pull-up (pinMode(pin, INPUT_PULLUP)). The potentiometer connects to analog pin A0, and you read the value with analogRead() to set the alarm temperature (0-1023 maps to 0-50°C). The display can show an alarm message in red if the temperature exceeds the threshold. The TFT_eSPI library supports touch screens if your module has a resistive touch overlay (usually XPT2046 controller). The touch pins are: T_IRQ to pin 7, T_DO to pin 12, T_DIN to pin 11, T_CS to pin 6, T_CLK to pin 13. You can use the touch to change the temperature scale or reset the max/min values. The calibration for touch is done with the library's calibrateTouch() function, which returns x, y, and z (pressure). The typical touch resolution is 4096x4096, mapped to the 240x320 display. For a temperature monitor, you can draw buttons on the screen: a "Reset Max" button at the bottom left, and a "C/F" button at the bottom right. The button detection is done by checking if the touch coordinates fall within the button rectangle. The display's refresh rate for touch updates is about 10ms, so you can poll touch every 100ms. The overall system latency from sensor read to display update is about 800ms for DS18B20 (due to conversion time) and 2 seconds for DHT22. You can reduce this by using the DS18B20 in 9-bit mode (conversion time 93.75ms) but with 0.5°C resolution. The code for 9-bit mode: sensors.setResolution(9); sensors.requestTemperatures(); delay(100);. The display update can be done in the background using a non-blocking timer with millis(). For example, read the sensor every 2 seconds, and update the display only if the temperature changed by more than 0.1°C. This reduces flicker and power consumption. The Arduino's flash memory usage for the full code (display, sensor, SD card, touch) is about 28KB out of 32KB on the Uno, so you need to optimize if adding features. Use the PROGMEM keyword for font data and strings to save RAM. The SRAM usage is about 1.5KB for buffers, leaving 0.5KB free. For the Mega, you have 8KB SRAM and 256KB flash, so no issues. The display's physical size is 2.8 inches diagonal, 50mm x 70mm, with a viewing angle of 60 degrees in all directions (TN panel). The brightness is about 300 cd/m² with the backlight at full, which is readable indoors but not in direct sunlight. For outdoor use, add a polarizing filter or increase the backlight current to 40mA (the LED can handle up to 50mA, but it reduces lifespan). The display's operating temperature is -20°C to +70°C, so it's fine for indoor monitors. The temperature sensor range: DS18B20 is -55°C to +125°C, DHT22 is -40°C to +80°C. For a freezer monitor, the DS18B20 is better. The connection reliability: use female-to-female jumper wires for the display (2.54mm pitch), and male-to-female for the sensor. Solder the sensor wires to avoid loose connections. The pull-up resistor for the DS18B20 should be as close to the sensor as possible, or at the Arduino end. The display's CS pin should be pulled high with a 10kΩ resistor to prevent spurious SPI transactions during boot. The reset pin can be connected to the Arduino's reset pin via a 100Ω resistor to allow the display to reset with the Arduino. The DC pin determines whether the SPI data is a command (low) or data (high). The ILI9341 initialization sequence is handled by the library, but you can customize the rotation: setRotation(1) for landscape with the USB port on the left. The pixel coordinates: (0,0) is top-left, (239,319) is bottom-right in portrait, but in landscape it's (0,0) top-left, (319,239) bottom-right. The temperature value can be displayed at (160, 120) for center of the screen in landscape. The font height for FreeSans18pt7b is 24 pixels, so the text fits within a 30-pixel tall area. The background color can be a gradient from blue to red based on temperature, using the map() function to convert temperature to hue. For example, map(tempC, 0, 50, 0, 255) for blue (0) to red (255). The color can be created with color565(hue, 0, 255-hue) for a simple gradient. The display's SPI bus can be shared with other devices (like an SD card) if you use separate CS pins. The maximum SPI speed for the ILI9341 is 40MHz, but the Arduino Uno's SPI hardware limits it to 8MHz (16MHz/2). The TFT_eSPI library can use a software SPI mode for other pins, but hardware SPI is faster. For the temperature monitor, 8MHz is enough because you only update every 2 seconds. The data from the sensor can be formatted with dtostrf(tempC, 4, 1, buffer) to convert float to string with one decimal place. The buffer size should be 10 bytes. The display's fillRect() function can be used to draw a bar graph: fillRect(10, 200, map(tempC, 0, 50, 0, 220), 20, color565(0,255,0)) for a green bar. The bar's height is 20 pixels, and the width varies with temperature. The axis can be drawn with drawLine() and drawFastHLine(). The grid lines can be at 10°C intervals: drawFastVLine(10 + map(10, 0, 50, 0, 220), 200, 20, color565(255,255,255)). The text labels for the axis can be drawn with setCursor() and print(). The overall layout: top 40 pixels for the title "Temperature Monitor", middle 160 pixels for the large temperature value, bottom 40 pixels for the bar graph and buttons. The title can be in white on a dark blue background. The temperature value can be in black on a white background for contrast. The bar graph can have a gradient from blue to red. The buttons can be drawn with fillRoundRect() for a modern look. The touch detection for buttons: if (touch.x > 10 && touch.x < 110 && touch.y > 200 && touch.y < 240) { toggle C/F; }. The touch coordinates need to be scaled from the raw values (0-4095) to the display coordinates (0-239 for x, 0-319 for y) using the calibration data. The calibration data can be stored in EEPROM (address 0) and read at startup. The EEPROM library (version 2.0) uses 1 byte per address, so store the calibration as 4 integers (xmin, xmax, ymin, ymax) in 8 bytes. The touch is resistive, so it requires a stylus or finger pressure (about 50g force). The display's glass is 1.1mm thick, so it's durable. The overall project cost: Arduino Uno ($25), display module ($12), DS18B20 ($3), breadboard ($5), jumper wires ($3), total $48. The code is open-source on GitHub, with examples from Adafruit and Bodmer. The wiring diagram: Arduino pin 13 to display SCK, pin 11 to MOSI, pin 12 to MISO (optional), pin 10 to CS, pin 9 to DC, pin 8 to RESET, 5V to VCC, GND to GND. For the DS18B20: pin 2 to data, 5V to VDD, GND to GND, 4.7kΩ between data and VDD. For the DHT22: pin 3 to data, 5V to VCC, GND to GND, 10kΩ between data and VCC. The power supply: use a 5V 1A USB adapter for the Arduino, or a 9V battery with the Arduino's barrel jack. The display's backlight can be turned off in software to save power: digitalWrite(backlightPin, LOW) if using a transistor. The sensor can be powered down between readings: digitalWrite(sensorPowerPin, LOW) for the DS18B20 (if using a MOSFET). The average power consumption with backlight off and sensor sleeping is about 50mA, which gives 20 hours on a 1000mAh battery. The data logging to SD card: use the SD library's File class to open "temps.csv" and append data. The file format: "2025-03-15 14:30:00, 25.5\n". The RTC module (DS3231) provides the timestamp via the RTClib library (version 2.1.4). The SD card should be formatted as FAT16 or FAT32, with a maximum size of 32GB. The display's microSD slot supports up to 32GB cards.
Ready to taste the story?
Browse our chef-developed, brown-butter cookie collection — baked in Brooklyn and shipped bakery-fresh nationwide.
Shop Cookies