A Raspberry Pi 4 based Embedded Linux IoT project for controlling an LED through a physical push button and a mobile-friendly web application.
The project contains two source-code components:
LED_Control_MQTT— Embedded Linux C application running on Raspberry Pi 4. It controls GPIO17, monitors GPIO27, and communicates using MQTT.LED_Control_Web— Python Flask web application with HTML, Bootstrap 5, JavaScript, and Paho MQTT for user-friendly LED control.
MQTT is the communication layer between the hardware-side C application and the web application.
LED_Control_Using_IoT/
├── README.md
├── .gitignore
│
├── LED_Control_MQTT/
│ ├── led_control_mqtt.c
│ └── README.md
│
└── LED_Control_Web/
├── app.py
├── mqtt_client.py
├── requirements.txt
├── templates/
│ └── index.html
├── static/
│ ├── css/
│ │ └── style.css
│ └── js/
│ └── app.js
└── README.md
Local Network
│
┌────────▼────────┐
│ Phone / Laptop │
│ │
│ HTML │
│ Bootstrap 5 │
│ JavaScript │
└────────┬────────┘
│ HTTP
▼
┌─────────────────┐
│ Flask Web App │
│ │
│ Python │
│ Paho MQTT │
└────────┬────────┘
│ MQTT
▼
┌─────────────────┐
│ Mosquitto │
│ MQTT Broker │
└────────┬────────┘
│ MQTT
▼
┌─────────────────┐
│ Raspberry Pi 4 │
│ │
│ C Application │
│ libmosquitto │
│ libgpiod │
└───────┬─────────┘
│
┌─────┴─────┐
│ │
GPIO17 GPIO27
│ │
▼ ▼
LED Push Button
| Component | Raspberry Pi GPIO |
|---|---|
| LED | GPIO17 |
| Push Button | GPIO27 |
The push button uses an input with an internal pull-up. The LED is controlled as a GPIO output.
- Raspberry Pi 4
- Debian Linux
- C
- AArch64 GNU cross compiler
- libgpiod
- libmosquitto
- Mosquitto MQTT broker
- Python 3
- Flask
- Paho MQTT
- HTML5
- Bootstrap 5
- JavaScript
rpi4/led/set
Messages:
ON
OFF
The web application publishes commands to this topic.
rpi4/led/status
Messages:
ON
OFF
The C application publishes the actual LED state to this topic.
Web Button
↓
Flask
↓
Paho MQTT
↓
rpi4/led/set
↓
Mosquitto
↓
C Application
↓
libgpiod
↓
GPIO17
↓
LED
Physical Push Button
↓
GPIO27
↓
C Application
↓
rpi4/led/status
↓
Mosquitto
↓
Python MQTT Client
↓
Flask
↓
Web Interface
This provides two-way IoT communication: the web application controls the LED, while the hardware-side application publishes the actual LED state back to the web application.
The current implementation can operate without Internet access when all components are reachable on the same local network.
Internet access is only required if the system is later extended to use a cloud service or remote MQTT broker.
Cross-compile led_control_mqtt.c for AArch64 Linux and copy the resulting executable to the Raspberry Pi.
Then:
chmod +x LED_Control_MQTT
./LED_Control_MQTTIf GPIO permissions require elevated privileges:
sudo ./LED_Control_MQTTVerify Mosquitto:
sudo systemctl status mosquittoFrom LED_Control_Web:
python -m venv .venvWindows:
.venv\Scripts\activateLinux:
source .venv/bin/activateInstall dependencies:
pip install -r requirements.txtStart Flask:
python app.pyFor local testing:
http://127.0.0.1:5000
To access the application from a phone on the same LAN:
http://<SERVER-IP>:5000
Replace <SERVER-IP> with the IP address of the computer running Flask.
- Start Mosquitto on the Raspberry Pi.
- Start the C application.
- Start the Flask web application.
- Open the web interface.
- Press ON and verify that the LED turns ON.
- Press OFF and verify that the LED turns OFF.
- Keep the C application running.
- Press the physical push button.
- Verify the LED state changes.
- Verify the web interface reflects the LED status.
Do not commit passwords, private credentials, MQTT authentication data, or other secrets.
Do not put machine-specific private IP addresses into public documentation. Use placeholders such as <RASPBERRY-PI-IP> or <SERVER-IP>.
- Cloud MQTT deployment
- Remote Internet-based control
- MQTT authentication
- TLS/SSL
- HTTPS
- User authentication
- Multiple GPIO devices
- Sensor integration
- IoT dashboard
- systemd service deployment
- Docker deployment
This project demonstrates an end-to-end Embedded Linux IoT workflow:
Embedded Linux
+
C
+
GPIO
+
MQTT
+
Python
+
Flask
+
Web UI
=
IoT LED Control System