0% found this document useful (0 votes)
397 views1 page

ESP32 Arduino Code - Obd2-1

This document contains an Arduino sketch for an ESP32 Bluetooth client that connects to an ELM327 OBD-II adapter. It initializes Bluetooth, connects to the ELM327 device, and sends commands to request engine RPM data. The loop continuously requests data and prints the responses from the ELM327 to the serial monitor.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
397 views1 page

ESP32 Arduino Code - Obd2-1

This document contains an Arduino sketch for an ESP32 Bluetooth client that connects to an ELM327 OBD-II adapter. It initializes Bluetooth, connects to the ELM327 device, and sends commands to request engine RPM data. The loop continuously requests data and prints the responses from the ELM327 to the serial monitor.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include "BluetoothSerial.

h"

BluetoothSerial SerialBT;

const char* ELM327_BT_NAME = "OBDII"; // Change to your ELM327's Bluetooth name

void setup() {
[Link](115200);
[Link]("Starting ESP32 Bluetooth ELM327 Client...");

if (![Link]("ESP32_OBD_Client", true)) { // true = client mode


[Link]("An error occurred initializing Bluetooth");
while (1);
}

[Link]("Bluetooth started, connecting to ELM327...");

if ([Link](ELM327_BT_NAME)) {
[Link]("Connected to ELM327!");
} else {
[Link]("Failed to connect. Make sure ELM327 is on and in range.");
while (1);
}

// Optional: Send ELM327 init commands


[Link]("ATZ"); // Reset
delay(2000);
[Link]("ATE0"); // Echo off
delay(1000);
[Link]("ATL0"); // Linefeeds off
delay(1000);
}

void loop() {
// Request Engine RPM (PID 010C)
[Link]("010C");
delay(500);

// Read response
while ([Link]()) {
String response = [Link]('\r');
[Link]("ELM327: ");
[Link](response);
}

delay(2000); // Wait before next request


}

You might also like