Smart Boat 21: Engine Tachometer with ESP32 and Optocoupler

3 min read 2 hours ago
Published on Oct 11, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

In this tutorial, we will learn how to set up a digital tachometer for your engine using the ESP32 microprocessor and an optocoupler. This project allows you to monitor your engine's RPM wirelessly by collecting data through various sensors connected to the ESP32 and transmitting it to a Raspberry Pi running Home Assistant. We will walk through the wiring process, configuration in Home Assistant, RPM calibration, and adding gauges to your dashboard.

Step 1: Gather Required Components

Before starting, ensure you have the following components:

  • ESP32 (38 pins recommended)
  • Optocoupler module (select 24V version)
  • 12V to 5V converter
  • Dupont breakout cables
  • Junction box (80mm x 80mm recommended)

You can purchase these components from the following links:

Step 2: Wiring the ESP32 and Optocoupler

  1. Connect the Optocoupler to the Engine:

    • Identify the two wires from the engine's alternator.
    • Connect these wires to the input side of the optocoupler.
  2. Wire the Optocoupler to the ESP32:

    • Connect the output of the optocoupler to a GPIO pin on the ESP32.
    • Ensure to connect the ground of the optocoupler to the ground of the ESP32.
  3. Power the ESP32:

    • Use the 12V to 5V converter to power the ESP32 from your boat's electrical system.

Step 3: Configuring Home Assistant

  1. Install Home Assistant on your Raspberry Pi if you haven't already.

  2. Add ESP32 as a Device:

    • Use the ESPHome integration to configure the ESP32.
    • Create a new configuration file for the ESP32.
  3. Code Example: Here’s a basic code snippet for the ESP32 configuration:

    esphome:
      name: boat_tachometer
      platform: ESP32
      board: esp32dev
    
    wifi:
      ssid: "your_wifi_ssid"
      password: "your_wifi_password"
    
    sensor:
      - platform: pulse_counter
        pin: GPIO12
        name: "Engine RPM"
        update_interval: 1s
    
  4. Upload the Configuration to the ESP32 using USB or OTA (Over-The-Air) methods.

Step 4: RPM Calibration

  1. Access the Dashboard in Home Assistant.
  2. Calibrate the RPM Sensor:
    • Start the engine and note the RPM displayed on the dashboard.
    • Adjust the pulse counter settings if necessary until the display matches the actual RPM.

Step 5: Add Gauges to the Dashboard

  1. Edit the Home Assistant Dashboard:

    • Navigate to your dashboard settings.
    • Add a new card for the RPM sensor.
    • Choose the gauge card type for visual representation.
  2. Customize the Gauge:

    • Set the minimum and maximum values according to your engine's specifications.
    • Adjust the color and style to match your preference.

Conclusion

You have successfully set up a digital tachometer for your engine using the ESP32 and optocoupler. You can now monitor your engine's RPM wirelessly from your Home Assistant dashboard. As a next step, consider exploring additional sensors to further enhance your engine monitoring capabilities. Happy boating!