Hello! Please Need Help with Relay and Seeed Studio XIAO ESP32S3 Sense

Hello, Need help figuring the relay issue.

Im a beginner , to ESP32, and HomeAssistant, so please help if my configuration, code or anything is wrong.

I’m trying to turn on a relay connected to NO side to a 12V DC LED Strip from Seeed Studio XIAO ESP32S3 Sense.

Here is the diagram from the original project.


r/homeassistant - LED Strip Diagram

LED Strip Diagram


r/homeassistant - DHT22 Diagram

DHT22 Diagram

Both the Relay and DHT22 share a ground, I’m not sure this is how it shgould be done, but please corect me if this is wrong.

Here is the yaml code:

esphome:
  name: "gpio switch"
  friendly_name: prusa-esp-camera

  platformio_options:
    build_flags: -DBOARD_HAS_PSRAM
    board_build.arduino.memory_type: qio_opi
    board_build.f_flash: 80000000L
    board_build.flash_mode: qio 

esp32:
  board: esp32-s3-devkitc-1
  framework:
    type: arduino

switch:
  - platform: gpio
    name: "LED Light"
    id: relay
    pin: 
      number: GPIO4
      mode: 
        output: True
      inverted: False

sensor:
  - platform: dht
    pin: GPIO1
    temperature:
      name: "Temperature"
    humidity:
      name: "Humidity"
    update_interval: 10s
    model: AUTO_DETECT

When the Board is powered on the Relay get powered on as well by default, I do see the green LED lighjts up a little more brighter when the switch is in ON position.

Voltage bwteen VCC and GND on the Relay =5.15V

Swich Off:
Relay Current between GND-IN = 3.6mA
Relay Voltage between GND-IN = 0.13V

Swich ON:
Relay Current between GND-IN = 47.7 mA
Relay Voltage between GND-IN = 3.33V

Wrong relay for your setup.
Your Esp is 3.3V device and that relay circuit is made for 5V signal.
So your relay never turns completely off and eventually it’s going to fry your Esp32 Gpio sinking 5V to it.

You can try powering relay at 3.3V. Might work, might not.
Or if you like tinkering, put NPN transistor on relay input.

Thank you for replying.

Okay, I may be completely wrong here but trying to learn and understand.

My understanding is that I would need a 5V relay if I want to connect to 5V rail on esp32 to the relay. But you are saying I need a 3.3V relay because the IN signal it’s getting is 3.3V?

I’m new and still trying to learn so I might not try the NPN Transistor just yet.

I am saying that your relay module is not compatible with your board.
It’s 5V relay and it doesn’t have circuit to be triggered with 0-3.3V signal.
It needs 5V signal to turn it off. And 0V signal to turn it on.
With 3.3V signal it’s not completely off. With 0V signal it’s completely on, but it sinks 5V to your Esp and eventually fries it.

It might work powered at 3.3V, you can try.

Otherwise buy a 3.3V relay module.
Edit: even better would be 12V relay module with separate 3.3V trigger circuit
or even better, use mosfet switch:
https://www.amazon.com/Anmbest-High-Power-Adjustment-Electronic-Brightness/dp/B07NWD8W26/?th=1

Thank you for your support and posting suggesstions. I will try the MOSFET route as a proper solution.

For now this 5V 30Amp Relay works well and switches as expected.

For your use case mosfet is the most efficient choice (and most silent). :wink:

okay, you got me there, efficient and silent.

If I replace the Relay with a mosfet, could you please share the what would the wiring layout of the circuit and the yaml code for that component?

To switch on/off you can use same yaml that you use with relay.
Esp gnd to gnd, esp gpio to input signal.

If your strip supports pwm dimming (and you want), use esphome light component

1 Like