How to control a relay from an ESP32 with the TCR-102 (no transistor needed)

Switching a 230 V lamp, pump or heater from an ESP32 usually means an extra transistor, a flyback diode and a relay module that is not designed for a control cabinet. With the TCR-102 you connect the GPIO pin straight to the relay input. Each input draws only 30–55 µA, so the ESP32 drives it without any extra parts. Everything mounts on a standard TS35 DIN rail.

This guide shows a complete 12 V setup: one power supply feeds both the relay unit and the ESP32, and you control two relays from the serial monitor.

What you need

Wiring

12 V supply +12 V GND DCC-1033 12 V in → 3.3 V out ESP32 3V3 GND GPIO25 GPIO26 TCR-102-12V 1 +12V 2 GND 3 IN1 4 IN2 9 COM1 8 NO1 10 NC1 5 NC2 · 6 NO2 · 7 COM2 Red: +12 V · Black: GND (common) · Orange: 3.3 V · Green: logic signals. Load wiring on pins 5–10 not shown.
From To Note
12 V supply + TCR-102 pin 1 (+12V) and DCC-1033 input + Relay coil supply
12 V supply GND TCR-102 pin 2 (GND) and DCC-1033 GND Common ground
DCC-1033 3.3 V out ESP32 3V3 pin Powers the ESP32
DCC-1033 GND ESP32 GND Common ground
ESP32 GPIO25 TCR-102 pin 3 (IN1) Relay 1
ESP32 GPIO26 TCR-102 pin 4 (IN2) Relay 2

The ground connection is the one people forget. The ESP32 GND must be connected to TCR-102 pin 2, otherwise the inputs have no reference and the relays will not switch reliably.

Tip: while you program the ESP32 over USB, disconnect the 3.3 V wire from the DCC-1033 so the board is not powered from two sources at once.

Connecting the load

Each relay is a changeover (SPDT) contact. For a load that should be on when the GPIO is high, wire it through COM and NO:

  • Relay 1: COM pin 9, NO pin 8, NC pin 10
  • Relay 2: COM pin 7, NO pin 6, NC pin 5

Input high energises the relay: COM connects to NO and the relay LED lights. Input low releases it: COM connects to NC. The contacts handle 250 VAC / 3 A or 30 VDC / 3 A.

Safety: 230 V mains wiring must be done by qualified personnel, in an enclosure, with the circuit protected by a suitable fuse or breaker.

Arduino code

Install the ESP32 board package in the Arduino IDE, select your board and upload the sketch below. Open the serial monitor at 115200 baud and type 1on, 1off, 2on, 2off or test.

// Elunits TCR-102 ESP32 demo
// Controls the two relays of a TCR-102 from the serial monitor.
#define FW_NAME    "Elunits TCR-102 ESP32 demo"
#define FW_VERSION "1.0.0"

const int RELAY1_PIN = 25;  // to TCR-102 pin 3 (IN1)
const int RELAY2_PIN = 26;  // to TCR-102 pin 4 (IN2)

void setRelay(int channel, bool on) {
  int pin = (channel == 1) ? RELAY1_PIN : RELAY2_PIN;
  digitalWrite(pin, on ? HIGH : LOW);
  Serial.printf("Relay %d %s\n", channel, on ? "ON  (COM-NO)" : "OFF (COM-NC)");
}

void runTest() {
  for (int ch = 1; ch <= 2; ch++) {
    setRelay(ch, true);
    delay(1000);
    setRelay(ch, false);
    delay(500);
  }
}

void setup() {
  Serial.begin(115200);
  delay(200);
  Serial.println(FW_NAME " v" FW_VERSION);   // first line: name and version

  pinMode(RELAY1_PIN, OUTPUT);
  pinMode(RELAY2_PIN, OUTPUT);
  digitalWrite(RELAY1_PIN, LOW);   // both relays off at start
  digitalWrite(RELAY2_PIN, LOW);

  Serial.println("Commands: 1on, 1off, 2on, 2off, test");
}

void loop() {
  if (!Serial.available()) return;

  String cmd = Serial.readStringUntil('\n');
  cmd.trim();
  cmd.toLowerCase();

  if      (cmd == "1on")  setRelay(1, true);
  else if (cmd == "1off") setRelay(1, false);
  else if (cmd == "2on")  setRelay(2, true);
  else if (cmd == "2off") setRelay(2, false);
  else if (cmd == "test") runTest();
  else if (cmd.length())  Serial.println("Unknown command: " + cmd);
}

The first line in the serial monitor shows the sketch name and version, so you always know which firmware is running on the board.

Why no transistor is needed

A typical relay coil needs 30–80 mA, more than an ESP32 pin should deliver. The TCR-102 has its own driver stage powered from pin 1, so the logic input only sees 30–55 µA. Any 3.3 V or 5 V output works, from an ESP32, Arduino or Raspberry Pi to a PLC. The input threshold is 1.8 V, so 3.3 V logic has good margin.

Running on batteries or solar

With the status LEDs disabled by the jumpers, the TCR-102-12V draws only 7 µA when both relays are off. Combined with ESP32 deep sleep, this makes it practical for remote pumps, gates and heaters on a 12 V battery.

Troubleshooting

  • Relay does not switch: check the common ground between ESP32 and TCR-102 pin 2, and that pin 1 has 10–15 V.
  • Relay clicks at power-up: some boards let pins float during reset. Add a 100 kΩ resistor from each input to GND.
  • LED lights but load does not turn on: check that the load is wired to COM and NO, not NC.

Downloads

Questions or need a different supply voltage? Contact us at post@elunits.com.