Yes, Arduino boards can use the CAN bus protocol, but not directly out of the box. Most Arduino boards lack a built-in CAN controller, so you need an external CAN shield or module (like the MCP2515) to interface with a CAN network. This article explains what CAN bus is, how to connect it to an Arduino, and what you need to know to get your first project running.
What Is CAN Bus and Why Use It with Arduino?
CAN (Controller Area Network) is a robust serial communication protocol designed for real-time control in vehicles and industrial machinery. It lets multiple microcontrollers and sensors talk over just two wires (CAN_H and CAN_L) without a central host. Each device on the network is a node with a unique identifier, and messages are broadcast to everyone, with each node deciding whether to act on them. This makes wiring simpler and reduces the number of cables, which is why cars use it for everything from engine control to airbags.
For an Arduino hobbyist, CAN bus is the gateway to reading real vehicle data (like RPM, speed, or coolant temperature) from a car’s OBD-II port, or building multi-node sensor networks where dozens of Arduinos share data over a single twisted pair. The protocol is also extremely reliable—it has built-in error detection and retransmission, so it is a good choice for projects where a lost message could cause a problem.
Hardware You Need: Shields and Modules
Because the Arduino’s microcontroller (ATmega328P on the Uno, for example) does not have a CAN controller, you must add one. There are two common approaches:
- MCP2515-based modules: The Microchip MCP2515 is a standalone CAN controller that connects to the Arduino via SPI. These modules are cheap (around $5–10) and widely available. They usually include a TJA1050 or MCP2551 transceiver chip, which handles the physical electrical signaling on the CAN bus. You connect them with just four wires: VCC, GND, MOSI, MISO, SCK, and CS (six pins total).
- CAN shields with integrated transceivers: Shields like the Seeed Studio CAN-BUS Shield or SparkFun CAN-BUS Shield plug directly onto an Uno or Mega. They have the same MCP2515 chip but add a DB9 connector, an OBD-II port, and sometimes a microSD slot. These are more convenient for prototyping but cost more (around $20–30).
Some newer boards, like the Arduino Due (which has an Atmel SAM3X8E) or the Portenta H7, have a built-in CAN controller. For those, you only need a transceiver chip (like the TJA1050) on a breadboard, not a full module. However, the vast majority of tutorials and libraries target the MCP2515 because it works with any Arduino.
Wiring and Basic Connections
Wiring an MCP2515 module to an Arduino Uno is straightforward. The module’s SPI pins map to the Uno’s SPI header: MOSI to pin 11, MISO to pin 12, SCK to pin 13, and CS (chip select) to pin 10 (or any digital pin you define in software). Power the module with 5V and GND. The CAN_H and CAN_L terminals on the module go to the two wires of your CAN bus. If you are just testing two Arduinos together, you must connect their CAN_H pins to each other and CAN_L pins to each other, and you also need a 120-ohm resistor between CAN_H and CAN_L at each end of the bus (so two resistors total for a two-node network).
If you are connecting to a car’s OBD-II port, you do not need to add resistors because the car’s network already has termination. Just connect the module’s CAN_H to OBD pin 6 and CAN_L to pin 14, plus ground to pin 5. Many ready-made OBD-II cables have these pins wired correctly, so you can plug directly into the shield.
Software Libraries and a First Sketch
The most popular library for MCP2515 is the mcp_can library (by coryjfowler) or the more modern MCP_CAN library by Seeed Studio. Both are available through the Arduino Library Manager. A basic send and receive sketch looks like this:
To send a message:
- Include the library and create an object:
MCP_CAN CAN(10);(10 is the CS pin). - In
setup(), callCAN.begin(CAN_500KBPS)to set the baud rate (500 kbps is common for cars; many industrial networks use 125 kbps). - In
loop(), build a byte array with your data and callCAN.sendMsgBuf(0x123, 0, 8, data)where 0x123 is the message ID, 0 means standard frame (not extended), 8 is the data length, anddatais the byte array.
To receive, you check CAN.checkReceive() in the loop; if it returns true, call CAN.readMsgBuf() to get the ID, length, and data. The library handles the low-level SPI communication, so you do not need to worry about the MCP2515 registers.
Choosing a Baud Rate and Message IDs
The baud rate must match across all nodes on the bus. For a car’s OBD-II port, the standard is 500 kbps (some older vehicles use 250 kbps, and a few use 125 kbps). If you are building your own network, you can choose any rate the MCP2515 supports (up to 1 Mbps), but lower rates are more reliable over longer wires. The message ID is an 11-bit number (standard frame) or 29-bit (extended frame). On a car, IDs are assigned by the manufacturer, and you cannot change them. For your own projects, you can pick any ID you like, but keep in mind that lower IDs have higher priority—if two nodes send at the same time, the one with the lower numeric ID wins arbitration.
A common beginner mistake is using the same ID for multiple nodes. Each node should have a unique ID range, or you will get collisions and lost messages. Also, remember that CAN is a broadcast protocol: every node sees every message, so you do not need addressing—just filter by ID in your receive code.
Common Problems and How to Fix Them
If your two Arduinos are not communicating, check these in order:
- Termination resistors missing: Without 120-ohm resistors at both ends, signals reflect and cause errors. Add them.
- Wrong baud rate: Both nodes must use the same rate. Double-check the
begin()parameter. - Ground connection: All nodes must share a common ground. If you power two Arduinos from separate USB ports, connect their GND pins together.
- CS pin mismatch: If you changed the CS pin in the constructor, make sure the wiring matches. The default is pin 10.
- Power supply: The MCP2515 module draws about 50 mA; if you power it from the Arduino’s 5V pin, it is fine, but a long bus with many modules may need a separate 5V supply.
If you see a lot of errors, use the library’s CAN.getError() function to get the error counter. A high transmit error counter usually points to wiring or termination; a high receive error counter often means a baud rate mismatch.
Reading Real Car Data (OBD-II)
To read data from a car, you need to know the OBD-II PID (Parameter ID) standard. For example, PID 0x0C gives engine RPM, PID 0x0D gives vehicle speed, and PID 0x05 gives coolant temperature. The request format is an 8-byte message: bytes 0–1 are the CAN ID (0x7DF for broadcast requests), byte 2 is the number of additional bytes (usually 2), byte 3 is the mode (0x01 for current data), byte 4 is the PID, and the rest are padding. The car’s ECU responds with messages on ID 0x7E8, and the data is in the last bytes. There are many tutorials that show the exact byte parsing, but the general flow is: send the request, wait for the response, parse the data bytes, and apply the scaling factor (for RPM, divide by 4).
Important: Reading OBD-II data is legal and safe for diagnostics, but you should never send write commands (mode 0x03 or 0x04) to a car while driving. Also, some modern cars use CAN FD (CAN with Flexible Data-rate) which the MCP2515 cannot handle; for those, you need a different chip like the MCP2517FD. Most cars from 2008 onward still support classic CAN on the OBD port, but a few electric vehicles use only CAN FD.
Costs and Alternatives
A complete Arduino CAN setup costs about $25–40: an Arduino Uno clone ($10–15), an MCP2515 module ($5–10), and a few jumper wires. An OBD-II cable adds another $5–10. If you want a ready-made solution, the Seeed CAN-BUS Shield is about $25 and includes the OBD connector. For higher performance, consider the Arduino Due (built-in CAN, about $40) or an ESP32 with an external CAN transceiver (the ESP32 has a CAN controller built into some variants, but the library support is less mature). For industrial use, a Raspberry Pi with a CAN hat is a common alternative, but it is more complex to set up and not real-time.
Frequently Asked Questions
Can I use an Arduino to hack a car’s ECU? You can read data, but sending arbitrary messages to a modern car’s ECU is risky and can cause errors or, in rare cases, damage. Stick to reading OBD-II PIDs for diagnostics. For tuning or flashing, you need specialized hardware and software.
What is the maximum cable length for CAN bus? At 500 kbps, the practical limit is about 40 meters (130 feet). At 125 kbps, you can go up to 500 meters (1,640 feet). Use twisted pair wire (like CAT5) and keep the bus linear—no star topologies.
Can I connect more than two Arduinos? Yes, up to 112 nodes on a standard CAN bus (the MCP2515 supports 112 nodes). Each node needs the same baud rate and its own unique message ID. You still need only two termination resistors at the physical ends of the bus.
Why do I need a 120-ohm resistor? The resistor matches the characteristic impedance of the twisted pair wire, preventing signal reflections. Without it, the high-speed pulses bounce back and cause bit errors. Place one at each physical end of the bus, not in the middle.
Is CAN bus the same as OBD-II? No. OBD-II is a diagnostic standard that specifies a physical connector and a set of PIDs. CAN is one of the underlying protocols used by OBD-II (since 2008 in the US). OBD-II can also run on other protocols like K-Line (ISO 9141), but modern cars almost all use CAN.
Can I use an Arduino to log CAN data to an SD card? Yes, many CAN shields have a microSD slot. You can write the received messages to a CSV file with a timestamp. Just be aware that at 500 kbps, the bus can be very busy, and the Arduino’s 16 MHz processor may miss messages if you also do heavy SD writes. Use a faster board like the Arduino Due for high-speed logging.
Related
- Where Does Hera Live? Greek Goddess Home
- Hera and Her Family: Greek Goddess of Marriage
- Apollo Home Care Daily Attendance Explained
How pages are sourced and corrected: Sources and editorial policy.