D1mini not booting if connected to relay board

Hi,
I’ve connected d1mini with 8 channel relay board as output (TX, RX, D0, D3, D4, D5, D6, D7) and connected it’s D1 and D2 to MCP23017 I2C GPIO extender as inputs (to use momentary switches). When I connected to power, it’s not booting up. When I remove VCC of relay board, it’s booting and then I re-connect the relay board VCC and I can use as usual. Please find the below esphome yaml code

esphome:
  name: livingroom_panel
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: "mywifi"
  password: "mypassword"
  fast_connect: true
  # Optional manual IP
  manual_ip:
    static_ip: 192.168.1.10
    gateway: 192.168.1.1
    subnet: 255.255.255.0

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

# I2C INTERFACE
i2c:
  sda: D2
  scl: D1
  scan: False
  frequency: 400kHz

# MCP23017 Component
mcp23017:
  - id: 'mcp23017_hub'
    address: 0x20

# Switches
binary_sensor:
  - platform: gpio
    name: "Switch 1"
    pin:
      mcp23017: mcp23017_hub
      # Use pin number 0
      number: 0
      mode: INPUT_PULLUP
      inverted: True
    on_press:
      then:
      - switch.toggle: relay1
    internal: True

  - platform: gpio
    name: "Switch 2"  
    pin:
      mcp23017: mcp23017_hub
      # Use pin number 1
      number: 1
      mode: INPUT_PULLUP
      inverted: True
    on_press:
      then:
        - switch.toggle: relay2
    internal: True

  - platform: gpio
    name: "Switch 3"
    pin:
      mcp23017: mcp23017_hub
      # Use pin number 2
      number: 2
      mode: INPUT_PULLUP
      inverted: True
    on_press:
      then:
        - switch.toggle: relay3
    internal: True

  - platform: gpio
    name: "Switch 4"
    pin:
      mcp23017: mcp23017_hub
      # Use pin number 3
      number: 3
      mode: INPUT_PULLUP
      inverted: True
    on_press:
      then:
        - switch.toggle: relay4
    internal: True

  - platform: gpio
    name: "Switch 5"
    pin:
      mcp23017: mcp23017_hub
      # Use pin number 4
      number: 4
      mode: INPUT_PULLUP
      inverted: True
    on_press:
      then:
        - switch.toggle: relay5
    internal: True

  - platform: gpio
    name: "Switch 6"
    pin:
      mcp23017: mcp23017_hub
      # Use pin number 5
      number: 5
      mode: INPUT_PULLUP
      inverted: True
    on_press:
      then:
        - switch.toggle: relay6
    internal: True

  - platform: gpio
    name: "Switch 7"
    pin:
      mcp23017: mcp23017_hub
      # Use pin number 6
      number: 6
      mode: INPUT_PULLUP
      inverted: True
    on_press:
      then:
        - switch.toggle: relay7
    internal: True

# Relays
switch:
  - platform: gpio
    name: "Fan"
    pin: GPIO16
    inverted: true
    id: relay1

  - platform: gpio
    name: "Ceiling Lights"
    pin: GPIO14
    inverted: true
    id: relay2

  - platform: gpio
    name: "Lights"
    pin: GPIO12
    inverted: true
    id: relay3

  - platform: gpio
    name: "Light"
    pin: GPIO13
    inverted: true
    id: relay4

  - platform: gpio
    name: "Bulb"
    pin: GPIO1
    inverted: true
    id: relay5

  - platform: gpio
    name: "Roof Light"
    pin: GPIO3
    inverted: true
    id: relay6

  - platform: gpio
    name: "Plug"
    pin: GPIO0
    inverted: true
    id: relay7

  - platform: restart
    name: "Livingroom Panel REBOOT"

# Status Sensors
sensor:
  - platform: wifi_signal
    name: "Livingroom Panel WiFi signal"
    update_interval: 60s

  - platform: uptime
    name: "Livingroom Panel uptime"

text_sensor:
  - platform: version
    name: "Livingroom Panel ESPHome version"

Which relay board did you order?

I know this is a nodemcu board, but same results. Some pins will cause boot failures.

1 Like

Yeah GPIO0 (D3) and GPIO1 (D4) could be the problem.

It’s generic 8 relay module

Hey,
I’ve checked this board before assigning those pins. This is the reason I’ve left D8 as it’ll cause boot failure when pulled high. But I don’t understand one thing.

