Skip to content

Latest commit

Β 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 

Repository files navigation

πŸš— CAN Bus Communication using Arduino + MCP2515

Implemented a real-time CAN Bus communication system using two Arduino nodes with MCP2515 CAN controllers and TJA1050 transceivers β€” transmitting live temperature, humidity, and potentiometer data over the CAN Bus with full performance metrics analysis.


πŸ“‹ Overview

CAN (Controller Area Network) Bus is a robust, differential two-wire communication protocol originally designed by Robert Bosch for automotive applications. This project demonstrates a working hardware implementation of CAN Bus between two Arduino nodes, with one acting as transmitter (reading sensors) and the other as receiver (displaying data on LCD).

Performance metrics including Throughput, Goodput, Latency, and Bus Utilization were measured in real-time on the receiver node.


πŸ› οΈ Hardware Used

Component Role
Arduino Uno (Γ—2) Main microcontroller for each node
MCP2515 External SPI-based CAN controller
TJA1050 CAN Bus transceiver (drives CAN_H / CAN_L)
DHT22 Sensor Temperature & Humidity measurement
Potentiometer Analog value simulation
16Γ—2 LCD Data display on receiver side
120Ξ© Resistors (Γ—2) Bus termination resistors
Connecting Wires CAN Bus line + SPI connections

⚑ CAN Bus Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     CAN_H ────────────────────
β”‚         TRANSMITTER NODE        β”‚                                β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”‚
β”‚  β”‚  Arduino  │──▢│ MCP2515  │──▢│─────│       TJA1050           β”‚β”‚
β”‚  β”‚          β”‚SPIβ”‚ CAN Ctrl β”‚   β”‚     β”‚   CAN Transceiver       β”‚β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”‚
β”‚       β–²                         β”‚                                β”‚
β”‚  [DHT22] [Potentiometer]        β”‚     CAN_L ────────────────────
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚          RECEIVER NODE          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Arduino  │◀──│ MCP2515  │◀──│── CAN Bus
β”‚  β”‚          β”‚SPIβ”‚ CAN Ctrl β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚       β”‚                         β”‚
β”‚    [LCD Display]                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Bus Termination: 120Ξ© resistors at both ends of CAN_H line.


πŸ“¦ CAN Frame Format Used

β”Œβ”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”
β”‚ SOF β”‚  Identifier  β”‚ Control Field β”‚ Data Field β”‚ CRC Field β”‚ ACK Fieldβ”‚ EOF β”‚
β”‚ 1b  β”‚   11 bits    β”‚  DLC (4 bits) β”‚  0–8 bytes β”‚  15 bits  β”‚  2 bits  β”‚ 7b  β”‚
β””β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”˜

CAN IDs used in this project:

  • 0xAA β€” Potentiometer value (1 byte)
  • 0xBB β€” Temperature + Humidity + Timestamp (6 bytes)

πŸ”Œ Wiring & Pin Connections

MCP2515 β†’ Arduino SPI

MCP2515 Pin Arduino Pin
VCC 5V
GND GND
SCK Pin 13 (SCK)
MOSI Pin 11 (MOSI)
MISO Pin 12 (MISO)
CS Pin 10
INT Pin 2

DHT22 Sensor (Transmitter)

DHT22 Pin Arduino Pin
VCC 5V
GND GND
DATA Pin A1

CAN Bus Lines

MCP2515 (TX) CAN_H ──────────────── MCP2515 (RX) CAN_H
             CAN_L ──────────────── CAN_L

πŸ’» Software & Libraries

#include <SPI.h>
#include <mcp2515.h>    // Seeed-Studio/CAN_BUS_Shield or autowp/mcp2515
#include <DHT.h>        // adafruit/DHT-sensor-library

CAN Bus Config:

#define CAN_SPEED   CAN_500KBPS
#define MCP_CRYSTAL MCP_8MHZ

πŸ“‚ Repository Structure

can-bus-arduino-mcp2515/
β”‚
β”œβ”€β”€ README.md
β”œβ”€β”€ transmitter/
β”‚   └── transmitter.ino         ← Sender: reads DHT22 + Pot β†’ sends CAN frames
β”œβ”€β”€ receiver/
β”‚   └── receiver.ino            ← Receiver: reads CAN frames β†’ LCD + Serial metrics
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ circuit_diagram.png     ← Full wiring diagram
β”‚   β”œβ”€β”€ serial_output.png       ← Serial monitor showing live metrics
β”‚   └── lcd_output.jpg          ← LCD displaying received sensor data
└── presentation/
    └── CAN_Bus_Slides.pdf      ← Project presentation

πŸ“Š Results & Performance Metrics

From live hardware testing at 500 kbps:

Metric Value
Frames/sec 23
Throughput 2.10 kbps
Goodput 0.66 kbps
Bus Utilization 0.42%
TX Time (avg) 182.17 Β΅s
TX Time (min/max) 130 / 230 Β΅s
Latency (avg) 308,628 ms*
Power 0.0512 W

*High latency value is due to cumulative delay measurement from program start, not per-frame latency. Per-frame TX time is ~182 Β΅s.


πŸš€ How to Run

  1. Install libraries via Arduino IDE β†’ Library Manager:

    • mcp2515 by autowp
    • DHT sensor library by Adafruit
  2. Upload transmitter/transmitter.ino to Arduino 1 (sender)

  3. Upload receiver/receiver.ino to Arduino 2 (receiver)

  4. Wire both MCP2515 modules together:

    • Connect CAN_H to CAN_H
    • Connect CAN_L to CAN_L
    • Add 120Ξ© termination resistors at both ends
  5. Open Serial Monitor at 115200 baud on receiver to see live metrics

  6. LCD will show: Pot=XX | T=XXC | H=XX%


πŸ“ˆ Key Learnings

  • SPI communication between Arduino and MCP2515
  • CAN frame construction (ID, DLC, data bytes, CRC)
  • Differential signaling for noise immunity
  • Multi-node bus architecture with collision-free arbitration
  • Real-time performance metric calculation (throughput, goodput, bus utilization)

πŸ”§ Future Improvements

  • Efficiency vs Payload Size analysis (1–8 bytes)
  • Bitrate scaling study: 500 kbps β†’ 1 Mbps
  • Add error handling for CRC failures and ACK retries
  • Extend to 3+ node network

πŸ‘€ Author

Divyanshu Kumar
B.Tech ECE, University of Delhi (2023–2027)
LinkedIn | GitHub


πŸ“„ License

MIT License β€” feel free to use for educational purposes.

About

CAN Bus communication using Arduino + MCP2515 + TJA1050 | Live DHT22 & pot data over 500kbps bus | 23 fps | 2.10 kbps throughput | Real-time LCD display

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors