This is the source code for a full-stack IoT project that monitors and controls a smart classroom prototype, tracks energy consumption, and provides a web-based dashboard for live data and personal carbon tracking.
This project is built on a 3-tier architecture.
-
1_firmware/(Embedded C++)- Device: Arduino Uno
- Code: Reads from PIR, LDR, DHT11, and ACS712 sensors.
- Logic: Controls light and fan relays based on sensor thresholds.
- Output: Sends a complete JSON data packet over the USB Serial port every 2 seconds.
-
2_backend/(Python)- Framework: Flask
- Code: A multi-threaded web server that:
- Runs a background thread to continuously read JSON from the Arduino's serial port.
- Provides a web API for the frontend.
- Manages a SQLite database for the personal carbon tracker.
-
3_webapp/(HTML/CSS/JavaScript)- Framework: Vanilla JS, HTML5, CSS3 (with Chart.js)
- Code: A static website that runs in the user's browser.
- Features:
- Live Dashboard: Polls the backend's
/api/live_dataendpoint to show real-time sensor readings and energy charts. - Personal Tracker: Provides a full CRUD (Create, Read, Delete) interface for a personal carbon log, saving data to the backend's database.
- Live Dashboard: Polls the backend's
You must run all three parts simultaneously.
- Assemble the circuit according to
docs/circuit_diagram.pnganddocs/pin_mapping.txt. - Open the
1_firmware/folder in the Arduino IDE. - Install the required libraries (ArduinoJson, DHT library, Adafruit Unified Sensor).
- Connect your Arduino and upload the
urja_tracker.inosketch. - DO NOT open the Serial Monitor (the Python backend needs access to the port).
- Open a terminal and navigate to the
2_backend/directory. - Setup (First time only):
- Create a virtual environment:
python -m venv venv - Activate it:
.\venv\Scripts\activate(Windows) orsource venv/bin/activate(Mac/Linux) - Install dependencies:
pip install -r requirements.txt
- Create a virtual environment:
- Find your Arduino Port:
- Check your Arduino IDE or Windows Device Manager to find its COM port (e.g.,
COM3,COM4).
- Check your Arduino IDE or Windows Device Manager to find its COM port (e.g.,
- Configure:
- Open the
.envfile and changeCOM_PORT=COM3to match your port.
- Open the
- Run:
- While in your activated virtual environment, run:
python main.py - You should see output indicating the Flask server is running and the serial thread has started.
- While in your activated virtual environment, run:
- No server is needed for the frontend.
- Navigate to the
3_webapp/folder. - Double-click
index.htmlto open it in your default web browser (e.g., Chrome, Firefox). - Navigate to the "Live Dashboard" to see data streaming from your Arduino, or "My Tracker" to log your personal footprint.