I'm using an Arduino Mega with a Bluetooth ELM327 adapter to read live data from my car’s OBD-II port — specifically RPM (PID 010C). The goal is to log data to an SD card or display it in real time.
To verify that my car and hardware were set up correctly, I took help from this article: The Ultimate Guide to Using a Car Diagnostic Scanner
I identified the correct OBD-II port and confirmed power and ground pins before connecting my hardware.
I initialized the communication with commands like ATZ, ATE0, and ATSP0.
I connected the ELM327 via Bluetooth (HC-05) to Arduino Mega's Serial1.
Sent the following AT commands:
Serial1.print("ATZ\r"); // Reset Serial1.print("ATE0\r"); // Echo off Serial1.print("ATSP0\r"); // Auto-select protocol Serial1.print("010C\r"); // Request engine RPM Occasionally received a valid response like: 41 0C 1A F8 → ((0x1A * 256) + 0xF8) / 4 = 1720 RPM. But responses are inconsistent: sometimes I get NO DATA, partial bytes, or just nothing. I'm suspecting either timing issues or that I’m not reading the buffer correctly.
Should I wait for the > prompt from ELM327 before sending another command? If so, what’s the best way to do that using Arduino code?
My Arduino code:
#include <SoftwareSerial.h> SoftwareSerial elmSerial(10, 11); // RX, TX for HC-05 (adjust as needed) void setup() { Serial.begin(9600); // Monitor elmSerial.begin(9600); // ELM327 default delay(1000); sendCommand("ATZ\r"); sendCommand("ATE0\r"); sendCommand("ATSP0\r"); } void loop() { sendCommand("010C"); // Request RPM delay(2000); // Wait between requests } void sendCommand(String cmd) { elmSerial.print(cmd + "\r"); delay(100); while (elmSerial.available()) { char c = elmSerial.read(); Serial.print(c); // Echo to Serial Monitor } }
SoftwareSerialcannot receive and send at the same time? Another hint: please extend the print toSerial.print(c, HEX);to make NUL bytes visible, as messages are binary.