This past summer, Arduino released a new version within their popular microcontroller series, the Nano R4. In a previous article I wrote about the new USB HID functionality that was added in the release. In this article I would like to focus on the addition of the CAN protocol being native to the Arduino Nano R4.
CAN Protocol – Electrical
The CAN (Controller Area Network) Protocol is a serial bus interface used to connect multiple devices in a Network. The devices all connect to a common Bus and share a twisted pair of wires called CAN High and CAN Low. The protocol requires 3 conductors to operate: CAN H, CAN L, and Ground. These CAN lines are opposites of each other. When the CAN lines are digital low, both CAN H and CAN L are at the same voltage. When the bus goes digital high, the line’s voltages go in opposite directions. For example, if they are digital low at a voltage of 2.5V, then at digital high, CAN H may be at 3.5V while CAN L would be at 1.5V. The voltages are equidistant from the digital low voltage which is called differential signaling. The benefits for differential signaling are that they minimize EMI (Electromagnetic Interference), allow long runs of wire, and high throughput. CAN is most used in vehicular communications and industrial automation.
How CAN Works – Logical Protocol
CAN in its simplest explanation can be thought of a group call full of people attempting to all talk to each other. Someone initiates a conversation by stating their ID and the ID of whom they need to communicate with. This allows the two to communicate effectively, all while sharing space with others. If two speakers attempt to communicate at the same time, the ID that is lower numerically is allowed to communicate first, the other follows unless a speaker with an ID that is lower attempts to speak. The speakers here are the devices (sensors, MCUs, etc.) and the shared space is the wires/bus.
What the Nano R4 CAN Now Do
This iteration of the Arduino Nano now has the R7FA4M1AB3CFM#HA0 32-bit MCU from Renesas which has a CAN controller packaged into it. The use of R4’s CAN peripheral requires an external CAN transceiver to work with a CAN bus. Arduino recommends transceivers such as the SN65HVD230 from Texas Instruments or the MCP2561 from Microchip. For my setup I used a TJA1050T made by NXP USA.
Example Code
#include <Arduino_CAN.h>
//This Code Honks the horn of a Tesla when a button is pressed on D6
#define BUTTON_PIN D6
#define HONK_TIME_MS 50
#define CAN_ID_HONK 0x273
bool lastButtonState = HIGH;
void setup() {
// Serial is optional; do not block startup
Serial.begin(115200);
pinMode(BUTTON_PIN, INPUT_PULLUP); // button wired D6 → GND
if (!CAN.begin(CanBitRate::BR_500k)) //Check if CAN started up fine
{
while (1); // hard fail
}
}
void loop() {
bool buttonState = digitalRead(BUTTON_PIN); //Read button
if (buttonState == LOW && lastButtonState == HIGH) // Detect button press and release
{
// Build CAN frame
CanMsg hornMsg;
hornMsg.id = CAN_ID_HONK; // ID273UI_vehicleControl
hornMsg.data_length = 8;
// Zero the 8 bytes
for (int i = 0; i < 8; i++) {
hornMsg.data[i] = 0;
}
// Bit 61 → byte 7, bit 5
hornMsg.data[7] = 0x20;
// Honk ON
CAN.write(hornMsg);
delay(HONK_TIME_MS);//Horn honks for
// Honk OFF
hornMsg.data[7] = 0x00;
CAN.write(hornMsg);
Serial.println("Horn triggered");
}
lastButtonState = buttonState; //Set previous button state
}Setup
To use the code shown above, one needs access to the CAN network in their Tesla vehicle. In the car used for this article, a 2021 Tesla Model Y Long Range, the CAN bus was found behind the center console, near the floor. A plastic cover needed to be pried off, and a splicer was purchased to connect in series. USB-C power was supplying the Nano R4. The provided code waits for a button to be pressed and released, connected to D6 and GND, and from there a data packet sends the honk horn bit for 50ms before setting it back to off. The idea is if the driver is hesitant to honk, the passenger can take some initiative. Below is the wiring needed for the CAN buses to work:
- Arduino GND to CAN Transceiver GND to Pin 5
- Arduino 5V to CAN Transceiver PWR
- CAN Transceiver CAN HIGH to Pin 6
- CAN Transceiver CAN LOW to Pin 14
- Arduino CAN RX to CAN Transceiver CAN RX
- Arduino CAN TX to CAN Transceiver CAN TX

CAN BUS Demo
Conclusion
In my sample code, I was able to control one of thousands of settings within my vehicle through the CAN bus. Some other examples could be starting seat heat on various seats, opening and closing the trunk, or turning on the wipers, with thousands of other controls for the vehicle. Some of these can damage the car and tinkerers should be careful not to damage the car with the messages being sent to it, especially whilst driving. The ones chosen here are generally low risk. Though overall CAN is a very robust protocol and can be used in many applications.
Learn more about DMC’s Embedded Development and Programming services and contact us for your next project!







