Machine Learning • Neural Networks • Automotive Engineering

Engine Air Brace

A theoretical approach to optimize engine performance by predicting air intake needs in real-time, ensuring peak efficiency and reduced emissions. Powered by the Tensorflow neural network running on Raspberry Pi 4.This was inspired by turbo technology to maximize fuel efficiency and power output.

TensorFlow Raspberry Pi 4 Neural Networks Engine Optimization

Project Overview

Developing an intelligent system to predict and optimize engine air intake for peak performance across varying environmental conditions.

The Challenge

Engines face the challenge of maintaining optimal fuel-to-air ratios across different environments. At high elevations, reduced air density affects combustion efficiency. Traditional systems struggle to adapt in real-time, leading to suboptimal performance and increased emissions.

Inspiration

Inspired by turbocharger technology, this project aims to create an intelligent system that anticipates air intake needs, maintaining peak performance regardless of environmental conditions.

The Solution

A TensorFlow neural network trained on multiple engine sensor inputs to predict Mass Air Flow (MAF) values with high accuracy. The system runs on a Raspberry Pi 4, making it cost-effective and suitable for real-world automotive applications.

Hardware

  • • Raspberry Pi 4 (8GB)
  • • Multiple sensor inputs
  • • Real-time processing

Software

  • • TensorFlow Neural Network
  • • Python/Machine Learning
  • • Real-time prediction

Technical Architecture

Built with cutting-edge machine learning technologies for reliable, real-time engine optimization.

Neural Network

Multi-layer TensorFlow neural network trained on engine sensor data to predict MAF values with 95%+ accuracy.

Real-time Processing

Raspberry Pi 4 delivers real-time predictions with sub-millisecond latency for immediate engine adjustments.

Multi-sensor Input

Processes data from throttle position, temperature, pressure, and RPM sensors for comprehensive analysis.

Performance Results

Demonstrating exceptional accuracy and reliability across diverse testing conditions.

0.9836
R² Score
Model Accuracy
Explains 98.36% of variance in MAF predictions. Values closer to 1.0 indicate better model fit - this score demonstrates exceptional predictive accuracy.
2.96
RMSE
Root Mean Square Error
Average prediction error of 2.96 units. Lower values indicate better accuracy - this represents excellent precision for MAF sensor readings.
8.78
MSE
Mean Squared Error
Squared average of prediction errors. Lower values indicate better performance - this low MSE confirms consistent, reliable predictions.

Understanding the Metrics

R² Score (0.9836)

What it means: The model explains 98.36% of the variance in MAF values. This is exceptional - scores above 0.9 are considered excellent in machine learning.

Why it's good: Nearly perfect correlation between predictions and actual values, indicating the neural network has learned the underlying patterns effectively.

RMSE (2.9638)

What it means: On average, predictions are off by ±2.96 units from the true MAF value. This represents the typical prediction error.

Why it's excellent: For MAF sensors (typically measuring 0-500+ g/s), an error of ~3 units represents less than 1% deviation - highly precise for real-world applications.

MSE (8.7843)

What it means: The average of squared prediction errors. Penalizes larger errors more heavily than smaller ones.

Why it's good: Low MSE indicates consistent accuracy with few large prediction errors - critical for engine optimization where precision matters.

Visual Performance Analysis

MAF Prediction vs Actual Values

MAF Prediction vs True Value Chart

Neural network predictions (blue) vs actual MAF values with regression line and ideal prediction line for comparison

TensorFlow + OBD2 Integration

Real-time neural network inference with live engine data acquisition.

TensorFlow Neural Network

import tensorflow as tf
from tensorflow.lite import Interpreter
import numpy as np

# Load optimized TensorFlow Lite model
interpreter = Interpreter('maf_model.tflite')
interpreter.allocate_tensors()

def create_model():
    model = tf.keras.Sequential([
        tf.keras.layers.Dense(128, activation='relu',
                            input_shape=(8,)),
        tf.keras.layers.Dropout(0.2),
        tf.keras.layers.Dense(64, activation='relu'),
        tf.keras.layers.Dense(32, activation='relu'),
        tf.keras.layers.Dense(1, activation='linear')
    ])

    model.compile(
        optimizer='adam',
        loss='mse',
        metrics=['mae', 'accuracy']
    )
    return model

def predict_maf_realtime(sensor_data):
    # Preprocess inputs for neural network
    normalized_input = preprocess_sensors(sensor_data)

    # TensorFlow Lite inference
    input_details = interpreter.get_input_details()
    output_details = interpreter.get_output_details()

    interpreter.set_tensor(
        input_details[0]['index'],
        normalized_input
    )
    interpreter.invoke()

    prediction = interpreter.get_tensor(
        output_details[0]['index']
    )

    return denormalize_maf(prediction[0][0])

........

OBD2 Live Data Stream

import obd
import time
import threading
from collections import deque

# OBD2 connection with live monitoring
connection = obd.OBD("/dev/ttyUSB0", baudrate=38400)

# Real-time data buffer
live_data = deque(maxlen=100)

OBD_COMMANDS = {
    'rpm': obd.commands.RPM,
    'throttle': obd.commands.THROTTLE_POS,
    'maf': obd.commands.MAF,
    'intake_temp': obd.commands.INTAKE_TEMP,
    'map': obd.commands.INTAKE_PRESSURE,
    'engine_load': obd.commands.ENGINE_LOAD
}

def stream_obd2_data():
    """Continuous OBD2 data acquisition"""
    while connection.is_connected():
        sensor_readings = {}

        for sensor, command in OBD_COMMANDS.items():
            response = connection.query(command)
            if response.value:
                sensor_readings[sensor] = float(
                    response.value.magnitude
                )

        # Add timestamp for real-time tracking
        sensor_readings['timestamp'] = time.time()
        live_data.append(sensor_readings)

        # Real-time TensorFlow prediction
        if len(live_data) >= 10:
            predicted_maf = predict_maf_realtime(
                sensor_readings
            )

            # Performance comparison
            actual_maf = sensor_readings.get('maf', 0)
            efficiency = calculate_efficiency(
                predicted_maf, actual_maf
            )

            print(f"Live MAF: {actual_maf:.2f} g/s")
            print(f"Predicted: {predicted_maf:.2f} g/s")
            print(f"Efficiency: {efficiency:.1f}%")

        time.sleep(0.05)  # 20Hz sampling rate

# Start real-time monitoring
threading.Thread(
    target=stream_obd2_data,
    daemon=True
).start()

........

Key Features & Benefits

Revolutionary engine optimization technology with real-world applications.

Real-time Optimization

Continuously adjusts engine parameters based on live sensor data for optimal performance under changing conditions.

High Accuracy

98.36% R² score demonstrates exceptional prediction accuracy for reliable engine management.

Cost-Effective

Raspberry Pi 4 implementation makes advanced engine optimization accessible and affordable.

Environmental Adaptability

Automatically adjusts for altitude, temperature, and atmospheric pressure changes.

Fuel Efficiency

Optimizes air-fuel mixture for maximum efficiency and reduced emissions.

Scalable Architecture

Modular design allows for easy integration with existing engine management systemstrhough the OBD- 2 port.

Technical Deep Dive

Understanding the engineering behind intelligent engine optimization.

Neural Network Architecture

Model Structure

  • Input Layer: 12 sensor inputs (throttle position, RPM, temperature, pressure, etc.)
  • Hidden Layers: Three dense layers (128, 64, 32 neurons) with ReLU activation
  • Dropout Layers: 20% dropout for regularization and overfitting prevention
  • Output Layer: Single neuron with linear activation for MAF prediction

Training Parameters

Optimizer: Adam
Loss Function: MSE
Batch Size: 32
Epochs: 25
Validation Split: 20%
Learning Rate: Adaptive

Hardware Implementation

Raspberry Pi 4

8GB RAM, ARM Cortex-A72 quad-core processor running TensorFlow Lite for optimized inference

Sensor Interface

GPIO and ADC interfaces for real-time sensor data acquisition from engine management system

Real-time Processing

Sub-millisecond inference times for immediate engine parameter adjustments

Dominique Taylor

Chemical engineer and entrepreneur with a passion for innovation and problem-solving.

Quick Links

Contact

  • Dominique.R.T13@gmail.com
  • Salt Lake City, Utah

© 2025 Dominique Taylor. All rights reserved.