Build a simple, accurate digital tachometer for your engine using an ESP32 “remote hub,” a ~$2 optocoupler, and ESPHome/Home Assistant. This guide covers wiring (alternator tacho → optocoupler → ESP32), ESPHome setup with a pulse counter, RPM calibration from real data points, optional engine-hours and engine-active entities, and a dashboard gauge.

🧭 What You’ll Build

  • ✅ ESP32 hub reading alternator pulses via an optocoupler (galvanic isolation)
  • ✅ ESPHome pulse counter sensor calibrated to true RPM
  • ✅ Optional entities: engine_hours and a binary engine_active
  • ✅ Home Assistant gauge (e.g., 0–2400 RPM) with color severities
  • ✅ Automations using RPM (overspeed alerts; gating other alerts when the engine is running)

🧰 Parts & Tools

  • ✅ ESP32 dev board (30- or 38-pin) + optional breakout/terminal board
  • ✅ Optocoupler input module (24 V version recommended for alternator signals)
  • ✅ Dupont leads / spade double-adapter (to share an existing analog tacho if needed)
  • ✅ Stable power: 12 V → 5 V DC-DC buck (boat install) or USB (bench)
  • ✅ Optional enclosure/junction box for the engine bay

🔌 Wiring Overview

  1. Optocoupler → ESP32
    • VCC (optocoupler) → ESP32 3.3 V (red)
    • OUT (optocoupler) → ESP32 GPIO25 (white)
    • GND (optocoupler) → ESP32 GND (black)
  2. Alternator / Regulator → Optocoupler input
    • ✅ Alternator W / stator / tacho terminal (or smart regulator’s tacho output) → optocoupler + input
    • ✅ Engine/alternator ground → optocoupler input
    • 💡 If sharing with an analog tacho, use a double spade adapter.
  3. ESP32 power
    • ✅ Boat: 12 V → 5 V DC-DC to the ESP32.
    • ✅ Bench: USB power is fine for testing.
💡 Quick Checks
  • ✅ Many optocoupler boards include an LED that blinks when pulses are present.
  • ✅ Confirm GPIO25 in hardware matches your ESPHome pin setting.

⚙️ ESPHome Setup (Firmware)

  1. Open ESPHome in Home Assistant → your ESP32 → Edit.
  2. Start from your existing base YAML (from your earlier ESP32 setup).
  3. Add the tachometer configuration here:
    👉 Tachometer YAML (pulse counter + calibration)
  4. Use platform: pulse_counter, pin: 25, and a calibration filter (calibrate_linear) that maps pulses-per-minute to RPM.
  5. Temporarily set logger to level: debug so you can see “pulses per minute” in logs.
  6. Save → ⋮ → Validate → ⋮ → Install → Wirelessly (OTA).
  7. Open logs and confirm the counter shows changing pulses/min with the engine running.

🧪 RPM Calibration Workflow

  1. With logger: level: debug active, start the engine.
  2. Hold the engine at known RPMs (analog tach; or a strobe app + reflective tape on the flywheel).
  3. For each RPM point, note the “pulses per minute” from the ESPHome log.
    • Example points from the video: 0 RPM → 0 PPM; 1000 RPM → ~15 200 PPM; 1200 RPM → ~18 200 PPM. Add 1–2 more points if you like (e.g., 1400–1800 RPM).
  4. Edit your YAML’s calibrate_linear pairs so the sensor reports actual RPM.
  5. Save → Validate → Install (OTA) again and verify the on-screen RPM matches your known points.
  6. Set logger back to info (don’t leave debug on; it’s chatty and slows the ESP32), then reinstall.
📎 Optional: Engine Hours & Engine Active
  • ✅ Add a template/counter for cumulative engine_hours based on RPM > 0.
  • ✅ Add a binary_sensor (engine_active) that’s on when RPM exceeds a small threshold.
  • These snippets are included at the bottom of the canonical YAML (link above). Remove them if you don’t need them.

📟 Dashboard Gauge (Home Assistant)

  1. Go to Settings → Devices & Services → ESPHome → your ESP32 and add the new entities to a dashboard.
  2. Add card → Gauge for the RPM sensor.
    • Range example: 0–2400 RPM
    • Severity example (from the video): Green to about 800, Yellow at 2000, Red from 2200 upward
  3. Optionally add the engine_active binary entity and engine_hours as secondary cards.

🚨 Useful Automations

  • ✅ Overspeed alert: If RPM > threshold → notify / siren / lights
  • ✅ Gate “low oil pressure” alerts so they only trigger when engine_active = on

🛠️ Troubleshooting

  • ✅ No pulses? Confirm you’re on the alternator’s W / stator / tacho terminal (or the smart regulator’s tacho out) and that the optocoupler LED blinks.
  • ✅ RPM unstable? Check grounds, cable terminations, and consider adding another calibration point.
  • ✅ Wrong pin? Ensure the ESPHome config uses pin: 25 if that’s how you wired it.
⚠️ Disclaimer

