Project 3.1.34: Zone Occupancy Dashboard
Advanced Embedded Systems Project Using Raspberry Pi Pico 2 W and MicroPython
Overview
The Pico reads one PIR sensor and shows the current occupancy state on a local OLED dashboard.
Shared spaces are easier to manage when users can see when motion is detected instead of guessing whether an area is active.
A Pico 2 W prototype with one PIR sensor and an OLED that acts as a local occupancy dashboard.
Motion sensing, simple occupancy logic, and honest explanation of what a local dashboard prototype can claim.
Required Components
![]() Raspberry Pi Pico 2 W |
![]() Motion sensor |
![]() Breadboard |
![]() Jumper wires |
![]() OlED |
Circuit Connections
| Component terminal | Connect to | Pico physical pin | Notes |
|---|---|---|---|
| PIR OUT | GPIO 14 | GPIO 14 / physical pin 19 | Motion input |
| PIR VCC | VBUS or module-rated supply | Physical pin 40 if 5V is required | Check your module label |
| PIR GND | GND | Physical pin 38 | Common ground |
| OLED VCC | 3.3V output | Physical pin 36 | Display power |
| OLED GND | GND | Physical pin 38 | Common ground |
| OLED SDA | GPIO 20 | GPIO 20 / physical pin 26 | I2C0 SDA |
| OLED SCL | GPIO 21 | GPIO 21 / physical pin 27 | I2C0 SCL |
Wiring Diagram

PIR OUT -> GPIO 14
GPIO 20 -> OLED SDA
GPIO 21 -> OLED SCL
Common GND -> PIR and OLED
Step-by-Step Assembly
- Connect the PIR sensor output to GPIO 14.
- Connect the PIR power and ground rails and allow the sensor to warm up before validation.
- Connect the OLED to Pico 3.3V, GND, GPIO 20, and GPIO 21.
- Upload ssd1306.py and confirm that the library appears in the Pico file list.
- Aim the PIR at the area you want to monitor and check for blind spots.
Testing Individual Components
Before running the full project, test each subsystem separately. This makes it easier to find wiring, library, or logic problems before full integration.
- Hardware setup: Assemble the Pico, sensor, indicator, and load wiring exactly as shown in the connection table before applying power.
- Test the input sensor: Print the PIR state and walk through the monitored area to confirm the mapping is correct.
- Test the output device: Run a short OLED test so the display path is known to work before you add occupancy data.
- Test the decision logic: Confirm that the occupancy label changes between IDLE and OCCUPIED when motion is detected.
- Run the full system: Run the dashboard while moving through the monitored area and compare the serial output with the OLED view.
- Validate the prototype: Check whether the PIR field of view creates blind spots or false triggers.
- Save the project: Save the validated program on the Pico as main.py and keep a copy on the computer for future edits.
Full Project Code
After completing and checking the circuit connections, open Thonny IDE, copy and paste this code into a new file or upload the project file to the Raspberry Pi Pico 2 W, then run it from Thonny.
from machine import I2C, Pin
import time
try:
from ssd1306 import SSD1306_I2C
HAS_OLED = True
except ImportError:
HAS_OLED = False
PIR_PIN = 14
I2C_SDA_PIN = 20
I2C_SCL_PIN = 21
pir = Pin(PIR_PIN, Pin.IN, Pin.PULL_DOWN)
i2c = I2C(0, sda=Pin(I2C_SDA_PIN), scl=Pin(I2C_SCL_PIN), freq=400000)
if HAS_OLED:
oled = SSD1306_I2C(128, 64, i2c)
def occupancy_label(motion_detected):
return "OCCUPIED" if motion_detected else "IDLE"
print("Zone occupancy dashboard ready")
while True:
motion_detected = pir.value()
label = occupancy_label(motion_detected)
print("Motion:{} Label:{}".format(motion_detected, label))
if HAS_OLED:
oled.fill(0)
oled.text("Zone Dashboard", 0, 0)
oled.text("Motion:{}".format(motion_detected), 0, 20)
oled.text(label, 0, 40)
oled.show()
time.sleep(1)
How the Code Works
| Code Section | What It Does | Why It Matters | What to Modify During Testing |
|---|---|---|---|
| Motion-sensor setup | Initializes one PIR input and the optional OLED display | A simple input map makes the prototype easy to build and test | Confirm the PIR is mapped to GPIO 14 before changing the dashboard logic |
| occupancy_label | Turns the PIR reading into an IDLE or OCCUPIED label | A clear label is easier to read than a raw digital value | Change the label logic if your real use case needs different states |
| Main loop | Reads the PIR state and prints the current occupancy label | Students can see how a motion input drives a local dashboard | Keep the update interval slow enough that the OLED remains readable |
| OLED update | Displays motion activity and the local occupancy label | This demonstrates a dashboard without overclaiming headcount accuracy | If the display is blank, verify ssd1306.py and the I2C wiring before changing the code |
Expected Result
The serial monitor reports the current reading or state clearly.
The hardware output responds when the decision logic changes state.
Subsystem behavior matches the thresholds, timing, or rules described in the document.
Validation Checks
- Normal condition test: confirm the system stays in its safe or idle state under baseline conditions
- Warning condition test: move the input close to the chosen threshold and confirm the transition is sensible
- Critical condition test: trigger the strongest alert or control state and confirm the output response is correct
- Calibration test: compare the sensor or timing against a known reference or repeated trial
- Limitation test: deliberately create an awkward or noisy condition and note how the prototype behaves
Deployment and Limitations
- This prototype works well for classroom demonstrations and local monitoring pilots
- Before deployment, it needs calibration records, protective mounting, and regular validation checks
- Display-only systems still depend on correct sensor placement and trained users
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| Motion is never detected | The PIR sensor is wired wrong or aimed badly | Test the PIR by itself and confirm its output pin wiring |
| Occupancy changes unexpectedly | The PIR is aimed at passing traffic or heat sources | Reposition the sensor and allow it to warm up before testing |
| OLED is blank | I2C wiring or library file is missing | Use GPIO 20 and GPIO 21 and confirm that ssd1306.py is on the Pico |
| The dashboard stays occupied | PIR warm-up or room layout is causing false triggers | Wait for warm-up and test the monitored area in isolation |




