How-to · Advanced · 3 min read
CAN Bus Basics
MCP2515 Modules, Transceivers and Adapters With Arduino and ESP32
By Geekobot Learning Team · Updated 29 Oct 2026
On this page
CAN bus is a two-wire differential network where many devices share one pair of wires and send short prioritised messages. An Arduino needs a CAN controller (MCP2515 over SPI) plus a transceiver. An ESP32 has a built-in CAN controller called TWAI and only needs a transceiver. Use 120 Ω termination at both ends and set the same bit rate on every node.
Key specs at a glance
- Wiring
- CANH and CANL twisted pair, plus ground
- Termination
- 120 Ω at each end of the bus
- Bit rate
- 125 kbit/s to 1 Mbit/s for classic CAN
- MCP2515
- SPI CAN 2.0B controller, usually with a TJA1050 5 V transceiver
- ESP32
- TWAI controller; use a 3.3 V transceiver such as SN65HVD230
- CAN FD
- Faster data phase, needs FD capable hardware
How CAN works
Each message has an ID (which also sets its priority), up to 8 bytes of data in classic CAN, and a CRC. Every node hears every message and decides whether to use it. If two nodes talk at once, the lower ID wins without losing data. This makes CAN reliable for cars, drones (DroneCAN), 3D printer toolheads and industrial machines.
Hardware options
Choose by platform.
| Platform | Parts | Notes |
|---|---|---|
| Arduino Uno / Nano | MCP2515 module with TJA1050 | SPI; check the crystal (8 or 16 MHz) in the code |
| ESP32 | TWAI controller plus a transceiver | No MCP2515 needed |
| Raspberry Pi | MCP2515 HAT or USB-CAN adapter | SocketCAN on Linux |
| PC | USB to CAN adapter | For analysers and ROS |
| Gateways | CAN to RS485/Ethernet converters | Link CAN to other networks |
- Arduino Uno / Nano
- Parts:
- MCP2515 module with TJA1050
- Notes:
- SPI; check the crystal (8 or 16 MHz) in the code
- ESP32
- Parts:
- TWAI controller plus a transceiver
- Notes:
- No MCP2515 needed
- Raspberry Pi
- Parts:
- MCP2515 HAT or USB-CAN adapter
- Notes:
- SocketCAN on Linux
- PC
- Parts:
- USB to CAN adapter
- Notes:
- For analysers and ROS
- Gateways
- Parts:
- CAN to RS485/Ethernet converters
- Notes:
- Link CAN to other networks
Sending a message with the MCP2515
This Arduino sketch uses the common mcp_can library and sends an 8 byte frame every second at 500 kbit/s. Set MCP_8MHZ or MCP_16MHZ to match the module's crystal.
#include <SPI.h>
#include <mcp_can.h>
MCP_CAN CAN0(10); // CS pin
void setup() {
Serial.begin(115200);
if (CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_8MHZ) != CAN_OK) {
Serial.println("CAN init failed"); while (1);
}
CAN0.setMode(MCP_NORMAL);
}
void loop() {
byte data[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
if (CAN0.sendMsgBuf(0x100, 0, 8, data) == CAN_OK) Serial.println("sent");
delay(1000);
}Troubleshooting
wrong crystal setting, wrong CS pin or wiring.
bit rates do not match, or no termination. Measure about 60 Ω between CANH and CANL with power off (two 120 Ω resistors in parallel).
use twisted pair, keep stubs short and ground the shield at one end.
use a 3.3 V transceiver or a level shifter (level shifting).
Try it: Uart baud rate error calculator
Change the values and the diagram and results update as you type.
Common mistakes to avoid
- Leaving out the termination resistors.
- Using the wrong crystal frequency in code.
- Different bit rates on different nodes.
- Connecting a 5 V transceiver output to a 3.3 V ESP32 pin.
- Running a long stub off the main bus.
Frequently asked questions
What is the difference between CAN and RS485?
Both use differential wires. CAN adds addressing, priority, error handling and message framing in hardware.
Do I need a transceiver?
Yes. The controller (MCP2515 or ESP32) needs a transceiver to drive the CANH and CANL lines.
Can MCP2515 do CAN FD?
No, it supports classic CAN 2.0A and 2.0B only.
How many devices on one bus?
Many dozens, limited by cable length and bit rate.
What is OBD-II?
The car diagnostic port, which carries CAN on pins 6 and 14 in most modern vehicles.
Parts for this guide
Calculators
Terms in this guide
Keep learning
Sources
Written by the Geekobot team from manufacturer datasheets. Always check the datasheet for the exact part and variant you buy.




