Secure checkout on Amazon.com.tr · Amazon delivery & returns Shop Arduino Products
∞arduinoforumBRING YOUR IDEAS TO LIFE. Find My Next Deal
ARDUINO GUIDE

MCP2515 Arduino CAN Bus Tutorial: Read OBD2 Data from Your Car

MCP2515 Arduino CAN Bus Tutorial: Read OBD2 Data from Your Car

Most modern cars share sensor data on a CAN bus, and the OBD2 diagnostic port gives you access to it. With an Arduino and an MCP2515 CAN bus module you can read engine RPM, speed and coolant temperature and build your own digital gauge or OBD2 display. This tutorial only reads standard diagnostic data — it does not change anything in the car.

What you need

  • An Arduino Uno or Nano
  • An MCP2515 CAN module (MCP2515 controller + TJA1050 transceiver, usually with an 8 MHz crystal)
  • An OBD2 breakout cable or connector
  • Optional: a 0.96″ I2C OLED display for a live gauge
  • For permanent installs: an automotive-rated 12 V to 5 V converter

Which cars work?

Cars that use the ISO 15765-4 (CAN) OBD2 protocol work with this method. Most cars built from around 2008 onwards use it, usually at 500 kbit/s (some use 250 kbit/s). Older cars may use K-Line or other protocols that the MCP2515 cannot read.

Wiring

MCP2515 module Arduino Uno / Nano
VCC 5V
GND GND
CS D10
SI (MOSI) D11
SO (MISO) D12
SCK D13
INT D2

On the OBD2 connector, pin 6 is CAN-High, pin 14 is CAN-Low, pins 4 and 5 are ground and pin 16 is +12 V battery. Connect CAN-H and CAN-L to the module’s H and L terminals and share ground.

Remove the 120 Ω termination jumper

The car’s CAN bus is already terminated. Most MCP2515 modules have a jumper (often labelled J1) that adds a 120 Ω terminator — remove it when you connect to a car.

Install the library

This example uses the arduino-mcp2515 library by autowp (install it as a ZIP from GitHub or through the Library Manager if listed). Other libraries such as MCP_CAN work the same way with different function names.

Example code: request RPM, speed and coolant temperature

#include <SPI.h>
#include <mcp2515.h>

MCP2515 mcp2515(10);           // CS pin
struct can_frame request, reply;

void askPid(byte pid) {
  request.can_id  = 0x7DF;     // OBD2 broadcast request
  request.can_dlc = 8;
  byte data[8] = {0x02, 0x01, pid, 0x55, 0x55, 0x55, 0x55, 0x55};
  memcpy(request.data, data, 8);
  mcp2515.sendMessage(&request);
}

void setup() {
  Serial.begin(115200);
  mcp2515.reset();
  mcp2515.setBitrate(CAN_500KBPS, MCP_8MHZ); // match your module's crystal
  mcp2515.setNormalMode();
}

void loop() {
  const byte pids[] = {0x0C, 0x0D, 0x05};    // RPM, speed, coolant
  for (byte pid : pids) {
    askPid(pid);
    unsigned long start = millis();
    while (millis() - start < 100) {
      if (mcp2515.readMessage(&reply) == MCP2515::ERROR_OK &&
          reply.can_id == 0x7E8 && reply.data[1] == 0x41 && reply.data[2] == pid) {
        byte A = reply.data[3], B = reply.data[4];
        if (pid == 0x0C) { Serial.print("RPM: ");        Serial.println(((A * 256) + B) / 4); }
        if (pid == 0x0D) { Serial.print("Speed km/h: "); Serial.println(A); }
        if (pid == 0x05) { Serial.print("Coolant C: ");  Serial.println(A - 40); }
        break;
      }
    }
  }
  delay(250);
}

How the formulas work

PID Value Formula
0x0C Engine RPM ((A × 256) + B) / 4
0x0D Vehicle speed A (km/h)
0x05 Coolant temperature A − 40 (°C)

Build an Arduino OBD2 display

Replace the Serial.print lines with output to a 0.96″ SSD1306 OLED (Adafruit_SSD1306 library) or a 16×2 I2C LCD. Both use the I2C pins (A4/A5 on Uno and Nano), so they do not conflict with the MCP2515 on the SPI pins.

Troubleshooting

  • No replies: turn the ignition on, check CAN-H/CAN-L are not swapped, and try CAN_250KBPS.
  • Garbage or bus errors: the crystal setting is wrong — read the crystal on your module (8 MHz or 16 MHz).
  • Works on the bench, not in the car: remove the 120 Ω jumper and make sure grounds are shared.

Safety and good practice

  • Only send standard OBD2 requests like the ones above. Do not send other frames on the bus — it can trigger warning lights or affect vehicle systems.
  • Test with the car parked. Mount any display where it does not distract you while driving.
  • Car electrical systems have voltage spikes; power a permanent install through an automotive-rated converter and unplug it when the car is parked for long periods.

Building a dashboard, logger or gauge? Show it in the Car & CAN Bus Projects board.

Sources & further reading

Comments

No comments yet. Questions about this guide, or tried it yourself? Share it below.

Leave a comment