RepositoryC++BGBulgaria
muki01

muki01/OBD2_KLine_Library

OBD2 K-Line diagnostics library for Arduino, ESP32 and compatible boards. Supports ISO9141, ISO14230 (KWP2000), KW1281, DS2 and KW82

103stars
22forks
0issues
2views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: obd2-library

#1 Repository of the week

2
TINIX TRENDING·Topic: kline

#2 Repository of the week

2
TINIX TRENDING·Topic: kwp2000

#2 Repository of the week

OBD2 KLine Library

GitHub forks GitHub Repo stars GitHub Issues or Pull Requests GitHub License GitHub last commit PlatformIO Registry Arduino IDE Library Manager

OBD2_KLine is a lightweight yet powerful Arduino-compatible library that enables direct communication with vehicles using the K-Line (ISO 9141 / ISO 14230 - KWP2000).

This library is designed for microcontrollers such as Arduino, ESP32, and similar platforms. It allows your device to communicate directly with a vehicle that uses the K-Line.
If you're curious about which types of data are supported, you can find a full list of features below.

K-Line is a legacy protocol used in many European and Japanese vehicles manufactured between ~1987 and 2010, especially before CAN became mandatory in newer models.
This makes the library ideal for working with older cars that still rely on ISO9141 or KWP2000 communication standards.

You can also see my other car projects:

  1. Тhis project is for BMW with I/K bus system.
  2. Тhis project is for Cars with CAN Bus.
  3. Тhis project is for Cars with ISO9141 and ISO14230 protocols.
  4. Тhis is my OBD2 CAN Bus Communication Library for Arduino IDE.
  5. Тhis is my OBD2 K-Line Communication Library for Arduino IDE.
  6. Тhis project is for VAG Cars with KW1281 protocol.

❓ Does Your Vehicle Support K-Line?

Before using this library, it's important to confirm whether your vehicle supports the K-Line protocol.

K-Line vehicles typically have Pin 7 on the OBD-II connector connected.
If your vehicle’s OBD-II connector has Pins 6 and 14 connected, it uses the CAN bus protocol instead of K-Line.

✅ Pin 7 (K-Line): Your vehicle likely supports ISO 9141 or ISO 14230 (KWP2000) — this library will work.
❌ Pin 6 and 14 (CAN bus): Your vehicle uses CAN — consider a different library.

Example photos of OBD2 Connector

OBD2 Connector Pin 7 K-Line OBD2 Connector Pin 6 and 14 CAN Bus

In the first image, the OBD2 socket includes pin 7, which indicates it operates using the K-Line protocol. In the second image, pins 6 and 14 are present, meaning it uses the CAN Bus protocol.


🚀 Key Features

  • Universal Compatibility: Works with Arduino (Uno, Nano, Mega), ESP32, and other popular microcontrollers.
  • Protocol Mastery: Supports both ISO 9141-2 and ISO 14230-4 (KWP2000).
  • Advanced Initialization: Features both 5-Baud (Slow Init) and Fast Init methods.
  • Smart Detection: Automatic protocol detection logic.
  • Full Diagnostics: - Read real-time sensor data (PIDs).
    • Retrieve and Clear Stored/Pending DTCs (Diagnostic Trouble Codes).
    • Access Vehicle Info (VIN, Calibration IDs).
    • Monitor Oxygen Sensor and On-board test results.
  • Developer Friendly: Integrated debug output for real-time monitoring.

📡 Supported OBD-II Modes

The table below lists the standard OBD-II modes supported by this library. These are universal for most vehicles.

ModeDescription
01Read current live data (sensor values)
02Read freeze frame data
03Read stored Diagnostic Trouble Codes (DTCs)
04Clear DTCs and MIL reset
05Oxygen sensor test results
06On-board monitoring test results
07Read pending Diagnostic Trouble Codes
09Retrieve vehicle information (VIN, calibration)

💡 Advanced Users: These modes are standard for OBD2. However, if you have documentation for manufacturer-specific PIDs or custom communication commands for your specific vehicle, you can use the library's core functions to send those custom requests as well.


📊 Typical Data Rates

Each protocol has its own timing characteristics, which affect how many responses you can expect per second when reading data from the ECU. The values below reflect actual performance measurements based on this library’s real-world testing.

ProtocolAverage Responses per Second
ISO 9141-2~7–8 responses/sec
ISO 14230-4~8–9 responses/sec

🔎 Note: Tese values represent average conditions based on real-world testing. The actual throughput can vary depending on the ECU’s internal processing time, the specific data being requested (e.g. PID type), and system latency.


🛠️Schematics for communication

These schematics are essential because K-Line communication operates at different voltage and signal levels than microcontroller pins. The circuits ensure proper level shifting and protection for safe, stable operation.

You can choose one of the following approaches depending on your project:

🔹 Transistor-Based Schematic

This schematic uses a discrete transistor-based approach to interface the K-Line with a microcontroller. It is a simple and low-cost solution suitable for basic implementations and prototyping.

The R6 resistor in this schematic is designed for 3.3V microcontrollers. If you are using a 5V microcontroller, you need to change the R6 value to 5.3kΩ.

🔹 Comparator-Based Schematic

