Back to IoT Blog
Connected Vehicles 25 min read

OBD-II Vehicle Diagnostics Monitor

Build a real-time vehicle diagnostics system using OBD-II port. Read engine data, track fuel efficiency, monitor fault codes, and receive maintenance alerts with ESP32 and ELM327.

What is OBD-II?

OBD-II (On-Board Diagnostics II) is a standardized automotive protocol that provides access to vehicle data. All cars sold in the US since 1996 and Europe since 2001 have OBD-II ports.

Available Data:
  • Engine RPM, Vehicle Speed
  • Coolant Temperature, Air Intake Temp
  • Fuel Level, Fuel Consumption
  • Throttle Position, Load Value
  • Fault Codes (DTCs), Readiness Status

Hardware Components

Wiring & Connection

ELM327 (OBD-II Adapter)
│
├── Pin 16 → +12V Battery (Red)
├── Pin 4 → Chassis Ground (Black)
├── Pin 5 → Signal Ground (Black)
└── Bluetooth/WiFi → ESP32

ESP32 to ELM327 (UART)
├── TX → RX
├── RX → TX
└── GND → GND

ESP32 Firmware

#include <WiFi.h>
#include <PubSubClient.h>
#include <ELM327.h>

const char* ssid = "YOUR_WIFI";
const char* password = "YOUR_PASSWORD";
const char* mqtt_server = "192.168.1.100";

ELM327 elm;
WiFiClient espClient;
PubSubClient client(espClient);

float rpm = 0;
float speed = 0;
float coolantTemp = 0;
int fuelLevel = 0;

void setup() {
  Serial.begin(115200);
  SerialBT.begin("OBD Monitor");
  
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) delay(500);
  
  client.setServer(mqtt_server, 1883);
  
  // Initialize ELM327
  elm.begin(Serial2);
  elm.initELM();
}

void loop() {
  if (!client.connected()) reconnect();
  client.loop();
  
  // Read RPM
  rpm = elm.rpm();
  
  // Read Speed
  speed = elm.kph();
  
  // Read Coolant Temp
  coolantTemp = elm coolantTemp();
  
  // Read Fuel Level
  fuelLevel = elm.fuelLevel();
  
  // Publish to MQTT
  publishData();
  
  delay(2000);
}

void publishData() {
  String payload = "{";
  payload += "\"rpm\":" + String(rpm) + ",";
  payload += "\"speed\":" + String(speed) + ",";
  payload += "\"coolant\":" + String(coolantTemp) + ",";
  payload += "\"fuel\":" + String(fuelLevel);
  payload += "}";
  
  client.publish("vehicle/obd/data", payload.c_str());
}

OBD-II PID Codes

PIDDescriptionFormula
01Monitor status-
04Calculated loadA*100/255
05Coolant tempA-40
0CEngine RPM((A*256)+B)/4
0DVehicle speedA
2FFuel levelA*100/255
46Ambient tempA-40

Mobile Dashboard

Create a simple Blynk or MIT App Inventor dashboard showing:

Safety Warning:
  • Don't program while driving
  • Secure all cables away from pedals
  • Use fuse-tap for permanent installations
  • Disconnect when not in use to prevent battery drain

Next Steps

  • Add GPS tracking for trip logging
  • Implement harsh braking/acceleration detection
  • Create maintenance schedule alerts
  • Add driver scoring system
  • Integrate with home automation