- Open
gesture_capture/gesture_capture.inoin Arduino IDE. - Install the following libraries via Library Manager:
- Adafruit MPU6050
- Adafruit Sensor
- Wire (built-in)
- Select your ESP32 board and correct port.
- Upload the sketch to your ESP32.
- Open a terminal and navigate to the
gesture_capturedirectory:cd gesture_capture - (Recommended) Create and activate a virtual environment:
- macOS/Linux:
python3 -m venv .venv source .venv/bin/activate - Windows:
python -m venv .venv .venv\Scripts\activate
- macOS/Linux:
- Install required Python packages:
pip install -r requirements.txt
- Run the data capture script (replace gesture/person as needed):
python process_gesture_data.py --gesture "W" --person "your_name"
This project implements a gesture recognition system using an ESP32 microcontroller with an MPU6050. The system consists of two main components: a gesture data capture system and a gesture inference system.
By completing this lab, students will:
- Understand the fundamentals of gesture recognition using IMU sensors
- Learn to collect and preprocess sensor data
- Gain experience with Edge Impulse's DSP and ML capabilities
- Develop practical skills in embedded systems programming
- Learn to optimize ML models for resource-constrained devices
- Understand the importance of proper hardware integration and user interaction
.
├── gesture_capture/ # Tools for capturing and processing gesture data
│ ├── gesture_capture.ino # Arduino sketch for data capture
│ ├── process_gesture_data.py # Python script for data processing
│ └── data/ # Directory for storing gesture data
└── wand/ # Gesture recognition inference system
└── wand.ino # Arduino sketch for gesture recognition
- ESP32 development board
- MPU6050 sensor
- LED (Check with Prototyping Lab for options of LED)
- Jumper wires for connections
- Breadboard for quick prototyping
- Battery and enclosure for creating your wand
Connect the MPU6050 to your ESP32:
- VCC → 3.3V
- GND → GND
- SCL → GPIO22 (or your I2C clock pin)
- SDA → GPIO21 (or your I2C data pin)
Note: Pin numbers may vary depending on your development board.
- Arduino IDE or PlatformIO with ESP32 board support
- Required libraries:
- Adafruit MPU6050
- Adafruit Sensor
- Wire (built-in)
- Edge Impulse SDK (for inference)
- Python 3.8 or newer
- Required packages specified in
requirements.txt
-
Navigate to the
gesture_capturedirectory -
Create a new project on your laptop. Create a virtual environment, activate it, and install the required libraries in
requirements.txt.For MacOS:
python3 -m venv .venv source .venv/bin/activate pip install -r requirements.txtFow Windows:
python -m venv .venv .venv/Scripts/Activate pip install -r requirements.txt
-
Upload
gesture_capture.inoto your ESP32. -
Run the Python script to collect gesture data:
python process_gesture_data.py --gesture "W" --person "your_name"
Here "W" represents the gesture. Name it appropriately based on the gesture being recorded.
-
Follow the on-screen instructions to capture gestures. The Python script should create a subdirectory as follows:
. ├── data/ # Data directory │ ├── O # All gesture data labeled with O │ ├── V # All gesture data labeled with V -
Collect gesture data for the following three spells:
- Fire Bolt<--->Gesture "Z": Deal 1HP from your opponent, consuming 1MP
- Reflect Shield<--->Gesture "O": Reflect Fire Bold from your opponent with doubled damage and consume 2MP
- Healing Spell<--->Gesture "V": Heal yourself with 1HP, consuming 2MP
- Navigate to the
wand_inferencedirectory - Upload
wand_inference.inoto your ESP32 - Open the Serial Monitor at 115200 baud
- Send 'o' to start gesture capture
- The system will automatically recognize and classify the gesture
The gesture data is stored in CSV format with four columns:
- Timestamp
- x: X-axis acceleration (m/s²)
- y: Y-axis acceleration (m/s²)
- z: Z-axis acceleration (m/s²)
Each capture contains approximately 100 samples (1 second at 100Hz). Modify the capture time for your case. The use of 1 second is for demo purpose only.
The wand inference system uses Edge Impulse for real-time gesture recognition. Here's how it works:
- Real-time gesture recognition at 100Hz sampling rate
- 1-second gesture capture window
- Automatic gesture classification
- Confidence score for each prediction
- The system continuously monitors the MPU6050 accelerometer
- When triggered (by sending 'o' via Serial), it captures 1 second of accelerometer data
- The captured data is processed using the Edge Impulse model
- The system outputs the predicted gesture and confidence score
The inference system is configured with:
- Sampling rate: 100Hz (10ms between samples)
- Capture duration: 1 second
- Accelerometer range: ±8g
- Gyroscope range: ±500°/s
- Filter bandwidth: 21Hz
The system outputs predictions in the following format:
Prediction: [gesture_name] (confidence_percentage%)
- Create a new project in Edge Impulse and complete the Audio classification tutorial.
- You are encouraged to reveiw the Motion Recognition tutorial.
-
Set up the hardware and collect data:
- Connect the MPU6050 to your ESP32. Note: How MPU6050 is placed on bread board should be consistent with your future plan when prototyping your wand.
- Use the provided
gesture_capture.inosketch andprocess_gesture_data.pyto record gesture data. Your data should cover all gestures shown in the spell cards. - For each gesture, collect at least 20 samples. Ensure good quality data by performing the gesture consistently.
- Save all data in the
datadirectory with clear naming conventions.
Note: You are allowed to share your recorded data with others. However, you need to collect your own data.
-
Discussion: Why should you use training data collected by multiple students rather than using your own collected data only? Think about the effectiveness and reliability of your wand.
-
Create a new project in Edge Impulse:
- Upload your collected gesture data as shown in the screenshot below
- Choose "Select a folder" as upload mode
- Choose the data directory on your laptop
- Use "Automatically split between training and testing"
- Correclty enter your label for each file
- By clicking on each data sample, you should visualize the data on the right hand side panel
- Upload your collected gesture data as shown in the screenshot below
-
Design and implement the model:
- Click on "Impulse Design" tab of the sidebar and create a new impulse
- Depending on your MCU, choose target device accordingly, e.g., "Espressif ESP-EYE (ESP32 240MHz)"
- Leave other fields as deafult
- In the data block, try out different parameter values for time size and stride.
- Add a processing block. Read through the available options and pick one for your impulse. Justify your option.
- Add a learning block. Read through the available options and pick one for your impulse. Justify your option.
- Save your impulse.
- Discussion: Discuss the effect of window size. Consider
- the number of samples generated
- the number of neurons in your input layer of neural network
- effectiveness when capturing slow-changing patterns
- Click on "Impulse Design" tab of the sidebar and create a new impulse
-
Choose your DSP block in the sidebar.
- Tune the hyperparameters and visualize the generated features until you are satisfied with the features.
- Take a screenshot of your generated features, and sketch a rough decision boundary between classes. Explain why do you believe the generated features are good enough.
-
Choose your ML block in the side bar.
- Tune the number of training epochs, learning rate, and neural network architecture until you are satisfied with the learning performance.
- Report the learning performance, your choices of hyper-parameters, and architecture.
-
Use "Live classification" and "Model testing" in sidebar to test your model performance. Please clearly document all metrics being used, e.g., accuracy, TP, FP, F1, etc.
-
Choose "Deployment" tab in sidebar.
- Find Arduino Library in the search bar
- Check Quantized (Int8) box, build the model and download it.
-
Discussion: Give at least two potential strategies to further enhance your model performance.
- Deploy the model to your ESP32 and use
wand.inoto test its performance with real-time gestures. Note: You need to rename header file (Line 18) accordingly. - Repeat your testing for a few times, and use appropriate metrics to document your wand's performance.
- Modify the provided
wand.inocode: Implement a button-triggered inference rather than typing 'o' in seriel monitor: ESP32 predicts the gesture once the button is pressed. - Test your code to ensure your wand functions.
- Create a demo video showing your wand.
The prototyping lab has pre-built a board with battery, MCU, switch, and sensor for your uses. Check it out with the instructional team.
- Power your ESP32 using a battery rather than USB cable.
- Use appropriate enclosure for your wand.
Please submit all deliverables listed below as a link to your GitHub repo. In addition, submit your report (pdf format) on Canvas. Please make your report self-contained. An example structure of GitHub repo is provided below for your reference:
TECHIN515-magic-wand/
├── src/
│ ├── sketches/ # Sketches with comments and Edge Impulse exports
│ ├── python-scripts/ # Python scripts for data collection
│ └── dataset/ # Collected dataset
│
├── docs/
│ ├── report.pdf # Final report in PDF format
|
├── media/
│ └── demo.mp4 # Link or file for the demo video
│
├── enclosure/ # CAD/STL files or images of the final enclosure
│ ├── final-enclosure-images/
│ └── notes.md # Description of materials, design decisions, and battery
│
├── README.md # Setup instructions, how to run, install dependencies, etc.
└── .gitignore # Ignore unnecessary files (e.g., __pycache__, temp data)
-
Code and Documentation:
- All sketches with comments
- Python scripts for data collection
- Your dataset
- Edge Impulse project export
- README with setup instructions
-
Report (PDF format) including:
- Pictures of hardware setup and connections
- Data collection process and results
- Edge Impulse model architecture and optimization
- Performance analysis and metrics
- Answers to questions and your choices to all design options with justifications
- Demo video link
- Challenges faced and solutions
-
Demo Video (less than 3 minutes):
- Show hardware setup
- Demonstrate data collection
- Show real-time gesture recognition
- Include performance metrics
-
Enclosure and Battery are due on May 20th, 2025.
- Components including board, MCU, IMU sensor, and wiring should be fully enclosed.
- Use mounting holes to stablize the board within your wand.
- Use reasonable enclosure based on your background in TECHIN511. For example, a box or staff is considered and inappropriate enclosure for the wand.
- Port not found: Specify the port manually with
--port COM3(Windows) or--port /dev/ttyUSB0(Linux/Mac) - Permission denied: On Linux/Mac, run
sudo chmod 666 /dev/ttyUSB0(replace with your port) - No data received: Check connections and ensure the sketch is uploaded correctly




