Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

GETTING STARTED WITH CAN INTERFACE WITH ARDUINO

By Prabakaran P.M May 9, 2021

This Article is to make readers to explore about how to interface CAN Bus with Arduino which is used in the Communication of Sensors, Actuators and controllers in a car.

This project helps in understanding the insights of CAN protocol interfacing with Arduino. Controller Area Network or CAN protocol is a methodology of communication between various electronic devices like engine management systems, gear control, active suspension, ABS, lighting control, air conditioning, airbags, central locking etc. embedded in an automobile. For further learnings refer this article.

Here you will get idea about the programming of Arduino to interface with CAN Controller (MCP2515) to act as a transceiver.

DESCRIPTION:

Prerequisites & Equipment:

You will need the following:

  1. Two Arduino Board or Arduino clone(Here is a guide if you need)

  2. A 5v TTL -UART Bluetooth module.

  3. Arduino IDE for the programming.

  4. Two MCP2515 CAN Tranciever.

Features MCP2515 CAN Tranciever:

  1. Implements CAN V2.0B at up to 1 Mb/s

  2. SPI Interface up to 10 MHz

  3. Standard (11 bit) and extended (29 bit) data and remote frames

  4. Two receive buffers with prioritized message storage

  5. Two LED indicators

Demonstration:

Prototype of Arduino based Transmitter and Receiver Circuits for communication over CAN Interface

Fig. 1: Prototype of Arduino based Transmitter and Receiver Circuits for communication over CAN Interface

1. Download the CAN-BUS Library code file for Arduino 1.0 and unzip it under the libraries directory of the Arduino IDE folder. For my computer’s setup, it’s in this directory

XXXarduino-1.0.1libraries

After copying files across, the directory

XXXarduino-1.0.1librariesDHT

2. Open the Arduino-1.0, and navigate to Examples you will find examples: receive_blink, receive_check, receive_interrupt, Send, Send_blink. Here we’ll use send and receive_check to check our CAN Bus.

Screenshot of navigating to sample code for CAN Receiver in Arduino IDE

Fig. 2: Screenshot of navigating to sample code for CAN Receiver in Arduino IDE

3. Upload Send examples to one Arduino Board. Choose the board by navigating to: Tools –>Serial Port–>COMX.

Note: Remember which board you select as a “send” node and which board you select as a “receive” node.

4. Open the “Serial Monitor” by selecting the Com Port which you selected for the Receiver, you will get the preset message “0 1 2 3 4 5 6 7” which is sent from the “send” node. This can be seen in the following picture.

Screenshot of Arduino Serial Port receiving preset messages over CAN Interface

Fig. 3: Screenshot of Arduino Serial Port receiving preset messages over CAN Interface

Functions in CAN Library:

1. Set the Baud Rate

To initialize the baud rate of the CAN Bus system use the following Functions.

The available baud rates are:

CAN_5KBPS, CAN_10KBPS, CAN_20KBPS, CAN_40KBPS, CAN_50KBPS, CAN_80KBPS, CAN_100KBPS, CAN_125KBPS, CAN_200KBPS, CAN_250KBPS, CAN_500KBPS and CAN_1000KBPS

2. Check Receive

The MCP2515 has two modes of Receive Check, one is Polling where the code checks the received frame and the other mode is Interrupt mode where, Separate Interrupt pin is used to notify the received frame.

The following is the Polling method to get the received frame.

INT8U MCP_CAN::checkReceive(void);

The function will return 1 if a frame is received, and 0 if nothing received.

3. Get CAN ID

If you want know the CAN ID of the Sending node when a message is received you vcan use the following Function.

INT32U MCP_CAN::getCanId(void)

4. Send Data

The below function is to send data onto the bus:

CAN.sendMsgBuf(INT8U id, INT8U ext, INT8U len, data_buf);

Where,

“id” gives CAN ID of the sending nodes.

“ext”  ‘0’ means standard frame. ‘1’ means extended frame.

“len” gives the length of this frame.

“data_buf” is the main content of this message.

For example, In the ‘send’ example, we have:

unsigned char stmp[8] = {0, 1, 2, 3, 4, 5, 6, 7};

CAN.sendMsgBuf(0x00, 0, 8, stmp); //send out the message ‘stmp’ to the bus and tell other devices this is a standard frame from 0x00.

5. Receive Data

The following function is used to receive data from the bus:

CAN.readMsgBuf(unsigned char len, unsigned char buf);

“len” gives the data length.

“buf” is the main content of this message.

Prototype of Arduino based CAN Transmitter Circuit designed on a breadboard

Fig. 4: Prototype of Arduino based CAN Transmitter Circuit designed on a breadboard

Prototype of Arduino based CAN Receiver Circuit designed on a breadboard

Fig. 5: Prototype of Arduino based CAN Receiver Circuit designed on a breadboard

You may also like:


  • What are different types of industrial robots?

  • What are LoRa gateways and what types are available?

  • What are the top tools for developing embedded software?

  • What is the Modbus protocol and how does it work?

  • What is a Robot Operating System (ROS)?

  • What is FreeRTOS?

Circuit Diagrams

circuit_30

Project Video


Filed Under: Electronic Projects
Tagged With: Arduino, Arduino project, can interface, electronic projects, spi
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Voltage mode pushpull is a nonsense SMPS?
  • Input impedance matching network
  • High Side current sensing
  • The comparison of different Tcl script checkers
  • Reducing "shoot-through" in offline Full Bridge SMPS?

RSS Electro-Tech-Online.com Discussions

  • Is AI making embedded software developers more productive?
  • Back to the old BASIC days
  • Parts required for a personal project
  • PIC KIT 3 not able to program dsPIC
  • Failure of polypropylene motor-run capacitors

Featured – RPi Python Programming (27 Part)

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol
  • RPi Python Programming 26 – Interfacing ADXL345 accelerometer sensor with Raspberry Pi

Recent Articles

  • What is AWS IoT Core and when should you use it?
  • AC-DC power supply extends voltage range to 800 V DC
  • Infineon’s inductive sensor integrates coil system driver, signal conditioning circuits and DSP
  • Arm Cortex-M23 MCU delivers 87.5 µA/MHz active mode
  • STMicroelectronics releases automotive amplifiers with in-play open-load detection

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe