Skip to content

Repository files navigation

ESP32 Sensor Module

GitHub: Carputer-project/esp32_sensor_module

Firmware for the sensor ESP32 on the Carputer PCB. Designed for OBD1 vehicles (pre-1996, all makes) — reads engine ECU sensor voltages, switch signals, and diagnostic pulses directly. No CAN bus required. CAN/OBD2 is an easy add — just a firmware update and an external CAN module (e.g. MCP2515 via SPI).

Currently configured for a Toyota 5S-FE as reference, but the voltage divider values and input pins work with any OBD1 ECU. Streams data over UDP to the carputer head unit.

Role

Connects to ECU as WiFi STA at 192.168.4.20, broadcasts JSON sensor data to 192.168.4.255:5001 (subnet broadcast so both carputer app and cluster display receive data). Also handles DTC (diagnostic trouble code) reading via the check-engine light blink pattern.

ECU Signal Wiring (5.6K + 10K Voltage Divider)

All ECU signals go through a voltage divider: R1 = 5.6KΩ (series from ECU), R2 = 10KΩ (to GND). Ratio = 0.641x. Max output: 5V × 0.641 = 3.21V (safe under 3.3V).

ECU Signal ──[5.6KΩ]──┬── ESP32 GPIO
│
[10KΩ]
│
GND

Analog Signals

GPIOECU SignalECU Pin NameADC ChannelUnitNotes
GPIO 32PIMMAP (Manifold Absolute Pressure)ADC1_CH4kPa0-5V → 0-3.21V
GPIO 33THWECT (Engine Coolant Temp)ADC1_CH5°FNTC via ECU 2.2K pullup to 5V, reversed through divider
GPIO 34VTATPS (Throttle Position Sensor)ADC1_CH6%Input-only pin

Digital Pulse Signals

GPIOECU SignalECU Pin NameEdgeCalculation
GPIO 25SPDSpeed SensorFALLING1.985 meters/pulse
GPIO 26IGfIgnition Feedback (RPM)RISINGRPM = (pulses × 1000 / elapsed_ms × 60) / 2 (4-cyl)

DTC Reader

GPIOFunctionWiringNotes
GPIO 19T/VF read5.6K+10K divider from ECU T pinMIL blink pattern, normally 5V
GPIO 22TE1 control1KΩ → base of 2N2222 NPN, collector → E1 (ECU GND), emitter → GNDPulled HIGH = TE1 → E1
GPIO 23TE2 control1KΩ → base of 2N2222 NPN, collector → E1 (ECU GND), emitter → GNDPulled HIGH = TE2 → E1

Additional Analog Inputs

GPIOSensorCircuitRangeNotes
GPIO 35Fuel Level120Ω pullup to 3.3V, sender to GND3Ω (full) to 110Ω (empty)ADC1_CH7, inverted logic
GPIO 36Oil Pressure120Ω pullup to 3.3V, sender to GND3Ω (0 psi) to 100Ω (100 psi)ADC1_CH0
GPIO 39Narrowband O2Direct 0-1V, no divider0.1V (rich 10:1) to 0.9V (lean 17:1)~450mV = stoich 14.7:1

Door Switches (GND-Switched)

Wired with 10KΩ series resistor from switch to GPIO. Uses INPUT_PULLUP.

GPIOSensorLogic
GPIO 13Driver DoorLOW = open, HIGH = closed
GPIO 14Passenger DoorLOW = open, HIGH = closed
GPIO 27TrunkLOW = open, HIGH = closed
GPIO 21HoodLOW = open, HIGH = closed

HC-05 Bluetooth Module (UART2 Serial Bridge)

ESP32 PinHC-05 PinFunction
GPIO 16 (RX2)TXDReceives data FROM HC-05
GPIO 17 (TX2)RXDSends data TO HC-05
GPIO 4STATEHIGH = BT connected, LOW = idle
5VVCCPower
GNDGNDGround
  • Baud rate: 38400 (AT command mode)
  • Serial bridge UDP port: 5004
  • Used for ELM327 Bluetooth OBD2 adapter communication

Network Configuration

ParameterValue
WiFi SSIDCarputer_ECU
WiFi Password12345678
WiFi ModeSTA (station)
Static IP192.168.4.20
Gateway192.168.4.1
Subnet255.255.255.0
UDP send192.168.4.255:5001 (subnet broadcast)
UDP listen (commands)5002
UDP DTC results5003
UDP serial bridge5004 (HC-05/ELM327)
Sensor update rate500ms
Speed/RPM calc rate100ms

Protocol

Sensor Data (UDP 5001, broadcast)

{
"event": "sensors",
"data": {
"coolant": 185,
"oil": 212,
"ambient": 72,
"intake": 68,
"rpm": 2450,
"speed": 45,
"tps": 23,
"map": 65,
"fuel": 42,
"oilPress": 38,
"afr": 14.7,
"driverDoor": 0,
"passDoor": 0,
"trunk": 0,
"hood": 0,
"obd2FuelTrim": 0,
"obd2Load": 0,
"obd2Coolant": 0,
"obd2Rpm": 0,
"obd2Speed": 0,
"obd2FuelPress": 0,
"obd2DistDtc": 0
}
}

Commands (UDP 5002)

{"cmd": "query"}

DTC (UDP 5003)

  • Send query → reads CEL blink pattern via T/VF pin
  • Returns parsed DTC codes

Complete Pin Allocation

GPIOFunctionTypeNotes
2LED indicatorOUTPUTBuild status
4HC-05 STATEINPUTBT connection status
12Door switch (old)INPUT_PULLUPReassigned — now used in body controller
13Driver DoorINPUT_PULLUP10K series resistor
14Passenger DoorINPUT_PULLUP10K series resistor
16UART2 RX (HC-05 TXD)Serial RX238400 baud
17UART2 TX (HC-05 RXD)Serial TX238400 baud
19DTC T/VF readINPUT5.6K+10K divider
21Hood switchINPUT_PULLUP10K series resistor
22TE1 controlOUTPUT1K → 2N2222 base
23TE2 controlOUTPUT1K → 2N2222 base
25Speed (SPD)Digital interruptFALLING edge
26RPM (IGf)Digital interruptRISING edge
27Trunk switchINPUT_PULLUP10K series resistor
32MAP (PIM)ADC1_CH45.6K+10K divider
33Coolant (THW)ADC1_CH55.6K+10K divider
34TPS (VTA)ADC1_CH65.6K+10K divider (input-only)
35Fuel levelADC1_CH7120Ω pullup
36Oil pressureADC1_CH0120Ω pullup
39Narrowband O2ADC1_CH3Direct 0-1V, no divider

Parts List

ComponentValueQuantityPurpose
Resistor5.6KΩ 1/4W6Voltage divider R1 (ECU signals + T/VF)
Resistor10KΩ 1/4W11Voltage divider R2 (6) + door pullups (4) + GPIO39 fix (1)
Resistor1KΩ 1/4W6Series protection (4 doors + 2 TE switch bases)
Resistor120Ω 1/4W2Fuel level + oil pressure sender pullups
2N2222 NPN transistor2TE1/TE2 open-drain switches to ECU E1
DC-DC converterAdjustable → 3.3V1Powers ESP32 from 12V
ESP32 DevKit1Sensor module MCU

Building & Flashing

cd esp32_sensor_module
pio run # Build
pio run --target upload # Upload via USB
pio device monitor -b 115200 # Serial monitor

Related Repositories

RepoRole
carputerQt5 head unit — receives UDP sensor data
carputer-pcbPhysical PCB with J5 socket for this ESP32
carputerandroidAndroid head unit — receives same UDP data
esp32_body_controllerCreates Carputer_ECU WiFi AP, forwards sensor data
esp32_clusterTFT display — receives broadcast sensor data on UDP 5001

About

ESP32 firmware — reads Toyota 5S-FE ECU sensors (MAP, RPM, coolant, TPS, speed), door switches, DTC — streams via UDP

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages