Connect Bluetooth OBD2 Arduino CAN Bus for Real-Time Car Data

As a passionate car enthusiast diving into the world of DIY automotive diagnostics, you might find yourself exploring ways to access and interpret your car’s data in real-time. For beginners venturing into the Arduino realm, projects involving CAN bus communication and Bluetooth connectivity can seem daunting. However, with the right guidance, connecting a Bluetooth Obd2 Arduino Can Bus setup to monitor your vehicle’s performance becomes an achievable and incredibly rewarding endeavor.

You’re on the right track if you’re aiming to bridge your car’s On-Board Diagnostics (OBD2) system to your Android device wirelessly. Using an Arduino Uno, a CAN-bus shield, and an HC-06 Bluetooth module is a popular and effective method to tap into the Controller Area Network (CAN) bus of your vehicle. This setup allows you to extract valuable data broadcast by your Engine Control Unit (ECU) and display it on user-friendly applications like Torque Pro. Imagine monitoring parameters like fuel pressure, engine timing, and air-fuel ratio on your Android phone – all thanks to your DIY Arduino project!

You’ve already made significant progress by successfully reading CAN data on your laptop’s serial monitor. This confirms that your CAN-bus shield and Arduino are correctly interfacing with your ECU, and the data is indeed flowing. The code snippet you’ve utilized effectively demonstrates reading CAN bus data:

// demo: CAN-BUS Shield, receive data with check mode
// send data coming to fast, such as less than 10ms, you can use this way
// loovee, 2014-6-13
#include <spi.h>

#define CAN_2515
// #define CAN_2518FD

// the cs pin of the version after v1.1 is default to D9
// v0.9b and v1.0 is default D10
// Set SPI CS Pin according to your hardware
// For Wio Terminal w/ MCP2518FD RPi Hat:
// Channel 0 SPI_CS Pin: BCM 8
// Channel 1 SPI_CS Pin: BCM 7
// Interupt Pin: BCM25
// *****************************************
// For Arduino MCP2515 Hat:
// SPI_CS Pin: D9
#ifdef CAN_2515
#include "mcp2515_can.h"
const int SPI_CS_PIN = 9;
const int CAN_INT_PIN = 2;

mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
#endif

void setup() {
  SERIAL_PORT_MONITOR.begin(1000000);

#ifdef CAN_2518FD
  while (0 != CAN.begin((byte)CAN_1M)) {
    // init can bus : baudrate = 500k
#else
  while (CAN_OK != CAN.begin(CAN_1000KBPS)) {
    // init can bus : baudrate = 500k
#endif
    SERIAL_PORT_MONITOR.println("CAN init fail, retry...");
    delay(100);
  }
  SERIAL_PORT_MONITOR.println("CAN init ok!");
}

void loop() {
  unsigned char len = 0;
  unsigned char buf[8];

  if (CAN_MSGAVAIL == CAN.checkReceive()) { // check if data coming
    CAN.readMsgBuf(&len, buf);    // read data,  len: data length, buf: data buf
    unsigned long canId = CAN.getCanId();

    SERIAL_PORT_MONITOR.println("-----------------------------");
    SERIAL_PORT_MONITOR.print("Get data from ID: 0x");
    SERIAL_PORT_MONITOR.println(canId, HEX);

    for (int i = 0; i<len; i++) {
      SERIAL_PORT_MONITOR.print(buf[i], HEX);
      SERIAL_PORT_MONITOR.print("t");
    }
    SERIAL_PORT_MONITOR.println();
  }
}

You’ve also confirmed that your HC-06 Bluetooth module can communicate with your Android phone and the Torque app. This isolates the next challenge: routing the CAN data you’re successfully reading to the Bluetooth module for wireless transmission to your Android device.

The key step now is to modify your Arduino code to send the CAN data not just to the serial monitor, but also to the Bluetooth module. Instead of using SERIAL_PORT_MONITOR.println() to display the CAN data, you need to use the serial communication linked to your Bluetooth module. Typically, HC-06 modules communicate via serial, and you’ve likely connected its TX pin to an Arduino RX pin (and HC-06 RX to Arduino TX, with voltage level consideration if needed).

Therefore, the core modification involves redirecting the CAN data output. Within your loop() function, where you currently have SERIAL_PORT_MONITOR.print() and SERIAL_PORT_MONITOR.println() commands to display data on the serial monitor, you should replace these with commands that send data to the serial port connected to your Bluetooth module.

If you’ve used the SoftwareSerial library to set up serial communication with your HC-06 on specific digital pins (like pins 2 and 3 as you mentioned for testing), you would use the SoftwareSerial object (let’s say you named it bluetoothSerial) to send the data. For example, instead of SERIAL_PORT_MONITOR.println(canId, HEX); you would use something like bluetoothSerial.println(canId, HEX);. You would apply this redirection to all the SERIAL_PORT_MONITOR.print() and SERIAL_PORT_MONITOR.println() lines within the CAN data processing part of your loop() function.

By making this change, the CAN data, which is currently visible in your serial monitor, will instead be transmitted via Bluetooth. The Torque app on your Android device, configured to receive data from your Bluetooth OBD2 adapter (which is now your Arduino + CAN bus shield + Bluetooth module setup), should then be able to interpret and display this data as virtual gauges.

This approach leverages the raw OBD2 format data directly from your ECU, which is ideal for applications like Torque Pro that are designed to parse and visualize standard OBD2 PIDs (Parameter IDs). You’ve already laid the groundwork by proving out each component individually. Now, connecting the CAN data stream to your Bluetooth transmission is the crucial link to bring your DIY Bluetooth OBD2 Arduino CAN bus project to life and visualize your car’s performance data on your Android device. Remember to ensure your baud rates match between your Arduino serial communication with Bluetooth and the expected settings of your Torque app for seamless data transfer.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *