Community project

ESP32 Eight-Channel Relay Tester

BERNSS

Published August 24, 2026

ESP32
Photo of ESP32 Eight-Channel Relay TesterGenerated with AI

This guide builds an eight-channel relay tester that validates each relay independently using an ESP32 microcontroller. The tester uses NPN transistors as low-side switches to control a JD-VCC relay module, allowing safe verification of relay operation without connecting any load circuits. Readers will receive a complete wiring diagram, parts list, and step-by-step assembly instructions.

The firmware cycles through each relay channel, energizing them one at a time and logging results to the serial monitor. This systematic approach makes it easy to identify any faulty relays or wiring issues before deploying the module in a real application. No external load or mains power is required—just the ESP32, relay module, transistors, resistors, and a regulated 5 V power supply.

Wiring diagram

Interactive · read-only
Wiring diagram for ESP32 Eight-Channel Relay Tester

Pan and zoom to explore the wiring. Remix the project to edit it in your own workspace.

Parts list

Bill of materials
ComponentQtyNotes
8-channel 5 V relay module with JD-VCC8 channels, 5 V1A ready-made board with eight relays that switches separate loads using its IN1 through IN8 control terminals.
Regulated 5 V, 2 A DC power supply5 V, 2 A1An external regulated supply that provides the 5 V power required by the relay board and its relay coils.
NPN Transistor (2N2222 / BC547)2N22221General-purpose NPN bipolar junction transistor (BJT) in TO-92 package. Used as a low-side switch to drive loads (e.g. buzzers) whose current exceeds ESP32 GPIO source capability (~12 mA). A ~1 kΩ base resistor is placed between the ESP32 GPIO and the transistor base. The collector connects to the load negative terminal (buzzer –), and the emitter connects to GND. When the GPIO goes HIGH (3.3 V), the transistor saturates and switches the load on. Compatible with both 2N2222/2N2222A and BC547/BC547B variants. Add a flyback diode (e.g. 1N4148) across inductive load terminals.
NPN Transistor (2N2222 / BC547)2N22221General-purpose NPN bipolar junction transistor (BJT) in TO-92 package. Used as a low-side switch to drive loads (e.g. buzzers) whose current exceeds ESP32 GPIO source capability (~12 mA). A ~1 kΩ base resistor is placed between the ESP32 GPIO and the transistor base. The collector connects to the load negative terminal (buzzer –), and the emitter connects to GND. When the GPIO goes HIGH (3.3 V), the transistor saturates and switches the load on. Compatible with both 2N2222/2N2222A and BC547/BC547B variants. Add a flyback diode (e.g. 1N4148) across inductive load terminals.
NPN Transistor (2N2222 / BC547)2N22221General-purpose NPN bipolar junction transistor (BJT) in TO-92 package. Used as a low-side switch to drive loads (e.g. buzzers) whose current exceeds ESP32 GPIO source capability (~12 mA). A ~1 kΩ base resistor is placed between the ESP32 GPIO and the transistor base. The collector connects to the load negative terminal (buzzer –), and the emitter connects to GND. When the GPIO goes HIGH (3.3 V), the transistor saturates and switches the load on. Compatible with both 2N2222/2N2222A and BC547/BC547B variants. Add a flyback diode (e.g. 1N4148) across inductive load terminals.
NPN Transistor (2N2222 / BC547)2N22221General-purpose NPN bipolar junction transistor (BJT) in TO-92 package. Used as a low-side switch to drive loads (e.g. buzzers) whose current exceeds ESP32 GPIO source capability (~12 mA). A ~1 kΩ base resistor is placed between the ESP32 GPIO and the transistor base. The collector connects to the load negative terminal (buzzer –), and the emitter connects to GND. When the GPIO goes HIGH (3.3 V), the transistor saturates and switches the load on. Compatible with both 2N2222/2N2222A and BC547/BC547B variants. Add a flyback diode (e.g. 1N4148) across inductive load terminals.
NPN Transistor (2N2222 / BC547)2N22221General-purpose NPN bipolar junction transistor (BJT) in TO-92 package. Used as a low-side switch to drive loads (e.g. buzzers) whose current exceeds ESP32 GPIO source capability (~12 mA). A ~1 kΩ base resistor is placed between the ESP32 GPIO and the transistor base. The collector connects to the load negative terminal (buzzer –), and the emitter connects to GND. When the GPIO goes HIGH (3.3 V), the transistor saturates and switches the load on. Compatible with both 2N2222/2N2222A and BC547/BC547B variants. Add a flyback diode (e.g. 1N4148) across inductive load terminals.
NPN Transistor (2N2222 / BC547)2N22221General-purpose NPN bipolar junction transistor (BJT) in TO-92 package. Used as a low-side switch to drive loads (e.g. buzzers) whose current exceeds ESP32 GPIO source capability (~12 mA). A ~1 kΩ base resistor is placed between the ESP32 GPIO and the transistor base. The collector connects to the load negative terminal (buzzer –), and the emitter connects to GND. When the GPIO goes HIGH (3.3 V), the transistor saturates and switches the load on. Compatible with both 2N2222/2N2222A and BC547/BC547B variants. Add a flyback diode (e.g. 1N4148) across inductive load terminals.
NPN Transistor (2N2222 / BC547)2N22221General-purpose NPN bipolar junction transistor (BJT) in TO-92 package. Used as a low-side switch to drive loads (e.g. buzzers) whose current exceeds ESP32 GPIO source capability (~12 mA). A ~1 kΩ base resistor is placed between the ESP32 GPIO and the transistor base. The collector connects to the load negative terminal (buzzer –), and the emitter connects to GND. When the GPIO goes HIGH (3.3 V), the transistor saturates and switches the load on. Compatible with both 2N2222/2N2222A and BC547/BC547B variants. Add a flyback diode (e.g. 1N4148) across inductive load terminals.
NPN Transistor (2N2222 / BC547)2N22221General-purpose NPN bipolar junction transistor (BJT) in TO-92 package. Used as a low-side switch to drive loads (e.g. buzzers) whose current exceeds ESP32 GPIO source capability (~12 mA). A ~1 kΩ base resistor is placed between the ESP32 GPIO and the transistor base. The collector connects to the load negative terminal (buzzer –), and the emitter connects to GND. When the GPIO goes HIGH (3.3 V), the transistor saturates and switches the load on. Compatible with both 2N2222/2N2222A and BC547/BC547B variants. Add a flyback diode (e.g. 1N4148) across inductive load terminals.
1 kΩ resistor1 kΩ1A small resistor that limits current from ESP32 GPIO16 into the first transistor.
1 kΩ resistor1 kΩ1A small resistor that limits current from ESP32 GPIO17 into the second transistor.
1 kΩ resistor1 kΩ1A small resistor that limits current from ESP32 GPIO18 into the third transistor.
1 kΩ resistor1 kΩ1A small resistor that limits current from ESP32 GPIO19 into the fourth transistor.
1 kΩ resistor1 kΩ1A small resistor that limits current from ESP32 GPIO21 into the fifth transistor.
1 kΩ resistor1 kΩ1A small resistor that limits current from ESP32 GPIO22 into the sixth transistor.
1 kΩ resistor1 kΩ1A small resistor that limits current from ESP32 GPIO23 into the seventh transistor.
1 kΩ resistor1 kΩ1A small resistor that limits current from ESP32 GPIO25 into the eighth transistor.

