I'm having a project, there will be a 16 relays (Lights), which are controlled by 16 buttons. I'm using esp32 as Micro-controller.

For achieving this, I've used two mcp23017 boards as GPIO extenders. Everything works perfect. The thing is, I want to use one power source for both relays and esp32+mcps. So now that "opto isolation" is gone as i understand.

For protecting my esp and mcp boards, what kind of components i can use ? I want to minimize the noise, make it more stable for circumstances.

Sorry for my poor drawing, but i hope that you will get the idea. (For the buttons, to minimize the drawing i just drawed one of them) (For the second relay, to minimize drawing i just supplied one 12v to output side, but all of them are connected to outputs)

Parts list:

  1. Buck converter
  2. MCP23017
  3. Relay Unit

enter image description here

  • 1
    \$\begingroup\$ What protection you are after? From what you need protection? \$\endgroup\$
    – Justme
    Jan 4, 2022 at 21:06
  • \$\begingroup\$ The relay contacts are of course still isolated from the relay coils. Why do you have multiple relay boards in your circuit, by the way? \$\endgroup\$ Jan 4, 2022 at 21:13
  • \$\begingroup\$ @Justme I mean people are saying that for "opto-isolation" you have to use two different power source, since im using one, i just wanted take people's opinion regarding if the circuit is fine like this, or there are anything i can do to improve it. (To make it more stable/convenient , to protect esp's from spikes etc) \$\endgroup\$
    – signalz
    Jan 4, 2022 at 21:21
  • \$\begingroup\$ well, to protect it from inductive spikes, you'll need separate power supplies. That you already know. \$\endgroup\$ Jan 4, 2022 at 21:23
  • 1
    \$\begingroup\$ @Justme i see your point, thanks for warning. As you said ESP32 is 3.3V and MCP23017 can work with 3.3/5.0V but since im feeding it with 5V there might be inconsistency. It was working fine like this and never checked it ! :) Thanks again i will fix it. Apart from this, do you see any other point that i should consider ? Thanks \$\endgroup\$
    – signalz
    Jan 4, 2022 at 23:21

1 Answer 1


I've noticed you want to stretch wires 40m. That's really far. It is possible to pick up noise and ground loops on the wires that will make the connections unreliable.

As a solution, I just found out you can buy a packet of 10 esp8266 wifi cards for around 30 dollars from amazon. Seems like just the ticket for you. Then, you control everything locally. These things will run off of cheapo 5V usb adapters. Here is a link to the amazon page:


You could still keep the esp32 as the main controller, and connect via wifi to the sub controllers, all without the annoying possibility of ground loops or noise. You can program the esp8266 with arduino, python, or various other languages.

You can then drive the relay boards with transistors that are driven by an esp8266 GPIO. Here is a link to a page that describes how to do it with discrete relays. The relay board may have the diode already built in.


Remember to use a "Logic Level" mosfet, or it won't work with esp8266, which outputs 3.3V on it's gpio ports (ISTR). You could also use an NPN transistor instead of a MOSFET, since they are pretty much guaranteed to work with a 3.3V system.

Edit: added the fact that esp8266 cards do wifi.

Edit 2: Use ESP-Now protocol. Watch this: https://www.youtube.com/watch?v=lkHdk_mKGUw

  • \$\begingroup\$ please don't Answer comments. I read "30-40 meters max distance between small relay and remote relay" so the 40 m wires will be 12 V. \$\endgroup\$
    – Juraj
    Jan 5, 2022 at 7:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.