SmartCruiseControl is an embedded ESP32 project that implements cruise control using CAN Bus data, with vehicle state monitoring and ELM327 command emulation for the Smart forfour 454 car
The software runs on an ESP32 using the Arduino framework and focuses on:
- Reading CAN Bus frames from a Smart vehicle.
- Estimating speed, RPM, distance, fuel level, and other critical vehicle parameters.
- Cruise control with PID, button-based enable/disable, and throttle override handling.
- Basic ELM327 emulation for OBD-II
01xxand22xxcommand responses. - Cruise control status indication using an LED.
- CAN Bus listen-only mode (
TWAI_MODE_LISTEN_ONLY) at 500 kbps. - Support for reading the following key CAN IDs:
0x09E- total distance0x200- speed0x208- brake intensity and extra speed data0x210- accelerator pedal position0x308- engine RPM0x408- fuel level0x416- battery voltage0x423- door status0x608- refrigerant temperature and fuel rate
- Cruise control state machine with:
STATE_OFFSTATE_ACTIVESTATE_OVERRIDE
- ELM327 interface over
Serialwith basicAT,01, and22command handling.
platformio.ini- PlatformIO configuration for ESP32.src/main.cpp- main entry point and FreeRTOS task setup.include/- constants, state definitions, and shared headers.lib/- modular libraries:can/- CAN bus reading and decoding.cruise_control/- cruise control logic.elm327/- ELM327 emulation and OBD response handling.fuel_range_estimator/- fuel range estimation.indicator_led/- PWM LED status indicator.pid_controller/- generic PID controller.speed_estimator/- speed estimation from CAN frames.throttle/- throttle output and override management.buttons/- analog button reading and cruise control button detection.
doc/- CAN Bus reverse engineering documentation.test/- PlatformIO testing notes and setup.
See requirements.md file for required software and hardware
See how-to-build.md file to build software and hardware
- The system starts by creating FreeRTOS tasks for CAN reception, CAN processing, and ELM327 emulation.
- The indicator LED shows cruise control status:
- off = cruise control disabled
- full brightness = cruise control active
- fading = throttle override active
- Cruise control buttons support
SET,RESUME, andCANCEL. - Pressing the accelerator while cruise control is active transitions the system to
STATE_OVERRIDE.
- The project is designed for the Smart Forfour 454 (2006) model, as described at the beginning of
doc/CAN bus reverse engineering.md. - With the necessary modifications, it could be adapted to other vehicles that use CAN Bus, electronic throttle, and physical brake/clutch switches.
- The implementation is based on CAN data documented in
doc/CAN bus reverse engineering.md. - The ESP32 pinout reference image is available at
doc/ESP32 pinout.pngand is used under Creative Commons BY-NC-ND via www.mischianti.org.
This project was inspired by:
See the LICENSE file for the project license terms.