This AIoT project utilizes an ESP32 microcontroller, an MPU6050 accelerometer/gyroscope sensor, an LCD display, and a potentiometer to build a real-time motion classification system. By leveraging a trained Random Forest machine learning model, the system identifies six different physical activities (e.g., bench press, overhead press, deadlift, squat, row, rest) and displays the results on the LCD. The system is designed for fitness tracking, sports performance monitoring, and real-time activity recognition. It integrates hardware and software to demonstrate a complete AIoT pipeline, from data collection and model training to deployment and visualization.
-
VS Code:
-
PlatformIO Extension:
- Install the PlatformIO IDE extension in VS Code.
- Go to Extensions (Ctrl+Shift+X), search for "PlatformIO IDE," and install it.
-
Wokwi Simulator:
- Install the Wokwi extension in VS Code to simulate ESP32 projects.
-
Python:
- Install Python (version >= 3.7).
-
KiCad:
- KiCad is an open-source software suite that I used for creating schematics and designing printed circuit boards (PCBs) in this project. It offers powerful tools and extensive community support, making it an ideal choice for hardware development.
- Use KiCad for schematic design and PCB layout.
- Leverage its tools for creating custom PCBs and visualizing designs in 3D.
Install the following Python libraries:
pip install pandas scikit-learn micromlgen
Add these libraries in the platformio.ini
file:
LiquidCrystal
Adafruit MPU6050
Adafruit Unified Sensor
The wokwi.toml
file is a configuration file used by the Wokwi simulator to set up the simulation environment for your project. It specifies important details like the firmware binary file to be used and the ELF file for debugging purposes.
[wokwi]
version = 1
firmware = '.pio/build/adafruit_feather_esp32s3_nopsram/firmware.bin'
elf = '.pio/build/adafruit_feather_esp32s3_nopsram/firmware.elf'
firmware
: Points to the compiled firmware binary that runs on the ESP32 in the simulator.elf
: Points to the ELF file used for debugging the firmware in the Wokwi simulator.
This file ensures that the simulation environment mirrors the real-world hardware configuration, allowing you to test your code effectively without physical hardware.
- ESP32-S3: Simulator was used to test the Model and IoT.
- MPU6050: Accelerometer and gyroscope sensor.
- LCD1602: 16x2 character LCD.
- Potentiometer: To adjust LCD brightness.
- Resistor: 1kOhm resistor.
Refer to the diagram.json
file to see the connections in the Wokwi simulator.
Component | ESP32 Pin | Description |
---|---|---|
MPU6050 - SDA | GPIO8 | I2C Data |
MPU6050 - SCL | GPIO9 | I2C Clock |
LCD1602 - RS | GPIO42 | Register Select |
LCD1602 - E | GPIO40 | Enable |
LCD1602 - D4, D5, D6, D7 | GPIO35, GPIO36, GPIO45, GPIO48 | Data Pins |
LCD1602 - V0 | Potentiometer SIG | Brightness Control |
- File:
motion_sensor.csv
- Contains motion data with accelerometer and gyroscope readings.
- Labels:
bench
,ohp
,dead
,squat
,row
,rest
.bench
: Bench press.ohp
: Overhead press.dead
: Deadlift.squat
: Squats.row
: Barbell rows.rest
: Inactivity or resting periods.
-
Description: This dataset contains motion sensor data collected from an MPU6050 sensor. It provides essential insights into various physical activities through accelerometer and gyroscope data, enabling real-time activity classification and motion analysis. Applications include fitness tracking, sports performance monitoring, and AI-powered activity recognition systems.
-
Use Cases:
- Train machine learning models for activity recognition.
- Develop real-time AIoT systems for fitness tracking.
- Analyze motion patterns for health and performance monitoring.
-
Data Dictionary:
- epoch: Timestamp of the data collection (numerical). Represents a Unix timestamp indicating the exact time each data point was recorded.
- Accelerometer_x: Acceleration along the x-axis (numerical).
- Accelerometer_y: Acceleration along the y-axis (numerical).
- Accelerometer_z: Acceleration along the z-axis (numerical).
- Gyroscope_x: Angular velocity around the x-axis (numerical).
- Gyroscope_y: Angular velocity around the y-axis (numerical).
- Gyroscope_z: Angular velocity around the z-axis (numerical).
- Label: Activity performed (
bench
,ohp
,dead
,squat
,row
,rest
) (categorical).
- File:
motion_sense.ipynb
- Preprocess the data and train a Random Forest classifier.
- Convert the trained model into C code using the
micromlgen
library.
- Load the dataset.
- Split the data into training and testing sets.
- Train a Random Forest classifier.
- Export the model to a header file:
from micromlgen import port c_code = port(clf, classmap=labels) with open("model.h", "w") as f: f.write(c_code)
- Copy the generated
model.h
file to theinclude/
directory of your PlatformIO project.
- File:
platformio.ini
- Create a new PlatformIO project for the ESP32-S3 board.
- Add the required libraries in the
platformio.ini
file:[env:adafruit_feather_esp32s3_nopsram] platform = espressif32 board = adafruit_feather_esp32s3_nopsram framework = arduino lib_deps = LiquidCrystal Adafruit MPU6050 Adafruit Unified Sensor
- File:
main.cpp
- Write the code to:
- Read accelerometer and gyroscope data from the MPU6050.
- Use the Random Forest model to classify activities.
- Display the result on the LCD.
- Adjust the LCD brightness with the potentiometer.
- Write the code to:
- File:
wokwi.toml
- Set up the Wokwi simulation environment using the following configuration:
[wokwi] version = 1 firmware = '.pio/build/adafruit_feather_esp32s3_nopsram/firmware.bin' elf = '.pio/build/adafruit_feather_esp32s3_nopsram/firmware.elf'
- Launch the Wokwi simulator in VS Code to test the firmware.
- Set up the Wokwi simulation environment using the following configuration:
- Verify the system in both the Wokwi simulator and on real hardware.
- Expected outputs:
- LCD displays the detected activity (e.g., "Motion: bench").
- The potentiometer adjusts LCD brightness.
- Results are logged to the Serial Monitor.
This project was created by me under the guidance of the instructors of IIT Kharagpur for the course - AIoT Hardware Design and Implmentation under IIT Kharagpur AI4ICPS Hub Foundation. Special thanks to faculties Prof. Sourabh Mahapatra, Prof. Abhra Majumder sir and Prof. Deepak Verma
This project demonstrates how to build an AIoT system using ESP32 and MPU6050 for real-time motion classification. A special thanks to IIT Kharagpur AI4ICPS for conducting a workshop on AI and ML for PCB design, which provided the foundational knowledge and inspiration for creating this project. For more information, visit their website: AI4ICPS.
Feel free to connect, collaborate, or share feedback:
- LinkedIn: Vijay Mahawar
- GitHub: vmahawar