Kunkune

How to Use MCP2515 CAN Bus Module with Arduino

How to Use MCP2515 CAN Bus Module with Arduino

By Kunkune | Published: 2026-10-17

Category: How-to Guides

Learn to wire and program the MCP2515 CAN bus module with Arduino for vehicle or industrial communication. Step-by-step guide with common pitfalls.

Quick Answer

To use the MCP2515 CAN bus module with Arduino, wire its SPI pins (CS, SCK, MOSI, MISO) and power it with 5V, then install the MCP_CAN library and send or receive CAN frames with simple sketches. The TJA1050 transceiver on the module handles the physical CAN signaling, so you only need to connect CANH and CANL to your bus. This guide walks through the wiring, library setup, and a basic send/receive example.

Wiring the MCP2515 to Arduino

The MCP2515 module uses SPI communication, so you connect it to the Arduino’s SPI pins: CS to pin 10 (default), SCK to 13, MOSI to 11, and MISO to 12 on an Uno. Power the module with 5V and ground. For the CAN bus side, connect CANH and CANL to your bus lines; if you're testing with two modules, connect CANH to CANH and CANL to CANL. Add a 120-ohm termination resistor at each end of the bus to prevent reflections.

Installing the CAN Library

The most common library is MCP_CAN by coryj Fowler, available in the Arduino Library Manager. Search for 'MCP_CAN' and install it. After installation, include the library in your sketch and initialize the CAN controller with the correct SPI CS pin and baud rate, typically 500kbps for automotive OBD-II.

Sending and Receiving CAN Frames

To send a frame, use sendMsgBuf(id, ext, len, buf). To receive, check for CAN_MSGAVAIL with checkReceive() and read with readMsgBuf(). The MCP2515 handles the low-level CAN protocol, so your code only deals with message IDs and data bytes. Remember that CAN is broadcast: every node sees all messages, and you filter by ID in software.

Step-by-Step Setup

  1. Connect the hardware: Wire the MCP2515 module to Arduino: VCC to 5V, GND to GND, CS to pin 10, SCK to 13, MOSI to 11, MISO to 12. Connect CANH and CANL to your bus. Double-check that you haven't swapped MOSI and MISO—this is a common mistake.
  2. Install the MCP_CAN library: Open the Arduino Library Manager, search for 'MCP_CAN', and install the latest version. Include it in your sketch with #include . If the library isn't found, check your spelling and internet connection.
  3. Initialize the CAN controller: Create an MCP_CAN object with the CS pin (e.g., MCP_CAN CAN0(10)). In setup(), call CAN0.begin(CAN_500KBPS) and verify the return value. The begin() call returns CAN_OK (0) on success; if not, check wiring and baud rate.
  4. Send a CAN message: Prepare a data buffer and call CAN0.sendMsgBuf(0x123, 0, 8, data); where 0x123 is the message ID and 8 is the data length. Ensure the ID doesn't conflict with other nodes on the bus.
  5. Receive CAN messages: In loop(), check if a message is available with CAN0.checkReceive() == CAN_MSGAVAIL, then read it with CAN0.readMsgBuf(&len, buf). If you don't see messages, verify that the bus has proper termination and that all nodes share the same baud rate.

Product Facts

  • MCP2515 CAN Bus Module TJA1050 Receiver SPI Module: Ideal for Car OBDII / CAN BUS monitoring and control This module is ready for automotive diagnostics, so you can tap into a vehicle's OBD-II port or build custom CAN nodes for monitoring and control.

Shop Related Products

MCP2515 CAN Bus Module TJA1050 Receiver SPI Module

MCP2515 CAN Bus Module TJA1050 Receiver SPI Module

$2.70 $3.85

Shop Now