A Raspberry Pi–based smart thermostat built with Kivy, using a DHT22 sensor for temperature & humidity readings and an I²C Relay HAT for heating/cooling control, displayed on a 3.5" 480×320 SPI touch screen.
- Real-time sensor display: Shows current temperature and humidity.
- Automatic control: Maintains a user-defined threshold with hysteresis to prevent relay chatter.
- Manual override: Toggle fan and heater independently via buttons.
- Unit switching: Convert between °C and °F on the fly.
- Date & time display: Central Time Zone clock updates every second.
- Touchscreen interface: All controls optimized for touch on a 3.5" display.
- Package structure: Clear separation of sensor I/O, control logic, and GUI code.
- Logging: All events and errors logged to
thermostat.log
.
- Touchscreen: 3.5 Inch 480×320 Touch Screen TFT LCD SPI Display Panel for Raspberry Pi A, B, A+, B+, 2B, 3B, 3B+, 4B, 5
-
Format SD Card : Download and run SD Card Formatter:
-
Write OS Image: Download Win32DiskImager and write Raspberry Pi OS:
-
Enable SSH
- Create an empty file named
ssh
(no extension) on the boot partition of the SD card.
- Create an empty file named
-
Hardware Setup
- Insert the SD card into the Raspberry Pi.
- Connect the 3.5" touch display via the SPI header.
- Power on the Pi.
-
Network & SSH
# On Pi, find IP address: ifconfig
- Connect using PuTTY or your SSH client (port 22).
- Login as
pi
, then change the default password when prompted.
-
Create Virtual Environment
sudo apt-get update sudo apt-get install python3-venv mkdir ~/my_project && cd ~/my_project python3 -m venv env source env/bin/activate
-
Install Dependencies
pip install adafruit-blinka adafruit-circuitpython-dht kivy smbus2 pytz pip install pyqt5 Adafruit_DHT RPi.GPIO # If PyQt5 errors: sudo apt-get install qt5-qmake qtbase5-dev build-essential libgl1-mesa-dev
-
Run the Application
python main.py
your_project/
├── thermostat/
│ ├── __init__.py
│ ├── sensors.py
│ ├── control_logic.py
│ └── GUI.py
└── main.py
- Python 3.7+
- Kivy
- adafruit-circuitpython-dht
- smbus2
- pytz
Install via:
pip install kivy adafruit-circuitpython-dht smbus2 pytz
git clone <repo-url>
cd your_project
source env/bin/activate # if using venv (recommended for external libraries)
python main.py
- Touchscreen controls:
- Slide threshold.
- Toggle Automatic/Manual.
- Manually toggle Fan/Heater.
- Switch °C/°F.
- Threshold & Hysteresis:
thermostat/control_logic.py
- I²C Addresses/Channels:
thermostat/sensors.py
- Display Settings:
thermostat/GUI.py
or override inmain.py
MIT License