FocusSense Room-monitoring Device
by Maxime_M in Circuits > Raspberry Pi
37 Views, 0 Favorites, 0 Comments
FocusSense Room-monitoring Device
I built FocusSense, an intelligent room-monitoring and productivity assistant. The device tracks indoor environmental parameters in real time using a custom-built, laser-cut wooden multiplex enclosure. It features an array of sensors to measure temperature, humidity, CO₂ levels, and ambient noise.
Supplies
Raspberry Pi 5 (4GB or 8GB) Description: Central processor of the system
Quantity: 1
Price: €88.95
RPi 5 Power Supply USB-C Description: Power supply for the RPi
Quantity: 1
Price: €19.41
Micro SD card (16GB) Description: To install the OS of the RPi and store your files
Quantity: 1
Price: €8.26
SCD40 CO2 Sensor Description: CO2 sensor for the project
Quantity: 1
Price: €18.25
AHT20 Temperature & Humidity Sensor Description: Sensor that measures the temperature & air humidity
Quantity: 1
Price: €5.50
KY-037 Sound Sensor Description: Sensor that measures the sound in the room
Quantity: 1
Price: €4.99
WS2812B LED ring (16 RGB LEDs) Description: An LED ring to display the status of the sensors or to show the timer
Quantity: 1
Price: €5.00
0.96 inch OLED Display (128*64, I2C) Description: Display to show the IP address & other matters
Quantity: 1
Price: €4.75
T-Cobbler for Raspberry Pi Description: Needed to connect the GPIO pins of the RPi to a breadboard
Quantity: 1
Price: €6.50
Vibration Motor Description: Actuator: Physical feedback (vibration) for timer or warning
Quantity: 1
Price: €3.00
PBS-110 Push Buttons Description: Push buttons to control the display & to be able to shut down the Pi
Quantity: 2
Price: €1.00
MCP 3002 Description: Analog-to-Digital converter to read the analog signal of the KY-037 on the Pi
Quantity: 1
Price: €2.50
Total Cost: €168.11
Tools & Consumables:
- Soldering iron and leaded or lead-free solder (leaded is easier to use for beginners).
- Jumper wires (Male-to-Female, Male-to-Male)
- Breadboard
- Laser cutter access (to create the box, or you can make something yourself).
- nylon (polyamide) M2 & M2.5 nuts & bolts to mount components (in case you use my box design)
Software:
- Visual Studio code: Used as the primary IDE for Python development.
- mySQL workbench: Used to design and manage your project database.
- Raspberry Pi Imager: Used to flash the Raspberry Pi OS onto your MicroSD card.
- Adobe Illustrator: Used to design the laser-cut files for your wooden multiplex enclosure (you can use another app, but I used Adobe Illustrator so I don't know which other ones work. the important part is your file needs to be compatible with your laser cutter software)
Flash the Operating System
- Insert the MicroSD card into your PC using a card reader.
- Open the Raspberry Pi Imager application you installed.
- Select Device: Choose "Raspberry Pi 5".
- Select OS: Scroll to the bottom of the list, choose "Use custom", and select your own .img file.
- Select Storage: Choose your MicroSD card.
- Configure Settings (Crucial): Click "Next" when asked about OS customization. Set these now (if the option is available for your custom image):
- Set a Hostname.
- Set a Username and Password (used to log into SSH)
- Configure Wi-Fi: Enter your SSID (WiFi name) and password so it connects automatically.
- Enable SSH: Check this box so you can control the Pi from your laptop via terminal (without needing a monitor/keyboard).
- Write: Click "Write" and let it finish.
- Once that is done:
- Insert the card into the Raspberry Pi 5, plug in the power supply, and wait for it to boot. You now have a working computer. That is the barrier to entry. Everything else starts from here.
Download link for the .img file: https://mega.nz/file/wvAQ3ZzR#CEwuOFvDpN77a2Rol3WgNu2yA_S0wVngmnGDNxbBlYs
Wiring & Prototyping
Before fitting components into the final enclosure, assemble the circuit on a breadboard. Prototyping allows you to verify sensor communication and pin configuration.
Your wiring diagram is divided into three main connection types. Use the provided T-Cobbler to extend the Raspberry Pi GPIO pins to your breadboard:
- I2C Bus (SCD40, AHT20, OLED): These components share the I2C bus. They all connect to the same 3.3V power, GND, SDA (GPIO 2), and SCL (GPIO 3) lines.
- SPI Bus & Analog Conversion (MCP3002 ADC & KY-037): * Connect the MCP3002 ADC chip to the Raspberry Pi's hardware SPI pins: MOSI (GPIO 10), MISO (GPIO 9), CLK (GPIO 11), and CS (GPIO 8 / CE0).
- Provide 3.3V power and GND to the MCP3002 chip.
- Connect the Analog Output (AO) pin of the KY-037 Sound Sensor to Channel 0 (CH0) of the MCP3002. (The KY-037 also needs its own VCC and GND connections).
- Direct GPIO (LED Ring, Buttons, Motor):
- WS2812B LED Ring: Connected to GPIO 18 (PWM).
- Push Buttons: Connected to GPIO 19 (IP display toggle) and GPIO 16 (Shutdown/Snooze button). Both use internal pull-up resistors configured in the code.
- Vibration Motor: Connected to GPIO 21.
Important Notes:
- Power Rails: Double-check your connections to the 3.3V vs. 5V pins on the Pi. Miswiring power to your sensors can permanently damage them. Ensure the WS2812B LED ring gets its required 5V power, while the delicate I2C sensors run on 3.3V.
- Common Ground: Ensure all components share a common ground (GND) connection back to the Raspberry Pi to prevent signal noise, especially for the analog sound readings.
- Test as you go: Once you have the I2C devices wired, run an i2cdetect -y 1 command in the terminal to verify the Pi "sees" the SCD40, AHT20, and OLED at their respective addresses before adding the SPI and GPIO components.
Downloads
Boot Up and Test the Prototype
Because you used the custom .img file from Step 0, this project is configured to run completely automatically. The MySQL database, the Python backend, and the web server are set up as background services. They will launch the moment the Raspberry Pi gets power. You do not need to install anything or type any commands to start the code.
1. Power on the Hardware Plug the power supply into your Raspberry Pi. Wait about 60 to 90 seconds for the system to boot up and for your services to start in the background.
2. Verify the Hardware Look at your breadboard. The OLED display should automatically turn on and show the project title along with live Temperature, Humidity, and CO₂ readings. Pro-tip: Blow on the SCD40 sensor to see the CO₂ values update instantly on the screen!
3. Check the Web Dashboard Make sure your computer or smartphone is connected to the same Wi-Fi network as your Raspberry Pi. Open a web browser and type in the IP address of your Raspberry Pi (for example: http://192.168.168.169). Do not add any ports or extra text at the end. The live dashboard will load automatically.
(Note: If you do not know your Raspberry Pi's IP address, Click the button connected to GPIO 19. this will show the IP addrers on the OLED-display for a short time)
4. Safely Shut Down If the screen lights up and the dashboard shows data, your circuit is perfect! Press the physical push button you wired to GPIO 16 to safely shut down the Pi (or SSH into it and type sudo poweroff). Once the green light on the Pi stops blinking, unplug the power and get ready to mount everything into the final case.
Laser Cutting & Enclosure Assembly
With your circuit fully tested and working, it is time to move the hardware into the permanent wooden housing. This step covers cutting the multiplex panels and mounting the hardware components exactly as designed.
1. Laser Cutting the Casing Download the provided design files (attached below) and use a laser cutter to cut the panels out of multiplex wood.
- Clean any laser-charcoal residue from the edges of your cut sheets using a lightly damp cloth or fine sandpaper.
- Test-fit the interlocking panels together to ensure everything aligns perfectly. The main case is designed to hold together without wood glue.
2. Mounting the Hardware Use the plastic bolts and nuts to secure the exposed components. Plastic hardware is used specifically to prevent shorting out the electronics.
- Front Panel (The Brain & Display): Mount the Raspberry Pi 5, the 0.96-inch OLED display, and the WS2812B LED ring directly to their designated cutouts on the front panel using the plastic bolts and nuts.
- Top Panel (Buttons): Mount the two physical push buttons through the circular holes on the top panel, securing them from the inside with their included hex nuts.
- Vibration Motor: Use a small dab of hot glue to firmly secure the vibration motor to the inside wall of the casing. Gluing it down ensures the haptic feedback transfers strongly through the wooden frame when the alarm goes off.
3. Internal Wiring & Closing the Case
- Loose Components: The rest of the hardware—the breadboard, SCD40, AHT20, MCP3002 ADC, and KY-037 sound sensor—are designed to sit loose inside the bottom of the enclosure.
- Carefully tuck the wiring inside the box. Make sure the loose SCD40 sensor is positioned near the ventilation cutouts so it gets adequate airflow for accurate CO₂ readings.
- Slide the final outer panels together to close the housing, ensuring you don't pinch any of the loose jumper wires in the seams, and leaving the cutout for the Raspberry Pi's USB-C power port completely clear.
Note: This file was made for multiplex that is 4 mm thick, if you use material that is not 4 mm, the final box will not fit together properly.
Downloads
Using Your Focus Device
Now that your project is fully assembled, here is how the system actually works in your day-to-day life. The device operates in different "states" depending on your room's air quality and what you configure on the web dashboard.
1. The Web Dashboard
- Open your browser and go to your device's IP address.
- From the frontend dashboard, you can view your historical data graphs, start a focus timer, and select which specific sensor you want to visualize on the physical LED ring.
2. The OLED Display & IP Button
- Default Mode: The screen acts as your main readout, showing the live Temperature, Humidity, and CO₂ levels.
- Override Mode: If the air quality drops to a warning/alarm level, or if you start a timer, the screen will automatically switch to display that critical alert or countdown instead of the standard readings.
- Find My IP: If you ever forget the device's IP address, just press the Secondary Button (GPIO 19) and the IP will temporarily flash on the OLED screen.
3. The LED Ring & Snoozing
- The WS2812B LED ring physically represents the data from whichever sensor you currently have selected on the web dashboard.
- Warning (Yellow): If the environment hits your custom warning threshold, the ring turns yellow. You can temporarily silence this by pressing the Main Power Button (GPIO 16) to "snooze" the warning.
- Alarm (Red): If levels reach the critical alarm threshold, the ring turns red. This means your focus and health are being impacted—you cannot snooze a red alarm! You must physically open a window or fix the environment to clear it.
4. The Focus Timer & Vibration Motor
- When you start a timer from the web interface, both the OLED and the LED ring will switch modes to show your remaining time progress.
- Once the timer hits exactly zero, the internal vibration motor kicks in. Because it is hot-glued to the inside wall, it transfers a strong, physical haptic buzz directly through the wooden casing to your desk to let you know your focus session is complete.
(Bonus): Accessing the MySQL Database
Because you are using the custom Raspberry Pi image, the MySQL database is already pre-installed, configured, and running seamlessly in the background. You do not need to set up anything for the device to work.
However, if you want to explore your raw sensor data, clear your history, or modify the database structure for your own upgrades, you can easily connect to it from your main computer.
How to connect:
- Download and install database client MySQL Workbench.
- Ensure your computer is on the same Wi-Fi network as your Raspberry Pi.
- Create a new connection with the following details:
- Hostname / IP Address: The IP address of your Raspberry Pi (e.g., 192.168.x.x).
- Port: 3306 (Default MySQL port).
- Username: root
- Password: S3crET
- Click Connect.
Once inside, look for the project1 database. Here you will find the History table (where all your sensor readings are logged) and the Config table (which stores your warning and alarm thresholds). If you ever want to completely reset your device's memory, simply run a TRUNCATE TABLE History; command to wipe the logs!