Assembly

6 steps
  1. Leave the relay screw terminals empty for the first test

    Do not connect lamps, motors, wall power, or any other load to the relay screw terminals yet. This first test only checks that each relay clicks and its small channel light turns on.

    • Tip: Place the relay module where you can see all eight small channel indicator lights.
    • Do not put wall power on the relay terminals while learning this test — a wiring mistake can cause electric shock, fire, or damage.
  2. Place the eight resistors and transistors

    Put the eight 1 kΩ resistors and eight 2N2222 transistors on a breadboard, leaving space between each channel. Keep each resistor with its matching transistor: R1 with Q1 through R8 with Q8. Before wiring, check the data sheet or package marking for your exact transistor’s flat-side pin order; different 2N2222 package styles can have different leg orders. Identify the base, collector, and emitter before applying power.

    • Tip: Mark the transistor channels 1 through 8 with tape so the matching wires do not get mixed up.
    • Putting a transistor in with the wrong legs connected can prevent the relay from working and can stress the ESP32 output pin.
  3. Wire the eight ESP32 control paths

    With the ESP32 unplugged, wire GPIO16 → R1 → Q1 base (control), GPIO17 → R2 → Q2 base (control), GPIO18 → R3 → Q3 base (control), GPIO19 → R4 → Q4 base (control), GPIO21 → R5 → Q5 base (control), GPIO22 → R6 → Q6 base (control), GPIO23 → R7 → Q7 base (control), and GPIO25 → R8 → Q8 base (control). Each resistor must be in series between its ESP32 pin and transistor base; it limits the small control current.

    • Tip: A resistor has no positive or negative end, so either leg can face the ESP32.
    • Do not connect an ESP32 GPIO straight to a transistor base without its 1 kΩ resistor — the resistor protects the ESP32 pin.
  4. Connect the transistor outputs to the relay inputs

    Connect Q1 collector → relay IN1 (signal), Q2 collector → IN2 (signal), Q3 collector → IN3 (signal), Q4 collector → IN4 (signal), Q5 collector → IN5 (signal), Q6 collector → IN6 (signal), Q7 collector → IN7 (signal), and Q8 collector → IN8 (signal). Connect every transistor emitter → ESP32 GND (ground). These transistors pull a relay input down to ground to turn its channel on.

    • Tip: Keep the channel numbers matched from resistor to transistor to relay input; this makes the click sequence easy to verify.
    • Do not connect the relay’s 5 V VCC terminal to any ESP32 GPIO or to the ESP32 3V3 terminal — 5 V on an ESP32 signal pin can damage it.
  5. Power the relay board from the external 5 V supply

    Connect external supply +5V → relay VCC (relay input-side power) and external supply +5V → relay JD-VCC (relay coil power). Connect external supply GND → relay GND (ground) and external supply GND → ESP32 GND (shared ground). If the module has a VCC-to-JD-VCC jumper fitted, remove it before making these two separate +5 V connections. The ESP32 remains powered from its USB cable.

    • Tip: Use a regulated 5 V supply rated for at least 2 A because all eight relays can be switched on together during the test.
    • Make sure +5 V and GND are not swapped — swapped power can damage the relay board. Do not feed the external 5 V supply into the ESP32 3V3 pin.
  6. Run the relay click test

    Plug the ESP32 into USB, then turn on the external 5 V relay supply. Press Schematik’s Deploy button. The program switches relay 1 through relay 8 on one at a time, then turns all eight on briefly before repeating.

    • Tip: You should hear one click at a time and see the matching relay indicator light. The serial output names the channel currently being tested.
    • If a relay stays on unexpectedly, unplug the ESP32 USB cable and turn off the external 5 V supply before changing wires.

Pin assignments

Board wiring reference
PinConnectionType
EXTsupply5v_1 +5V8-channel 5 V relay module with JD-VCC VCCpower
EXTsupply5v_1 +5V8-channel 5 V relay module with JD-VCC JD-VCCpower
GNDsupply5v_1 GNDground
GNDrelay8_1 GNDground
GNDq1 EMITTERground
GNDq2 EMITTERground
GNDq3 EMITTERground
GNDq4 EMITTERground
GNDq5 EMITTERground
GNDq6 EMITTERground
GNDq7 EMITTERground
GNDq8 EMITTERground
GPIO 16r1 END1digital
EXTr1 END2NPN Transistor (2N2222 / BC547) BASEdigital
EXTq1 COLLECTOR8-channel 5 V relay module with JD-VCC IN1digital
GPIO 17r2 END1digital
EXTr2 END2NPN Transistor (2N2222 / BC547) BASEdigital
EXTq2 COLLECTOR8-channel 5 V relay module with JD-VCC IN2digital
GPIO 18r3 END1digital
EXTr3 END2NPN Transistor (2N2222 / BC547) BASEdigital
EXTq3 COLLECTOR8-channel 5 V relay module with JD-VCC IN3digital
GPIO 19r4 END1digital
EXTr4 END2NPN Transistor (2N2222 / BC547) BASEdigital
EXTq4 COLLECTOR8-channel 5 V relay module with JD-VCC IN4digital
GPIO 21r5 END1digital
EXTr5 END2NPN Transistor (2N2222 / BC547) BASEdigital
EXTq5 COLLECTOR8-channel 5 V relay module with JD-VCC IN5digital
GPIO 22r6 END1digital
EXTr6 END2NPN Transistor (2N2222 / BC547) BASEdigital
EXTq6 COLLECTOR8-channel 5 V relay module with JD-VCC IN6digital
GPIO 23r7 END1digital
EXTr7 END2NPN Transistor (2N2222 / BC547) BASEdigital
EXTq7 COLLECTOR8-channel 5 V relay module with JD-VCC IN7digital
GPIO 25r8 END1digital
EXTr8 END2NPN Transistor (2N2222 / BC547) BASEdigital
EXTq8 COLLECTOR8-channel 5 V relay module with JD-VCC IN8digital

Firmware

ESP32
main.cppDeploy to device
#include <Arduino.h>
// ESP32 eight-channel relay test through eight 2N2222 transistor switches.
// Each ESP32 HIGH passes through a 1 kΩ base resistor, turns its 2N2222 on,
// and pulls the matching active-low relay input to ground.


// Forward declarations
void setAllRelays(bool on);

const uint8_t RELAY_1_PIN = 16;
const uint8_t RELAY_2_PIN = 17;
const uint8_t RELAY_3_PIN = 18;
const uint8_t RELAY_4_PIN = 19;
const uint8_t RELAY_5_PIN = 21;
const uint8_t RELAY_6_PIN = 22;
const uint8_t RELAY_7_PIN = 23;
const uint8_t RELAY_8_PIN = 25;

const uint8_t relayPins[] = {
  RELAY_1_PIN, RELAY_2_PIN, RELAY_3_PIN, RELAY_4_PIN,
  RELAY_5_PIN, RELAY_6_PIN, RELAY_7_PIN, RELAY_8_PIN
};
const uint8_t RELAY_COUNT = sizeof(relayPins) / sizeof(relayPins[0]);
const unsigned long RELAY_ON_MS = 700;
const unsigned long GAP_MS = 300;
const unsigned long ALL_ON_MS = 1000;
const unsigned long ROUND_PAUSE_MS = 3000;

void setAllRelays(bool on) {
  for (uint8_t i = 0; i < RELAY_COUNT; i++) {
    digitalWrite(relayPins[i], on ? HIGH : LOW);
  }
}

void setup() {
  Serial.begin(115200);
  for (uint8_t i = 0; i < RELAY_COUNT; i++) {
    pinMode(relayPins[i], OUTPUT);
    digitalWrite(relayPins[i], LOW); // Transistor off: relay input stays high, relay off.
  }
  Serial.println("8-channel relay test ready. No mains load is required for this test.");
}

void loop() {
  for (uint8_t i = 0; i < RELAY_COUNT; i++) {
    Serial.printf("Testing relay %u\n", i + 1);
    digitalWrite(relayPins[i], HIGH);
    delay(RELAY_ON_MS);
    digitalWrite(relayPins[i], LOW);
    delay(GAP_MS);
  }

  Serial.println("Testing all relays together");
  setAllRelays(true);
  delay(ALL_ON_MS);
  setAllRelays(false);

  Serial.println("Round complete; all relays off.");
  delay(ROUND_PAUSE_MS);
}

“Deploy to device” opens this project in Schematik, where you can flash it to your board over USB.

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