2025

Smart Thermostat Control System

An embedded IoT thermostat prototype built for Raspberry Pi featuring state machine logic, PWM LED control, and UART serial communication for temperature regulation simulation

Tech Stack

Python 3Raspberry Pi 4gpiozerostatemachinepyserialGPIOPWMUART

Context

The Problem

Smart home thermostats require reliable hardware-software integration to control heating/cooling systems based on user input and environmental data. This project explores how embedded systems manage state transitions and hardware peripherals for IoT applications.

Constraints

  • Raspberry Pi hardware with GPIO pins, LEDs, and buttons
  • State machine design for Off, Heat, and Cool modes
  • PWM (Pulse Width Modulation) for LED brightness control
  • UART serial communication for data transmission
  • Python-based implementation with hardware abstraction
  • Support for setpoint adjustment with button inputs

Stakes

Academic project for CS-350 (Emerging Systems Architecture and Technologies) demonstrating embedded systems programming, hardware interfacing, and IoT principles

My Role

Title

Embedded Systems Developer

Team

Academic Project (Individual)

Ownership

Complete development of thermostat logic, state machine implementation, GPIO control, PWM configuration, UART communication, and hardware integration

Approach & Key Decisions

Designed and implemented a thermostat control system using Raspberry Pi 4 with Python, leveraging the gpiozero library for GPIO control and statemachine library for state management, with PWM for LED fading effects and UART for serial communication with external systems.

Python 3 with gpiozero library for GPIO abstraction

gpiozero provides high-level Pythonic API for GPIO operations, simplifying LED and button control while abstracting low-level register manipulation and pin management.

State machine pattern for thermostat mode management

State machines provide clean separation of Off, Heat, and Cool behaviors with explicit transitions, making the logic maintainable and testable compared to nested conditionals.

PWM (Pulse Width Modulation) for LED intensity control

PWM enables smooth LED fading effects to indicate temperature differential (solid LED when at setpoint, fading when heating/cooling needed), providing intuitive visual feedback without analog circuits.

UART serial communication for thermostat-server messaging

UART enables communication with external systems like temperature sensors or monitoring servers, demonstrating real-world IoT connectivity patterns used in smart home devices.

Button-based interface for mode cycling and setpoint adjustment

Physical buttons simulate real thermostat controls, allowing users to cycle through Off/Heat/Cool modes and adjust target temperature without requiring display or touchscreen.

Modular code architecture with separated CRUD, app logic, and data import

Separating concerns enables independent testing of state machine logic, hardware interfacing, and serial communication, improving code maintainability and reusability.

Alternatives Considered

Considered using C for direct hardware control but chose Python for rapid prototyping, better debugging experience, and extensive library support for Raspberry Pi

Challenges & Solutions

Challenge

Implementing state machine logic with clean transitions between Off, Heat, and Cool modes

Solution

Used statemachine library to define explicit states and transitions, with button press events triggering state changes and LED colors (red for Heat, blue for Cool, off for Off mode) updating automatically.

Challenge

Creating realistic LED fading effects to indicate temperature differential

Solution

Implemented PWM control with gpiozero's PWMLED class, calculating duty cycle based on difference between current temperature and setpoint. LEDs fade when temperature is away from setpoint and stay solid when reached.

Challenge

Handling button debouncing and multiple input events simultaneously

Solution

Leveraged gpiozero's Button class with built-in debouncing, configured separate callbacks for mode button, increase button, and decrease button with proper event handling and state updates.

Challenge

Establishing UART serial communication for data logging and monitoring

Solution

Built client-server architecture using pyserial library, encoding thermostat state (mode, setpoint, temperature) into byte streams, transmitting over UART, and decoding on server side for logging and visualization.

Challenge

Simulating temperature changes without physical temperature sensor

Solution

Implemented temperature simulation logic that gradually adjusts toward setpoint based on current mode (heating increases temperature, cooling decreases it), providing realistic behavior for testing and demonstration.

Outcomes & Impact

Embedded Systems Expertise

Demonstrated proficiency in Raspberry Pi GPIO programming, hardware-software integration, and IoT device prototyping

State Machine Implementation

Clean state-driven architecture with Off, Heat, and Cool modes with button-triggered transitions

PWM Control

Smooth LED fading effects based on temperature differential using pulse width modulation at 60+ Hz

UART Communication

Serial data transmission between Raspberry Pi and monitoring server using pyserial with byte encoding/decoding

User Interface

Physical button controls for mode cycling and setpoint adjustment with real-time LED visual feedback

Video Demonstration

Published YouTube demo showcasing thermostat functionality and hardware interaction

Project Links