The NEC 110.26 breaker panel clearance code mandates a strict 36-inch deep, 30-inch wide, and 6.5-foot high clear working space in front of your electrical panel. In cluttered basements or garages, it is easy to accidentally stack boxes or build shelving that violates this boundary, creating a severe safety hazard for anyone troubleshooting a tripped breaker. To automate compliance monitoring, you can build an ESP32-based ultrasonic distance sensor that triggers a local OLED alert the moment an object breaches a 38-inch threshold (allowing a 2-inch buffer for sensor cone spread). This guide provides the exact hardware, pinout, and C++ code to build this monitor, while breaking down the specific NEC rules you need to know to pass an inspection.
The NEC 110.26 Standard & Project Overview
Before we wire the sensor, you need to understand the exact dimensions the National Electrical Code (NEC) requires for working space. According to NEC 110.26(A), the clearance is defined in three dimensions:
- Depth: For standard residential 120/240V systems (0-150V to ground), Table 110.26(A)(1) requires a minimum depth of 36 inches (3 feet). This is measured from the exposed live parts of the panel (or the front of the panel if the cover is on) straight out into the room.
- Width: NEC 110.26(A)(2) dictates the width must be at least 30 inches, or the width of the equipment itself, whichever is greater. This space must be centered on the panel.
- Height: NEC 110.26(A)(3) requires the space to be clear from the floor up to 6.5 feet (or the height of the equipment if it is taller).
Hardware Spec Sheet & Pin Mapping
This build targets the ESP32-WROOM-32 DevKit v1 (30-pin variant). We are using the HC-SR04 ultrasonic sensor because it offers reliable 2cm to 400cm ranging, which perfectly covers our 36-inch (91.4cm) threshold. However, the HC-SR04 Echo pin outputs 5V logic, which will fry the 3.3V-tolerant GPIOs on the ESP32. A voltage divider is mandatory.
| Component | Exact Variant / Model | Quantity | Notes |
|---|---|---|---|
| Microcontroller | ESP32-WROOM-32 DevKit v1 (30-pin) | 1 | Must be the 30-pin layout for standard pinouts |
| Distance Sensor | HC-SR04 Ultrasonic Module | 1 | 5V VCC, requires logic level shifting on Echo |
| Display | SSD1306 0.96" I2C OLED (128x64) | 1 | 4-pin I2C variant (VCC, GND, SCL, SDA) |
| Resistors | 1kΩ and 2kΩ (1/4W) | 1 each | For 5V to 3.3V voltage divider on Echo pin |
| Power | 5V 2A USB Micro-B Supply | 1 | HC-SR04 draws peak current during ping; do not use PC USB |
ESP32 Pin Mapping Table
| Module Pin | ESP32 GPIO | Wiring Notes |
|---|---|---|
| HC-SR04 VCC | VIN (5V) | Requires stable 5V; do not use 3V3 pin |
| HC-SR04 GND | GND | Common ground with ESP32 and OLED |
| HC-SR04 Trig | GPIO 25 | Direct connection (3.3V output triggers 5V sensor fine) |
| HC-SR04 Echo | GPIO 27 | VIA VOLTAGE DIVIDER: 1kΩ from Echo to GPIO 27, 2kΩ from GPIO 27 to GND |
| OLED VCC | 3V3 | SSD1306 runs natively on 3.3V |
| OLED GND | GND | Common ground |
| OLED SCL | GPIO 22 | Default I2C SCL for ESP32 |
| OLED SDA | GPIO 21 | Default I2C SDA for ESP32 |
Step-by-Step Assembly & Compilable Code
- Build the Voltage Divider: Solder the 1kΩ resistor to the HC-SR04 Echo pin. Connect the other end of the 1kΩ resistor to GPIO 27. Solder the 2kΩ resistor between GPIO 27 and GND. Verify with a multimeter that the resistance ratio is correct before applying power.
- Mount the Sensor: Secure the HC-SR04 to a wooden stud or drywall anchor exactly 38 inches away from the front face of the breaker panel. Ensure the sensor is at least 4 feet off the ground to avoid detecting baseboards or floor clutter.
- Wire the I2C OLED: Connect the SSD1306 display to GPIO 21 (SDA) and GPIO 22 (SCL). Ensure you are using the 3.3V pin for power.
- Flash the Firmware: Install the
Adafruit_SSD1306andAdafruit_GFXlibraries via the Arduino IDE Library Manager. Select "ESP32 Dev Module" as your board, copy the code below, and flash.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// --- PIN DEFINITIONS ---
#define TRIG_PIN 25
#define ECHO_PIN 27
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C
// --- THRESHOLDS ---
// NEC 110.26 requires 36" (91.44cm). We set warning at 38" (96.52cm).
#define CLEARANCE_THRESHOLD_CM 96.5
#define TIMEOUT_US 30000 // 30ms timeout for pulseIn
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
Serial.begin(115200);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
digitalWrite(TRIG_PIN, LOW);
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("[FAULT] SSD1306 allocation failed"));
for(;;); // Halt if display fails
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0);
display.println("NEC 110.26 Monitor");
display.println("Initializing...");
display.display();
delay(1000);
}
void loop() {
// Trigger ultrasonic ping
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
// Read echo with strict timeout to prevent hanging
unsigned long duration = pulseIn(ECHO_PIN, HIGH, TIMEOUT_US);
display.clearDisplay();
display.setCursor(0,0);
display.println("Panel Clearance Mon");
display.drawLine(0, 10, 128, 10, SSD1306_WHITE);
if (duration == 0) {
// Error Handling: Timeout or stuck pin
Serial.println("[FAULT] ECHO_TIMEOUT: Pin 27 stuck HIGH > 30ms");
display.setCursor(0, 20);
display.setTextSize(1);
display.println("ERROR: Sensor Timeout");
display.println("Check voltage divider");
display.println("and 5V rail stability.");
} else {
float distance_cm = (duration * 0.0343) / 2.0;
float distance_in = distance_cm / 2.54;
display.setCursor(0, 20);
display.setTextSize(2);
display.print(distance_in, 1);
display.println(" in");
display.setTextSize(1);
display.setCursor(0, 50);
if (distance_cm < CLEARANCE_THRESHOLD_CM) {
display.println("WARNING: CODE VIOLATION");
Serial.printf("[ALERT] Clearance violated: %.2f inches (Limit: 36 in)\n", distance_in);
} else {
display.println("STATUS: NEC Compliant");
}
}
display.display();
delay(500); // 2Hz polling rate
}
Debugging: First Three Checks & Timeout Errors
If your serial monitor outputs the exact string [FAULT] ECHO_TIMEOUT: Pin 27 stuck HIGH > 30ms, the ESP32's pulseIn() function hit the 30-millisecond timeout without seeing the Echo pin drop back to LOW. This is the most common failure mode for 5V sensors on 3.3V microcontrollers. Here are the first three things to check, ranked by probability:
- Voltage Divider Integrity (Most Likely): The Echo pin is outputting 5V. If your 2kΩ pull-down resistor is missing, loose, or the wrong value, the 5V signal will backfeed into GPIO 27, triggering the ESP32's internal protection diodes and holding the pin HIGH. Disconnect the Echo wire, power the ESP32, and measure the voltage at the junction of the 1kΩ and 2kΩ resistors while the sensor is pinging. It must read between 3.2V and 3.4V.
- 5V Rail Sag: The HC-SR04 draws a spike of current when the ultrasonic transducers fire. If you are powering the ESP32 from a weak PC USB port (limited to 500mA), the 5V VIN rail will sag below 4.5V, causing the sensor's internal comparator to lock up. Use a dedicated 5V 2A wall adapter.
- Acoustic Multipath Reflection: If the sensor is mounted near metallic EMT conduit or a wire gutter, the 15-degree ultrasonic cone might be bouncing off the pipe and returning a chaotic, stretched echo that exceeds the timeout window. Cup your hand around the sensor to narrow the beam; if the error stops, you need to 3D-print a shroud for the transducers.
Extending and Simplifying the Build
Depending on your deployment environment, you may want to modify this base design.
- How to Extend (Home Assistant Integration): To log code violations over time, add the
PubSubClientlibrary and configure the ESP32 to publish thedistance_infloat to an MQTT broker (e.g., Mosquitto) on topichome/sensors/panel_clearance. You can then create an automation in Home Assistant that sends a push notification to your phone if the distance drops below 36 inches for more than 5 minutes. - How to Simplify (Headless Mode): If the panel is in a dark, finished utility closet where an OLED display is useless, strip out the
Wire.handAdafruit_SSD1306libraries. Rely entirely on the Serial output or add a simple 5mm Red LED to GPIO 26 that illuminates when thedistance_cm < CLEARANCE_THRESHOLD_CMcondition is met. This reduces power draw and frees up I2C pins for other sensors.
FAQ: Breaker Panel Clearance Code Questions
What is the exact breaker panel clearance code for residential spaces?
For standard residential 120/240V split-phase systems, NEC 110.26(A) requires a clear working space that is at least 36 inches deep, 30 inches wide (or the width of the panel, whichever is greater), and 6.5 feet high. The space must be kept entirely clear of storage, shelving, and permanent fixtures. This applies to both main service panels and interior subpanels.
Does the breaker panel clearance code apply to the space above the panel?
Yes. NEC 110.26(A)(3) mandates that the working space must extend from the floor (or grade) up to a height of 6.5 feet (2.0 meters), or the height of the equipment if the panel is taller than 6.5 feet. You cannot run HVAC ductwork, plumbing pipes, or mount storage shelves directly above the panel within this 30-inch wide column, even if those objects are flush with the ceiling.
Can I install a shelf or storage rack outside the breaker panel clearance code zone?
Yes, provided it does not encroach on the 30-inch width or 36-inch depth boundaries. However, NEC 110.26(B) also requires that the working space provide "sufficient access and egress." If your shelving unit forces an electrician to squeeze sideways or step over obstacles to reach the 30-inch wide clearance zone, an inspector can still fail the installation for blocking the path of egress. Always leave a clear, unobstructed walking path to the panel.
How do I measure the breaker panel clearance code width if my panel is in a corner?
The 30-inch width must be centered on the panel. If your panel is mounted in a corner where a full 30-inch centered width is physically impossible (e.g., only 10 inches of wall space on the left side), the NEC requires the space to be measured from the nearest edge of the panel outward to complete the 30-inch total width. However, local Authority Having Jurisdiction (AHJ) inspectors are notoriously strict about corner-mounted panels; many will require the panel to be relocated to ensure the 30-inch zone is fully symmetrical and unobstructed by the adjacent wall.






