Table of Contents
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
- ESP32 DevKit: WiFi/Bluetooth microcontroller
- ELM327 Bluetooth/WiFi: OBD-II adapter
- OBD-II Extension Cable: For easier mounting
- 5V Power Supply: USB or buck converter
- OLED Display (optional): 0.96" I2C display
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
| PID | Description | Formula |
|---|---|---|
| 01 | Monitor status | - |
| 04 | Calculated load | A*100/255 |
| 05 | Coolant temp | A-40 |
| 0C | Engine RPM | ((A*256)+B)/4 |
| 0D | Vehicle speed | A |
| 2F | Fuel level | A*100/255 |
| 46 | Ambient temp | A-40 |
Mobile Dashboard
Create a simple Blynk or MIT App Inventor dashboard showing:
- Real-time RPM gauge
- Speedometer
- Temperature warning
- Fuel level indicator
- Trip statistics
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
Related Articles:
Fleet Tracking |
Vehicle Health Monitoring