AI StudyFocus: Build a Focus Tracker With Computer Vision on a Raspberry Pi
by Max Drahomaretskyi in Circuits > Raspberry Pi
28 Views, 0 Favorites, 0 Comments
AI StudyFocus: Build a Focus Tracker With Computer Vision on a Raspberry Pi
AI StudyFocus is a real-time focus analysis system for students. It uses a USB webcam and a YOLO26 computer vision model to detect different study behaviours. The system transforms these detections into a focus score and shows live feedback in a Gradio app and on the custom-made laser cut box.
The prototype combines AI, software, hardware and a maker part. A Raspberry Pi runs the system and connects to a webcam, LCD display, RGB LED, buzzer, microphone, and start/stop session button. The Gradio dashboard shows the live camera input, AI detection result, focus score, warnings, data visualisation, and debugging tools.
I created this project because many students believe they are studying effectively, while in reality they may often be distracted by their phone, noise, pets or other habits. AI StudyFocus gives students an opportunity to reflect on their study sessions using live predictions, warnings, session statistics and focus graphs.
Supplies
Hardware
Raspberry Pi 5 + MicroSD card with Raspberry Pi OS
Power supply for Raspberry Pi
Freenove Project Board
USB webcam
Microphone / USB microphone / webcam microphone
Push button
Maker part
Plywood 4 mm thickness (preferably 450x600 mm)
2x Box Hinges (60x35 mm)
8 or 12x Screws (12 mm)
Strong wood glue
Laser cutter is preferred
Note: Freenove Project Board includes a lot of hardware parts, such as LCD display with I2C module, active buzzer, RGB LED, jumper wires and built-in pull-up-down resistors.
Total cost: ~186.33 €
Downloads
Prepare the Parts and Files
Before building, prepare:
- all hardware from the BOM
- Raspberry Pi OS on the microSD card
- the project code
- the trained YOLO model file
- the enclosure files
- the 3D print file for the camera holder
- the wiring diagram
Build the Enclosure
For my project I used both Laser cutting and 3D printing.
I used Laser cutting to create the actual enclosure, the box that will contain all the electronics.
- For that I used 4mm plywood and cut it according to the file I attached below.
- You need the wood glue to assemble each part firmly. After the glue has dried, check that none of the parts are loose.
- Now you need to check how the Project Board and all the electronics fit inside the enclosure. If something doesn't fit/holes too big/engraved text wrongly placed - then you may fix and recut it again.
- If everything is fine then the next step will be to screw the hinges to the back of the enclosure. This part is tricky and requires precision.
- If the lid opens and closes normally - congratulations! You have assembled the box.
I used 3D printing to create the camera holder that will be mounted in the cut-outs on the back of the enclosure.
- Use the .stl file attached below.
- Set infill to 25% gyroid
- Set wall count to 6
- Set support to Tree
- Print the part and remove the supports carefully.
Connect the Electronics
For this part you need these electronic parts:
- Raspberry Pi
- Freenove Project Board (LCD display, RGB LED, buzzer, 20 cm F-F Jumper wires are included)
- Webcam (preferably with microphone)
- Push button
- 4x 30 cm F-F Jumper wires (for LCD)
- 2x 30 cm M-F Jumper wires (for button)
Connect the components just like shown below:
- LCD I2C -> SDA, SCL, VCC, GND
- RGB LED -> GPIO pins + 3.3V
- Button -> GPIO pin + GND
- Microphone -> USB or audio input
- Webcam -> USB or camera connector
I chose those pins for them:
- LCD address: 0x27
- Button GPIO: 14
- Buzzer GPIO: 12
- RGB LED pins: 5, 6, 13
Assembling Everything Together
Follow these steps to complete the hardware part:
- Place the Project Board with pre-mounted Raspberry Pi inside the box
- Connect the button to GND and a GPIO pin
- Connect the LCD to corresponding pins
- Connect RGB LED to corresponding pins
- Pass the USB cable of the webcam through the cut-out in the back of the box and connect the webcam to RPi
- Mount the webcam on the stand and place the stand into the holder.
- Mount the holder into the special cut-outs on the back of the box (mount in left cut-outs if box will lay on the right of you and vice-versa)
- Connect Raspberry Pi to the power supply
Done. You have to end up with the same result as on the picture above.
Dataset and AI Model
I created my own dataset using a webcam in simulated study situations. I annotated the data in Roboflow.
Classes:
- focused
- looking_away
- phone
- phone_usage
- eyes_closed
- head_down
- yawning
- talking
*Note: phone_usage is a derived class. The system detects it when a phone is visible together with distracted behaviour such as looking away or head down.
The images were manually annotated with bounding boxes and exported in YOLO26 format.
After preparing the dataset, I trained a YOLO object detection model. The trained model file was saved as best.pt and used inside the Python application.
Backend and Database
The project uses a FastAPI backend and PostgreSQL database to store the study session data.
- FastAPI enables communication between the backend and the frontend.
- Database makes it possible to later view useful data, such as session history, hardware logs or detection events.
Gradio Frontend
The Gradio dashboard is the main user interface of the project.
User work flow in steps:
- User first lands on the About & Onboarding page. This page explains what the project does, how the system works, and what each detection class means.
- After reading the necessary information, the user can go to the Operating page.This page is used during a study session. A user now may start a study session, view live camera input, detected behaviour, their current focus score and possibly warnings that may occur while the study session.
- After ending the study session, the user can go to the Data page. This page shows saved session information. The information is shown in cards and graphs, which makes it easy to understand.
- The Gradio app also has a Debugging page. This page helps test hardware and system components and mainly used by the developer.
How to Test It Yourself
At this point you might want to test it yourself. If so, then follow these steps:
1. Clone the repository.
2. Start the backend.
3. Start the Gradio frontend.
4. Open the dashboard in the browser.
If running on Raspberry Pi from another device, use:
Final Result
After you have done all those steps, the full system is ready to use. You can start a study session, sit in front of the webcam and receive feedback through the dashboard or hardware components.
That's it! Have fun!