PosturePulse
by Nischeith Ravindra Boddapati in Circuits > Raspberry Pi
33 Views, 0 Favorites, 0 Comments
PosturePulse
PosturePulse is an AI-powered posture monitoring system designed to help users maintain healthy sitting habits. Using a Raspberry Pi, camera, and computer vision model, the system detects different sitting postures in real time and provides feedback when poor posture is identified. It also records posture data, tracks monitoring sessions, and displays statistics through an interactive dashboard. The goal of PosturePulse is to promote better posture awareness and reduce the risk of discomfort and long-term health issues caused by prolonged poor sitting posture.
Supplies
HARDWARE:
- Raspberry Pi 5
- Raspberry Pi 5 Power Adapter
- Logitech C270 USB Webcam
- HC-SR04 Ultrasonic Distance Sensor
- 16×2 LCD Display with I2C Interface
- Push Button
- Active Buzzer
- Jumper Wires
- RBG led
Preparing the RaspberryPi
What You Need
- Raspberry Pi 5
- MicroSD Card (32 GB or larger recommended)
- Power Supply
- Internet Connection
- Computer for remote access
Step 1: Install Raspberry Pi OS
Open Raspberry Pi Imager on your computer and insert the microSD card. Select your Raspberry Pi model and choose Raspberry Pi OS Lite (64-bit) as the operating system.
Step 2: Configuring the Pi
Before writing the operating system to the microSD card, configure the Raspberry Pi settings. Set a hostname, username, password, and enable SSH so that the Raspberry Pi can be accessed remotely.
Once the configuration is complete, write the operating system to the microSD card.
Step 3: Boot the Raspberry Pi
Insert the microSD card into the Raspberry Pi and connect the power supply. Allow the device to boot and connect to the network.
Step 4: Connecting via SSH
Using a computer on the same network, connect to the Raspberry Pi through SSH. This allows the system to be configured and managed remotely without requiring a separate monitor, keyboard, or mouse.
Step 5: Update the System
After connecting successfully, update the operating system and installed packages using the following commands:
sudo apt update
sudo apt upgrade -y
Step 6: Install Project Dependencies
Install all required software packages and Python libraries needed for PosturePulse, including OpenCV, FastAPI, Gradio, SQLModel, PostgreSQL , and Raspberry Pi GPIO libraries.
Once these steps are completed, the Raspberry Pi is ready for hardware integration and software development.
Collecting Dataset
To train the posture detection model, a custom dataset was collected containing images of different sitting postures. Since the goal of PosturePulse is to monitor users while they are working at a desk, the images were captured from a side-view perspective to closely match the final system setup.
During the early stages of the project, a front-view dataset was considered. However, after further evaluation, the project was redesigned to use side-view posture detection because it provides a clearer representation of a user's sitting posture and better reflects real-world usage.
The dataset was created by capturing images of different posture variations, including both good and bad postures.
1. Good Posture
- The user sits upright with their back straight and shoulders aligned.
- This posture represents the recommended sitting position.
2. Slouching
- The user leans forward with a rounded upper back and shoulders.
- This posture can increase strain on the neck and spine.
3. Leaning Forward
- The user bends their upper body excessively toward the desk or screen.
- This often occurs when focusing closely on a monitor.
4. Leaning Backward
- The user reclines too far backward, reducing proper ergonomic support.
- This posture can affect balance and sitting stability.
5. Looking Down
- The user's head and neck are tilted downward for an extended period.
- This posture may contribute to neck discomfort and poor spinal alignment.
6. Looking Up
- The user's head is tilted upward beyond a neutral position.
- This posture can place unnecessary strain on the neck muscles.
Extracting Keypoints and Training the Model
After collecting the dataset, the next step was to extract body keypoints from each image. For this, I used the MediaPipe Pose Landmarker, which detects important body landmarks such as the head, shoulders, and hips.
The extracted landmark coordinates were then processed through feature engineering. Additional features were created from the keypoints to better represent body posture and improve the model's ability to distinguish between different sitting positions.The extracted keypoints and engineered features were saved to a CSV file, which was then used for model training and evaluation.
Several classification algorithms were trained and evaluated using the engineered features. The performance of each model was compared based on classification accuracy and overall reliability. After testing multiple approaches, the Random Forest classifier achieved the best results and was selected as the final model.
Images → MediaPipe Pose Landmarker → Keypoint Extraction → Feature Engineering → CSV Dataset → Multiple Classifiers → Random Forest Selected
Creating Database
To store posture monitoring data, a PostgreSQL database was created. The database allows PosturePulse to keep track of monitoring sessions, posture classifications, and posture events generated during operation.
Three main tables were used:
Sessions
This table stores information about each monitoring session, including start time, end time, and session id.
Posture Events
This table records every detected posture event along with its confidence score, sensor presence and alert triggered.
Posture Classes
This table contains the available posture(6).
By storing this information in a database, PosturePulse can generate statistics, visualize posture trends, and provide users with a detailed session history through the dashboard.
Relationships
The database follows a relational structure:
- One Session can contain multiple Posture Events.
- One Posture Class can appear in multiple Posture Events.
- Each Posture Event belongs to exactly one Session and one Posture Class.
Designing PosturePulse
Before assembling the system, a housing was designed to safely contain all electronic components while keeping the device easy to use and maintain.
The enclosure consists of a rectangular MDF box with dimensions of 260 mm (width), 250 mm (depth), and 140 mm (height), using 4 mm thick MDF sheets. The design provides enough space for the Raspberry Pi, wiring, sensors, and other electronic components.
Front View
The front panel contains all user-facing components. A raised camera holder is positioned at the top to capture the user's posture from the side. The panel also includes an I2C LCD display for system information, a push button to enable or disable monitoring and turning off, an ultrasonic sensor for user presence detection, and an LED indicator for visual feedback.
Left View
The left side includes a ventilation opening to improve airflow inside the enclosure. A dedicated opening is also provided for the power cable connection.
Right View
The right side contains an additional ventilation opening to help prevent heat buildup during operation.
Construction Materials and Assembly
The enclosure can be manufactured using laser-cut MDF. The main structure is assembled using wood glue, while electronic components are mounted using screws where necessary.
- The I2C LCD display is mounted into the box.
- The ultrasonic sensor is mounted into the box.
- The push button and LED are fixed through dedicated cut-outs in the front panel.
- A custom camera holder is created using two MDF sections to elevate the camera above the main enclosure.
- Jumper wires are used to connect the Raspberry Pi to the ultrasonic sensor, LCD display, LED, and other electronic components.
- The buzzer is integrated into the electronics assembly and provides audio feedback during posture monitoring.
This enclosure provides a compact and organized structure that protects the electronics while ensuring all sensors and feedback components remain easily accessible.
Hardware Components
Ultrasonic Sensor (HC-SR04):
The ultrasonic sensor detects whether a user is present at the desk. It is used to automatically start and stop posture monitoring sessions.
I2C LCD Display
The LCD display provides information, such as monitoring status and detected posture.
Buzzer
The buzzer generates audio alerts whenever poor posture is detected, helping users correct their sitting position.
Push Button
The push button is used to enable or disable posture monitoring. A short press toggles the monitoring state, while holding the button for 3 seconds safely shuts down the Raspberry Pi.
RGB LED
The RGB LED provides visual feedback about the current system status:
- Blue – Waiting for a user to be detected.
- Green – Good posture detected.
- Red – Poor posture detected
Making the Makercase
MakerCaseMakerCase was used to design the enclosure for PosturePulse. It allowed the dimensions of the box to be specified and automatically generated laser-cut panels with finger joints for assembly. The generated design was then customized by adding cut-outs for the LCD display, ultrasonic sensor, push button, LED, ventilation slots, and power cable access. Using MakerCase simplified the enclosure design process and ensured that all components could be mounted securely inside the MDF housing.
MakerCase was used to generate the SVG files for the enclosure panels based on the required dimensions of the PosturePulse housing. The SVG files were then imported into Adobe Illustrator, where additional modifications were made, including cut-outs for the LCD display, ultrasonic sensor, push button, LED, and ventilation openings. Labels and graphics were also added for laser engraving. The final design files were used for both laser cutting and engraving the MDF enclosure components before assembly.
How the System Works
Workflow
- User presses the push button to enable monitoring.
- Ultrasonic sensor detects whether the user is sitting at the desk.
- A monitoring session automatically starts using ultrasonic sensor.
- USB webcam captures live video.
- MediaPipe extracts body landmarks.
- Trained AI model classifies posture as:
- Good Posture
- Leaning forward
- Slouching
- Looking down
- Looking up
- Leaning sideways
- Poor posture maintained for a period triggers an alert.
- Posture events are stored in PostgreSQL.
- Dashboard visualizes statistics and session history.
- Session ends automatically when the user leaves the desk.
User
↓
Ultrasonic Sensor
↓
Raspberry Pi
↓
Camera → AI Model
↓
Posture Detection
↓
FastAPI Backend
↓
PostgreSQL Database
↓
Gradio Dashboard
Developing the Gradio Interface
To make PosturePulse easy to use, a web-based user interface was developed using Gradio. The interface allows users to interact with the system, monitor their posture, and view collected data through a simple and intuitive dashboard.
The application consists of four main pages:
About and Onboarding
This page introduces the project and explains how the system works. It also provides setup instructions, hardware information, and guidance for first-time users.
Operating Page
The Operating page is used for posture monitoring. Users can view the live camera feed, monitor posture predictions, confidence scores, and session duration. The page also supports image uploads for posture analysis and displays real-time monitoring information.
Data Page
The Data page provides an overview of collected posture data. It displays statistics such as total sessions, monitoring time, posture distribution, alerts, and session history. Users can also inspect detailed information for individual monitoring sessions.
Debug Page
The Debug page was created to assist with system testing and troubleshooting during development. It provides access to diagnostic information from the hardware components and software services, making it easier to verify sensor readings, monitor system status, and identify potential issues while developing and testing PosturePulse.
By using Gradio, the system provides a user-friendly way to interact with the posture monitoring system without requiring users to access the underlying code or database directly.
Automation
To improve usability, PosturePulse was configured to start automatically whenever the Raspberry Pi is powered on. The required backend services, posture detection application, and Gradio interface launch during startup without requiring any manual intervention.
This automation transforms PosturePulse into a plug-and-play device. Users simply connect power, wait for the system to boot, and begin monitoring their posture without needing to access the terminal or run any commands.
Github
The GitHub repository contains all files required to recreate and understand the PosturePulse project. This includes the source code for the Raspberry Pi application, machine learning model training notebooks, Gradio user interface, FastAPI backend, database implementation, and hardware control scripts.