Community project

Isolated ESP32 Motorcycle Tachometer

Photo of Isolated ESP32 Motorcycle Tachometer

Cyril Stephan

Last updated October 14, 2026

Build an isolated motorcycle tachometer that displays engine RPM on a vibrant 1.28-inch round TFT display. The ESP32 microcontroller reads ignition pulses through an optocoupler-isolated input circuit, protecting the board from high-voltage motorcycle electrical noise while accurately measuring engine speed.

This guide provides a complete wiring diagram, parts list, and step-by-step assembly instructions. The included Arduino firmware handles pulse detection with debouncing, calculates RPM in real time, and renders a custom gauge interface on the circular display. Builders will learn how to safely integrate automotive sensors with microcontroller projects using galvanic isolation.

Wiring diagram

Wiring diagram for Isolated ESP32 Motorcycle Tachometer
Loading diagram…

Gather all the parts

QtyComponent
1

GC9A01 Round TFT LCD 1.28 inch 240x240

1.28 inch round IPS TFT LCD display module with GC9A01/GC9A01A driver IC. 240x240 RGB resolution, 4-wire SPI interface, and 3.3V/5V module input. Module-side labels are VCC, GND, DIN, CLK, CS, DC, RST, and BL/BLK. The display is write-only over SPI, so no MISO line is required for the LCD. Supported by Adafruit GC9A01A and TFT_eSPI libraries in Arduino-compatible firmware projects.

1

PC817 Optocoupler

Single-channel optocoupler (opto-isolator) in a 4-pin DIP package. Galvanically isolates a low-voltage logic side from a separate circuit by coupling an internal infrared LED to a phototransistor across an insulating gap (isolation voltage ~5 kV). Used to read a higher-voltage signal safely, switch between circuits with different grounds, or shield a microcontroller from a noisy or mains-referenced domain. The input LED needs a series current-limiting resistor (~1 kOhm from a 5 V signal, ~220-330 Ohm from 3.3 V) sized for ~5-20 mA forward current; the output transistor is typically wired open-collector with a pull-up to the MCU side.

1

10 kΩ resistor

10 kΩ

A fixed resistor that keeps the tachometer input high when the optocoupler is off.

1

22 kΩ 3 W resistor

22 kΩ, 3 W

A high-power resistor that limits current from the floating ignition pickup loop into the optocoupler LED.

1

1N4148 diode

1N4148

A small diode connected across the optocoupler LED in reverse to protect it from reverse ignition pulses.

1

Boucle de pickup inductif isolée

Une boucle de fil isolé enroulée autour du câble de bougie pour détecter les impulsions d’allumage sans connexion électrique au moteur.

Assemble it in 5 steps

1. Coupez l’alimentation avant de câbler

Débranchez le câble USB. Posez l’ESP32, l’écran et la petite carte du capteur sur une surface non conductrice afin qu’aucun fil nu ne puisse se toucher.

  • Ne raccordez jamais la boucle de pickup directement au câble haute tension de la bougie : elle doit seulement être enroulée autour de son isolation.

2. Branchez l’écran rond

Reliez VCC de l’écran au pin 3V3 de l’ESP32 (alimentation), GND au pin GND (retour), SCL à GPIO18 (horloge), SDA à GPIO23 (données), CS à GPIO25 (sélection), DC à GPIO4 (commande/données) et RST à GPIO27 (remise à zéro).

  • Sur cet écran, les marquages SCL et SDA correspondent aux fils SPI SCK et MOSI, pas aux broches I²C de l’ESP32. Utilisez des fils courts.
  • Assurez-vous que VCC et GND ne sont pas inversés : une alimentation inversée ou du 5 V sur un écran 3,3 V peut l’endommager.

3. Montez la sortie du capteur RPM

Sur la perfboard, reliez l’émetteur du PC817 au GND de l’ESP32 (retour), puis le collecteur à GPIO22 (signal). Reliez une patte de la résistance 10 kΩ au collecteur du PC817 et son autre patte au 3V3 de l’ESP32 (maintient le signal haut au repos).

  • Le PC817 vu avec l’encoche vers le haut a les broches 1 et 2 à gauche, 3 et 4 à droite : vérifiez la fiche de votre pièce avant de souder.

4. Montez la boucle de pickup isolée

Reliez Loop A de la boucle au premier côté de la résistance 22 kΩ, puis le second côté de cette résistance à l’anode du PC817. Reliez Loop B à la cathode du PC817. Placez la 1N4148 en parallèle inverse : extrémité sans trait vers la cathode du PC817, extrémité avec trait noir vers l’anode du PC817.

  • Ne reliez ni Loop A ni Loop B au GND ESP32, au négatif de la batterie ou au cadre de la moto : les deux fils doivent rester flottants.

5. Faites le premier essai écran

Alimentez l’ESP32 par USB, sans connecter encore la boucle autour du câble de bougie. L’écran doit afficher « DTR 125 », « TACHO », « Tr/min » et la valeur 0.

  • Si l’écran reste gris ou montre une ligne, contrôlez d’abord DC vers GPIO4, RST vers GPIO27, VCC vers 3V3 et GND vers GND.

Review all connections

1. Connections between "tft_gc9a01_1" and "ESP32"

Functiontft_gc9a01_1ESP32
powerVCC3V3
groundGNDGND
spiSCKGPIO 18
spiMOSIGPIO 23
spiCSGPIO 25
digitalDCGPIO 4
digitalRSTGPIO 27

2. Connections between "pc817_1" and "ESP32"

Functionpc817_1ESP32
digitalAnode → 22 kΩ 3 W resistor End 2EXT
digitalCollectorGPIO 22
groundEmitterGND
groundCathode → Boucle de pickup inductif isolée Loop BEXT

3. Connections between "pullup_10k_1" and "ESP32"

Functionpullup_10k_1ESP32
powerEnd 23V3
digitalEnd 1 → PC817 Optocoupler CollectorEXT

4. Connections between "reverse_diode_1n4148_1" and "ESP32"

Functionreverse_diode_1n4148_1ESP32
digitalAnode → PC817 Optocoupler CathodeEXT
digitalCathode → PC817 Optocoupler AnodeEXT

5. Connections between "pickup_resistor_22k_1" and "ESP32"

Functionpickup_resistor_22k_1ESP32
digitalEnd 1 → Boucle de pickup inductif isolée Loop AEXT

Deploy the firmware

#include <Arduino.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_GC9A01A.h>

constexpr int TFT_CS = 25;
constexpr int TFT_DC = 4;
constexpr int TFT_RST = 27;
constexpr int TFT_SCK = 18;
constexpr int TFT_MISO = 19; // Ajouté pour éviter le crash du SPI
constexpr int TFT_MOSI = 23;
constexpr int PIN_RPM = 22;

constexpr uint32_t PULSES_PER_REVOLUTION = 1;
constexpr uint32_t MIN_PULSE_INTERVAL_US = 2000;
constexpr uint32_t RPM_TIMEOUT_MS = 1500;

Adafruit_GC9A01A tft(TFT_CS, TFT_DC, TFT_RST);

volatile uint32_t pulseCount = 0;
volatile uint32_t lastPulseUs = 0;

uint32_t lastSampleMs = 0;
uint32_t lastDisplayRpm = UINT32_MAX;
uint32_t displayedRpm = 0;

void IRAM_ATTR onTachPulse() {
  const uint32_t nowUs = micros();
  if ((uint32_t)(nowUs - lastPulseUs) >= MIN_PULSE_INTERVAL_US) {
    pulseCount++;
    lastPulseUs = nowUs;
  }
}

void drawStaticScreen() {
  tft.fillScreen(GC9A01A_BLACK);
  tft.drawCircle(120, 120, 118, GC9A01A_BLUE);
  tft.drawCircle(120, 120, 116, GC9A01A_DARKGREY);

  tft.setTextColor(GC9A01A_CYAN);
  tft.setTextSize(2);
  tft.setCursor(70, 50);
  tft.print("DTX 125");

  tft.setTextColor(GC9A01A_WHITE);
  tft.setTextSize(2);
  tft.setCursor(86, 78);
  tft.print("TACHO");

  tft.setTextColor(GC9A01A_LIGHTGREY);
  tft.setTextSize(2);
  tft.setCursor(98, 168);
  tft.print("Tr/min");
}

void drawRpm(uint32_t rpm) {
  tft.fillRect(25, 100, 190, 52, GC9A01A_BLACK);
  tft.setTextColor(GC9A01A_GREEN);
  tft.setTextSize(5);

  char text[12];
  snprintf(text, sizeof(text), "%lu", static_cast<unsigned long>(rpm));
  
  // Correction du centrage : à la taille 5, un caractère fait 30 pixels de large (5 * 6)
  const int16_t x = 120 - ((strlen(text) * 30) / 2); 
  tft.setCursor(x, 112);
  tft.print(text);
}

void setup() {
  Serial.begin(115200);
  delay(500); // Laisse le temps au port série de se stabiliser
  
  pinMode(PIN_RPM, INPUT_PULLUP);

  // Initialisation SPI avec la broche MISO officielle pour stabiliser le pilote
  SPI.begin(TFT_SCK, TFT_MISO, TFT_MOSI, TFT_CS);
  tft.begin();
  tft.setRotation(0);
  drawStaticScreen();
  drawRpm(0);

  attachInterrupt(digitalPinToInterrupt(PIN_RPM), onTachPulse, FALLING);
  lastSampleMs = millis();
  Serial.println("DTR 125 tachometer ready");
}

void loop() {
  const uint32_t nowMs = millis();
  if ((uint32_t)(nowMs - lastSampleMs) < 500) {
    return;
  }

  uint32_t count;
  uint32_t lastPulse;
  noInterrupts();
  count = pulseCount;
  pulseCount = 0;
  lastPulse = lastPulseUs;
  interrupts();

  const uint32_t elapsedMs = nowMs - lastSampleMs;
  lastSampleMs = nowMs;

  if (lastPulse == 0 || (uint32_t)(micros() - lastPulse) > RPM_TIMEOUT_MS * 1000UL) {
    displayedRpm = 0;
  } else {
    displayedRpm = (count * 60000UL) / (elapsedMs * PULSES_PER_REVOLUTION);
  }

  if (displayedRpm != lastDisplayRpm) {
    drawRpm(displayedRpm);
    lastDisplayRpm = displayedRpm;
    Serial.printf("RPM: %lu\n", static_cast<unsigned long>(displayedRpm));
  }
}

Remix this project

Make it yours in one click

Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.

Open in Schematik