mode: INPUT_PULLUP
inverted: True

I’ve programmed all pins to pull high.
The documentation shows
inverted ( Optional , boolean): If all read and written values should be treated as inverted. Defaults to False .
But I don’t understand this. Is inverted: True makes the pin to pull low?

With

mode: INPUT_PULLUP
inverted: True

On = low
Off = high

That does not help determining the power requirements.

It’s a 5v relay board brought from aliexpress.
[https://www.aliexpress.com/item/32888878613.html?spm=a2g0s.9042311.0.0.27424c4dknth1N]
removed all inputs and outputs and kept 1st one and uploaded and tested,

# I2C INTERFACE
i2c:
  sda: D2
  scl: D1
  scan: False
  frequency: 400kHz

# MCP23017 Component
mcp23017:
  - id: 'mcp23017_hub'
    address: 0x20

# Switches
binary_sensor:
  - platform: gpio
    name: "Switch 1"
    pin:
      mcp23017: mcp23017_hub
      # Use pin number 0
      number: 0
      mode: INPUT_PULLUP
      inverted: True
    on_press:
      then:
      - switch.toggle: relay1
    internal: True

# Relays
switch:
  - platform: gpio
    name: "Fan"
    pin: GPIO14
    inverted: true
    id: relay1

facing same issue. Looks like it’s an issue with resistance of relay.
Relay light always turned on (less bright) for D7(GPIO13) which is not programmed and TX(GPIO1) randomly turning on and off and it’s responding when I use switch 1 to toggle relay which is connected to D0(GPIO16).
Later changed output to D5(GPIO14), same weird issue with relay connected to TX(GPIO1).

Though I removed all switches and relays, it was same. Later flashed complete code with all 7 relays and switches, board was normal (removed relay board while boot and connected after boot). But unable to boot while connected to relays.
No issue when rebooted from home assistant and booted normal.

Problem appears only when connecting to AC mains.

Notice this specification for the board:

5 V-12V to TTL control signal

The Wemos D1 only has 3.3V logic output and thus is not capable of driving the relay control lines on this board.

I’m using another chip with tasmota connected to 4 relay board with momentary switches. I thought this may work, but haven’t calculated the voltage for all 8 relays.
So, if I use a logic-level converter, can I able to make it work?
like this one.

Theoretically…

However that issue would only prevent you from controlling the relays. It wouldn’t make your D1 Mini not boot.

How much current can the 5V power source you are using supply?

The relay board will draw about 560mA with all relays on, add to that a fudge factor and the D1 mini max current and you would need at least 1Amp.

Do you have an oscilloscope or multimeter you can use to look at your 5V power supply with when just the relay board is connected?

I’ve connected 5V 1A power supply and all relays turning on without any issue (tested with 5V 700mA power supply without any issue)
Using same 5V and ground pins to relays which is also connected to d1mini.
yes, the bootup issue still not fixed.

Wanted to change input to d1mini and relay output connections to MCP extender board. I know GPIO extender only provides 3.3v in logic level. As per the seller MCP23017 supports voltage between 1.8 to 5.5V.

Low Standby Current: 1 A (max.)
Operating Voltage:

  • 1.8V to 5.5V @ -40°C to +85°C
  • 2.7V to 5.5V @ -40°C to +85°C
  • 4.5V to 5.5V @ -40°C to +125°C

Can I use 5v line to MCP board? So that I can disconnect relay board direct connection with d1mini. As MCP sends 3.3v there won’t be any issue with SDA and SCL pins right?

Removed all I2C and switches components. Nothing controlling I2C inputs and relay outputs. But relay board still acting weird. Looks like the issue is not with relays.

I just remembered when I accidentally put 5V on one of the D1 mini GPIOs. It didn’t damage it but it wouldn’t boot either. If the inputs to your relay board have pull up resistors putting 5V on the D1 pins this could be the issue. In which case the level shifter should fix the problem.

Thanks, I’ll try that.

After all trials, I’ve changed both relay outputs and input switches to GPIO extender. Initially I have doubts on it’s voltage limitation. But after connecting both, all 8 relays and switches working without any issues. As it was connected to D1 and D2 of d1mini, all other pins are not connected to anything. However, I’ll get a logic level shifter just in case anything happen abnormally.

It seems like the issue with GPIO pins of d1mini that connected to relay. As I removed all other output pins from d1mini, not facing any boot up issue. However, it’s just a work around, but not a solution.

1 Like