The information provided is for educational and informational purposes only. Perform all installations safely and correctly; consult a licensed professional for boat electrical work. Use at your own risk.

🎬 Video Transcript

Introduction

In this video we’ll set up a digital tachometer for our engine. This is another engine-monitoring project using the super-useful ESP32 microprocessor. In other projects we set up engine-temperature monitoring, oil pressure, and tank-level monitoring with an ESP32. For this tachometer, we’ll use the same ESP32.

The ESP32 functions as a remote hub with numerous ports to connect a wide variety of sensors. It collects data from these sensors and transmits it wirelessly to our central system, a Raspberry Pi running Home Assistant. If you haven’t set up an ESP32, don’t worry—I have a separate video guide dedicated to that with a quick and easy setup.

For this project we’ll use an optocoupler module that costs around two dollars and is straightforward to implement. We connect two wires from the optocoupler to the engine’s alternator, link the optocoupler to the ESP32, and perform some basic configuration in Home Assistant. The optocoupler detects electrical pulses from the alternator stator in an isolated circuit using light, enabling RPM measurement. It’s all very easy to set up.

Integrating tachometer monitoring into the smart-boat system offers several advantages: alerts when engine RPM exceeds thresholds, counting engine hours, and historical data for insights into fuel-consumption patterns based on RPM. The tachometer can also serve as a binary entity for other automations to indicate whether the engine is running. For example, the low-oil-pressure automation can check if the engine is running before deciding if low oil pressure is actually an issue. You’ll also benefit from a sleek digital gauge on your dashboard.

Wiring up ESP32 and Optocoupler

Here we have the optocoupler module. One end connects to the alternator; the other end connects to the ESP32. There’s a small LED that illuminates when there’s an input signal.

My ESP32 is already provisioned as in my ESP32 video. The red cable goes to 3.3 V, the white cable goes to pin 25, and the black cable goes to ground. On the optocoupler: the red 3.3 V cable plugs into VCC, the white cable from pin 25 plugs into OUT (the data terminal), and the black ground plugs into GND.

On the input side, the black cable comes from your engine or alternator ground. The red cable goes to the + terminal on the optocoupler and then to your alternator. On the alternator, use either the W terminal, the stator terminal, or the tacho terminal—it depends on the alternator. If you have a smart regulator, connect to its tacho output. If you need to share that connection with an existing analog tachometer, use a double spade adapter.

Normally you power the ESP32 with a buck converter (12 V to 5 V). For this demo I’m using a USB connector. That’s all that’s needed to connect the alternator tachometer to our smart-boat system.

Add to Home Assistant

In Home Assistant, we need an ESP32 already provisioned. I’m using ESPHome, and the ESP32 here is flashed with the basic YAML that ESPHome provides. To add the tachometer, scroll to the end of the YAML and paste in the tachometer configuration from my code page. I’ve included the YAML there to configure the optocoupler with the ESP32. I’ve also added some optional YAML I’ll explain in a moment.

Make sure the logger level starts at debug so we can calibrate the tachometer. Check that a logger block isn’t already present; if it is, change its level instead of adding another. The tachometer uses a pulse counter platform in ESPHome, which we’ll calibrate to become RPM. Leave everything the same: pin 25 is the pin we used in the wiring. If you changed the pin on your ESP32, this is the only thing you need to change.

For calibration, we’ll connect the optocoupler to the alternator, turn the engine on, and collect data points. For my engine, at 1000 RPM I was getting about 15,200 pulses per minute. At 1200 RPM I was getting about 18,200. You can add more points. ESPHome will calibrate a line that converts alternator pulses to engine RPM. The additional YAML I added includes engine hours and a binary sensor that indicates when the engine is active. They’re optional—remove them if you don’t need them. Save, validate, and install over-the-air.

RPM Calibration

When the logs start, look for the line showing the engine tachometer’s “received counter pulses per minute.” That’s the value we’ll calibrate against actual engine RPM. Start the engine and set it to known RPM values using your analog gauge or a strobe app with reflective tape on the flywheel. For each setpoint, note the pulses per minute and the corresponding RPM.

As a quick example at idle, I see around ~13,000 pulses per minute and about 860 RPM. For my calibration I used 0→0, 1000→15,200, and 1200→18,200. I took four points and found it reasonably accurate, but you can keep going if you like. After editing the calibration, compile and upload again. Once you finish calibration, change the logger level back to info so it doesn’t spam the logs and slow the ESP32.

Add Gauges to Dashboard

To visualize the entities, go to Settings → Integrations → ESPHome, open the device, and add the entities to a dashboard. I created a dashboard called “Tacho” for this demo. Add a Gauge card for RPM. My engine maximum is 2400 RPM, and I set severities with green around idle (~800), yellow at 2000, and red at 2200 and above. Turn the engine on and it should show the correct RPM. You’ll also see the engine_active binary entity and engine_hours, which you can use in automations.

Outro

That’s it—tachometer monitoring integrated into our smart-boat system. If you found this helpful and informative, please like the video and consider subscribing for more boating and technology projects.