An automated greenhouse control system built on the STM32F103C8T6 (BluePill), monitoring environmental conditions and automatically controlling actuators (fan, water pump, servo-driven window, grow light) — with a keypad + LCD interface for manual control and live debugging.
This was a team project for our Embedded Systems course, developed and simulated in Proteus, programmed with STM32CubeMX + Keil (MDK-ARM).
The system continuously reads a set of analog sensors (temperature, gas/air quality, soil moisture, light, humidity, water level) plus a digital rain sensor, and automatically drives the greenhouse's actuators to keep conditions within target ranges. A 20×4 character LCD and 4×4 matrix keypad give the user a menu-driven interface to view live sensor readings, switch between automatic and manual control of the fan/pump, and access a dedicated debug page — all built without any RTOS, running on a single bare-metal control loop.
- Automatic climate control
- Fan turns on based on temperature, gas level, or humidity thresholds
- Water pump activates on low soil moisture, and skips watering if rain is detected or the water reservoir is low
- Grow light toggles based on ambient light level
- Buzzer + RGB-style status LEDs alert on high temperature
- Motorized window (servo)
- Smooth, non-blocking open/close motion (ramped pulse width, not an instant jump)
- Physical lock button (interrupt-driven) that freezes the window at its current position
- LCD + Keypad UI
- Multi-page menu: help screen, main status, sensor detail, and a live debug page
- Manual override for fan and pump directly from the keypad, with a one-key return to full-auto mode
- Debounced keypad scanning tuned to avoid phantom key presses
- Built with STM32 HAL (no RTOS) — a single non-blocking main loop drives sensing, control, UI, and I/O together
- MCU: STM32F103C8T6 ("BluePill")
- Framework: STM32 HAL (via STM32CubeMX code generation)
- IDE / Toolchain: Keil MDK-ARM
- Simulation: Proteus (schematic + live simulation)
- Language: C
Smart-Greenhouse/
├── FourthCube/FourthCube/
│ ├── Core/
│ │ ├── Inc/ # Header files (main.h, LCD1602.h, etc.)
│ │ └── Src/ # Application source (main.c, LCD1602.c, etc.)
│ ├── Drivers/ # STM32 HAL + CMSIS (generated by CubeMX)
│ ├── MDK-ARM/ # Keil project files
│ └── FourthCube.ioc # CubeMX configuration file
└── Simu/ # Proteus simulation project + backups
- Install STM32CubeMX and Keil MDK-ARM (or MDK-ARM Lite for smaller projects)
- Open
FourthCube/FourthCube/FourthCube.iocin CubeMX if you want to inspect/regenerate the peripheral configuration - Open
FourthCube/FourthCube/MDK-ARM/FourthCube.uvprojxin Keil - Build the project (F7)
- Flash to an STM32F103C8T6 board via ST-Link (or your preferred programmer)
To simulate without hardware:
- Open the project in Proteus from the
Simu/folder - Load the compiled
.hexfile (found inMDK-ARM/FourthCube/FourthCube.hexafter building) onto the virtual MCU - Run the simulation
- Sensors (ADC): 3× temperature inputs, gas/air quality, soil moisture, light, humidity, water level
- Digital input: Rain sensor
- Actuators: Fan, water pump, grow light, buzzer, status LEDs (GPIO outputs)
- Servo motor: Drives the window open/close mechanism via PWM (TIM3), with a physical lock button on an external interrupt line
- User interface: 20×4 character LCD (custom driver) + 4×4 matrix keypad
This was built as a team project:
- Amirreza Farghani — hardware layout, servo/window control, actuator logic
- Mohammadreza Osuli — air quality, water level & rain sensing, fan control
- Mani Ebrahimi — keypad and LCD integration
- Hosein Sabzforoush — light and water sensor logic
Working on the sensor and control logic taught me a lot about tuning threshold-based automatic control (avoiding oscillation between on/off states) and debugging real hardware issues like floating-pin spurious interrupts and keypad phantom key presses — problems that only show up once you move past pure simulation.