This design uses a low-cost comparator IC to process the K-Line signal and convert it into a clean digital level for the microcontroller. It offers a good balance between cost, simplicity, and signal reliability.

  • Can be implemented using cheap and widely available comparators such as LM393
  • Better noise immunity than discrete transistor-based designs
  • Provides well-defined logic thresholds
  • Suitable for low-budget projects that require improved signal stability
  • Slightly higher component count compared to the transistor solution, but still cost-effective

🔹 Dedicated Automotive IC Schematic

L9637D MC33290

SI9241 SN65HVDA195

This schematic category uses dedicated automotive communication ICs (e.g. L9637D, MCZ33290, Si9241, SN65HVDA195 etc.) specifically designed for K-Line / ISO 9141 applications.

  • Built-in voltage level shifting and protection
  • Fully compliant with automotive communication standards
  • Highest reliability and signal stability
  • Recommended for production-grade and long-term use designs

📦 Installation

  1. Open the Arduino IDE.
  2. Go to Sketch -> Include Library -> Manage Libraries...
  3. Search for "OBD2 K-Line".
  4. Click Install.

Manual Installation

Alternatively, download this repo as a .zip file and include it via Sketch -> Include Library -> Add .ZIP Library...


⚡ Basic Usage: Get Live Data

This example demonstrates how to read Engine RPM, Coolant Temperature, and Vehicle Speed. The library automatically handles different board architectures (AVR/ESP32).

#include "OBD2_KLine.h"

// Check for board compatibility and define Serial interface
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega2560__)
  #include <AltSoftSerial.h>
  AltSoftSerial Alt_Serial;
  OBD2_KLine KLine(Alt_Serial, 10400, 8, 9); // AVR: RX 8, TX 9
#elif defined(ESP32)
  OBD2_KLine KLine(Serial1, 10400, 10, 11); // ESP32: RX 10, TX 11
#endif

void setup() {
  Serial.begin(115200);
  
  KLine.setDebug(Serial);           // View communication logs
  KLine.setProtocol("Automatic");  // Supports ISO9141, ISO14230_Slow, ISO14230_Fast
  
  Serial.println("OBD2 System Starting...");
}

void loop() {
  if (KLine.initOBD2()) {
    int rpm = KLine.getLiveData(0x0C);        // PID 0x0C: Engine RPM
    int coolant = KLine.getLiveData(0x05);    // PID 0x05: Coolant Temp
    int speed = KLine.getLiveData(0x0D);      // PID 0x0D: Vehicle Speed

    Serial.print("RPM: "); Serial.println(rpm);
    Serial.print("Temp: "); Serial.print(coolant); Serial.println(" C");
    Serial.print("Speed: "); Serial.print(speed); Serial.println(" km/h");
  }
}

Custom PCBs designed for this library:

OBD2 K-Line PCB 1 OBD2 K-Line PCB 2

🛠️ Custom Hardware & PCBs: If you are looking for ready-to-use devices or custom-made PCBs based on this project, feel free to reach out to me via email in the Contact section below.


☕ Support My Work

If you enjoy my projects and want to support me, you can do so through the links below:

Buy Me A Coffee PayPal GitHub Sponsors


⚖️ License & Commercial Usage

This library is Dual-Licensed by MukiTech:

  • Personal / Educational: Free for non-commercial research and testing.
  • Commercial / Professional: Any usage in commercial products, for-profit services, or mass-produced hardware requires a mandatory Commercial License.

Unauthorized commercial distribution or integration into proprietary diagnostic tools is strictly prohibited and protected by international copyright laws.


📬 Contact

For information, job offers, collaboration, sponsorship, or purchasing my devices, you can contact me via email.

📧 Email: muksin.muksin04@gmail.com


Similar Projects

Discover other similar projects and AI models.

RepositoryC++
muki01/OBD2_K-line_Reader

OBD2 K-line Reader (ISO9141 and ISO14230) with microcontrollers like ESP32, Arduino.

265
Oct 6, 2026
RepositoryC++
adlerre/obd2-mqtt

OBD2 to MQTT for Home Assistant

280
Nov 12, 2026
RepositoryC++
kerpz/ArduinoHondaOBD

Collections of Arduino codes that reads and translates Honda OBD codes to ELM / OBD 2 PID codes. It also process and displays the output to a LCD or transmit the output to a bluetooth channel.

192
Feb 13, 2024
RepositoryPython
cedricp/ddt4all

OBD tool

2.0k
Nov 30, 2026
RepositoryShell
jgamblin/CarHackingTools

Install and Configure Common Car Hacking Tools.

983
May 7, 2023
RepositoryC
limiter121/esp32-obd2-emulator

Open-source OBD-II emulator based on an ESP32 + CAN transceiver IC, controllable via WiFi through a simple web UI (or via API)

507
Apr 9, 2018
RepositoryC
VaAndCob/ESP32-Bluetooth-OBD2-Gauge

DIY bluetooth obd2 gauge with ESP32 (CYD)

484
Oct 24, 2025
RepositoryC
devcoons/iso15765-canbus

Implementation of ISO15765-2 in C

201
Jun 22, 2026
RepositorySwift
kkonteh97/SwiftOBD2

🚗 Swift OBD2: Real-time vehicle diagnostics made simple. Read live data, clear trouble codes, and build custom automotive apps. Bluetooth/WiFi ready with built-in testing emulator.

165
Jan 26, 2026