Build an ESP32 OBD-II CAN Bus Reader and Data Logger
ESP32 DevKitC development board
MCP2515 CAN bus module with TJA1050 transceiver
OBD-II to DB9 or pigtail cable
MicroSD card module (SPI)
MicroSD card 8-32GB
0.96 inch I2C OLED display
Project enclosure box
Dupont jumper wires
120 ohm resistor pack
USB car charger 5V 2A
Prices and availability as of Nov 28, 5:32 AM ET and subject to change. The price shown on Amazon at the time of purchase applies.
Every car built since 2008 (and most built since the mid-1990s) exposes a CAN bus through its OBD-II port, carrying far more data than the generic "check engine" codes a cheap Bluetooth scanner reads. Engine RPM, coolant temperature, throttle position, fuel trim, wheel speed, and dozens of other parameters are broadcast on that bus continuously, whether or not anything is listening. This project builds a standalone ESP32-based reader that taps into that stream, decodes the parameters you care about, logs them to a microSD card for later analysis, and shows live values on a small OLED screen — no phone, no subscription app, no cloud account. It's the same basic approach used by data-logging boxes sold for track days and tuning work, built from parts that together cost a fraction of a commercial unit.
Why an MCP2515 Instead of the ESP32's Built-In CAN Controller
Several ESP32 variants (including the plain ESP32 and the ESP32-S3) have a built-in TWAI (Two-Wire Automotive Interface) peripheral, which is Espressif's name for a CAN controller. In principle you could skip the MCP2515 module and wire a standalone CAN transceiver directly to the ESP32's TWAI pins. In practice, the MCP2515 module route is more forgiving for a first build: it's a complete, pre-wired board with its own crystal, its own transceiver, and a stable SPI interface that isolates CAN bus electrical noise from the ESP32's other peripherals. If you already have a TWAI-capable ESP32 and want to skip a part, the wiring and software differ enough that it's worth treating as a separate project rather than a drop-in substitution.
Understanding What You're Actually Listening To
OBD-II defines a standardized set of Parameter IDs (PIDs) for emissions-related data — Mode 01 PIDs like 0x0C (engine RPM) and 0x05 (coolant temperature) are standardized across nearly every manufacturer. Beyond those, each manufacturer broadcasts huge amounts of proprietary data on the same bus for their own body control, transmission, and infotainment modules, using PIDs and scaling factors that are never officially published. This project focuses on the standardized Mode 01 PIDs, which work identically across makes and models, rather than reverse-engineering manufacturer-specific traffic (a worthwhile follow-up project, but a much deeper rabbit hole).
| PID (hex) | Parameter | Formula | Units |
|---|---|---|---|
| 0x0C | Engine RPM | ((A*256)+B)/4 | RPM |
| 0x0D | Vehicle speed | A | km/h |
| 0x05 | Coolant temperature | A-40 | °C |
| 0x11 | Throttle position | A*100/255 | % |
| 0x0F | Intake air temperature | A-40 | °C |
| 0x06 | Short term fuel trim | (A-128)*100/128 | % |
| 0x2F | Fuel tank level | A*100/255 | % |
Step 1: Wire the MCP2515 Module to the ESP32
The MCP2515 communicates over SPI. Wire it as follows, using the ESP32 DevKitC's default VSPI pins:
- MCP2515 VCC → ESP32 5V (most MCP2515 breakout boards have an onboard 5V-to-3.3V regulator for the MCP2515 chip itself, but check your specific board — some require 5V on VCC and use 3.3V-tolerant SPI logic, others want 3.3V directly)
- MCP2515 GND → ESP32 GND
- MCP2515 CS → ESP32 GPIO5
- MCP2515 SO (MISO) → ESP32 GPIO19
- MCP2515 SI (MOSI) → ESP32 GPIO23
- MCP2515 SCK → ESP32 GPIO18
- MCP2515 INT → ESP32 GPIO4
Most MCP2515 breakout modules already include the 120 ohm termination resistor across CAN-H/CAN-L. If yours doesn't, add one — OBD-II buses are already terminated at both ends inside the vehicle, so an unterminated tap generally still works, but a mismatched impedance on a long lead can cause intermittent read errors.
Step 2: Wire the OBD-II Connector
On the standard 16-pin OBD-II connector, the pins you need are:
- Pin 6: CAN-H → MCP2515 CAN-H
- Pin 14: CAN-L → MCP2515 CAN-L
- Pin 16: Battery +12V (switched or constant, depending on the cable) → a separate 12V-to-5V buck converter or USB car charger module, not directly to the ESP32
- Pin 4/5: Chassis/signal ground → common ground with the ESP32 and MCP2515
Never feed the OBD port's 12V rail directly into the ESP32's 5V pin. Use a proper buck converter or a cheap USB car charger module gutted for its regulator board — automotive 12V rails see significant voltage spikes during cranking and alternator load dumps that a dedicated automotive-rated regulator is designed to survive.
Step 3: Flash the Firmware
Using the Arduino IDE with the autowp-mcp2515 and Adafruit SSD1306 libraries installed, the core loop does three things every cycle: requests a PID over CAN, waits for the response frame, and decodes it using the formulas above. A minimal request frame for engine RPM looks like this:
// Standard OBD-II request, ID 0x7DF, Mode 01, PID 0x0C (RPM) struct can_frame request; request.can_id = 0x7DF; request.can_dlc = 8; request.data[0] = 0x02; // 2 additional data bytes follow request.data[1] = 0x01; // Mode 01 (show current data) request.data[2] = 0x0C; // PID: engine RPM request.data[3] = 0x00; request.data[4] = 0x00; request.data[5] = 0x00; request.data[6] = 0x00; request.data[7] = 0x00; mcp2515.sendMessage(&request);
The ECU responds on ID 0x7E8 with the requested value in bytes A and B of the payload. Poll each PID on a rotation (RPM and speed at higher priority/frequency, coolant temp and fuel trim less often) rather than requesting everything every loop iteration — flooding the bus with requests can cause some ECUs to throttle or ignore additional queries.
Step 4: Log to microSD and Display Live Values
Write each decoded sample to a CSV file on the SD card with a timestamp, using the ESP32's internal millis() counter since you won't have reliable wall-clock time without adding a GPS or NTP source. A typical log line looks like 12453,2341,62,89,14.2 (ms since boot, RPM, speed, coolant temp, throttle %). Buffer writes in RAM and flush every second or two rather than opening and closing the file every loop iteration; SD card writes are slow relative to CAN polling and will create gaps in your data if done naively on every sample. The OLED display can cycle through 3-4 values per screen, refreshing every 250-500ms, which is fast enough to be useful without visibly lagging.
Safety Notes
Tapping a live vehicle CAN bus is generally safe for passive listening and standard OBD-II PID requests — this is exactly what every commercial OBD scanner does. That said, keep a few things in mind:
- Never transmit arbitrary or malformed CAN frames onto a vehicle bus, and never experiment with anything beyond standard Mode 01 PID requests while the engine is running or the vehicle is in motion. Some manufacturer-specific CAN IDs control actuators, and an unintended frame on the wrong ID has, in rare documented cases, triggered unexpected behavior in body control or transmission modules.
- Mount the enclosure somewhere it can't interfere with pedals, the steering column, or airbag modules, and secure the OBD cable so it won't get caught during a wheel movement or passenger entry.
- Don't leave undervoltage-sensitive electronics powered directly from the battery pin without a fuse inline; a short in your wiring is otherwise a direct short across the vehicle's battery.
Once the logger is running reliably, the next step is usually pulling the CSV off the SD card after a drive and graphing it in a spreadsheet or a tool like Python/pandas — RPM versus throttle position over a drive cycle makes shift points and part-throttle behavior obvious in a way that watching a live gauge never does.