ESPHome multi sensor / actor: please help me finish my project

Hi everybody,

I am working on a project that is getting way over my head, so I am asking for help (or, perhaps, anyone else is interested in building this and we can collaborate).

This mess (picture below) just fried my power source, so I decided to make custom PCBs instead of breadboarding this. However, last time I did this (for a smaller project that I actually thought I had figured out), the PCBs I ordered did not work.


(left to right: nodeMCU v2 ESP9266 development board - 3V3/5V power source - MCP23017)

This specific project is meant to be next to my garage and control multiple relays, provide different sensor readings, and more.

Below is a list of components that I got so far, but more shall follow. Considering that I need to order multiple PCBs anyway, I want to use them for other ESPHomes with less sensors as well…

  • at least 2x 8 Relais Module (VCC, GND, IN1 - IN8)
  • at least 2x MCP23017 I/O Expander (VCC, GND, SCL, SDA) to handle all those GPIOs
  • 1x - 2x Piezo Buzzer (2 Pins)
  • 1x - 2x BH1750 temperature/humidity/pressure sensor (VCC, GND, SCL, SDA, ADDR)
  • 1x Rain Sensor
  • 1x TEMT600 brightness sensor (VCC, GND, OUT - I believe this is an analog sensor)
  • 2x+ Reed Sensors (2 Pins)
  • 3x SR505 PIR sensor (VCC, GND, Data)
  • 4x Water Level Sensor (VCC, GND, OUT, “M”)
  • multiple LEDs (2 Pins)
  • multiple DS18b20 temperature sensors (VCC, GND, Data); the multiple sensors are only for this one device
  • multiple `momentary switches* (2 Pins)
  • perhaps Neopixel LEDs (VCC, GND, Data)

Photos of those components at the bottom of this post.

I have multiple questions about this:

  • can I use the MCP23017s GND for all the components’ GND pin? When I tested without the I²C extender and used the nodeMCUs ground for both the reed sensor and the piezo buzzer, the reed sensor would be toggled (somewhat randomly, so not every time, but most of the time) when I toggled the piezo buzzer via gpio switch over ESPHome)

  • What would you use as connectors? As you can see in the first photo, I use different terminal connectors that I crimped myself. However, either I use cheap materials, or I suck at crimping. Especially those white terminal connectors don’t work reliably (the reason I fried the power source was that one ground came loose and I tried to “fix” this problem temporarily with crocodile clamps - learned my lesson :D)

  • How would you handle unused pins? Depending on whether I use 2 or 3 MCP23017 I²C expanders, I’ll have 28 - 42 GPIO pins available. This might seem like a lot, but the relays themselves will already require ~16 of those; however, as I mentioned above, I am planning on using this PCB for other things (not having the relays connected) for other purposes. So I figure most of the GPIO pins / I²C expander pins ought to be accessible in a way that’ll allow me to use them for different purposes. Would you recommend all of them going to a screw terminal (green/blue in first photo, green in LED photo below)? This way, I’d have to connect each I/O separately to the relays’ IN pins, but would also have the freedom do use a different purpose on the next project that might not require a relay at all

  • Do I need resistors for any of these components? I read that I’d need a 220Ohm - 1k Ohm for the reed sensor so that it wouldn’t send false positives. I had done this, but it didn’t work at all. Once I removed the resistor and connected it to some GPIO and GND (as INPUT_PULLUP), it worked perfectly - without false positives.

  • Would you use something other than the nodeMCU v2 board? I have multiple Wemos D1 Mini clones, however, afaik, they don’t support VCC (or powering them other than via USB), which I don’t like.

  • What else do I need to pay attention to? After posting this, I will get started on a Fritzing file for the custom PCB. If people are interested in this project and/or helping me build it, I can upload those here as well once they are done. I’d just like to make extra sure that I don’t order useless PCBs like last time - that was my first project, so it’s okay that it didn’t work, but it took quite some time and cost a bit of money, so I’d like to be super sure the next PCBs work as expected… :slight_smile:

  • Are there some GPIOs on the ESP that I must not use? I looked at the specs and thought as long as I didn’t use D2 and D4, I’d be safe. But again, I’d like to make extra sure before ordering PCBs.

Thank you in advance for your input :slight_smile:


PIR

Relay

Piezo Buzzer

BH1750

TEMT6000

Reed Sensor

LED

Momentary Push Button

MCP23017 I²C Expander

Water Level Sensor

Rain Sensor

Neopixel Circle

Yes, this is the worst board imho. My D1 Mini clones can all be powered on the VCC pin without problems.

Alone from the amount of stuff you want to drive you should maybe consider using a esp32 board instead of esp82xx based one. It will provide already much more usable GPIO’s to start with

Defiantly, check here for the esp8266: ESP8266 Pinout Reference: Which GPIO pins should you use? | Random Nerd Tutorials

2 Likes

Thank you!

Do you use D1 Mini Pro devices? Mine are just D1 Mini clones and don’t have VCC. There is 3V3 and 5V, but I remember something about those two not being able to use an external power supply (hopefully, I remember incorrectly; but I know that I settled on nodeMCU instead of these for that very fact).

The ESP32 does have more GPIOs, but unless there is another upside to using them (other than the BT compatibility, which I am not sure I can utilize in this scenario), I’d rather stick with whatever ESP8266 it’ll turn out to be and multiple I²C expanders. I have little experience with ESP32, but the few things I have tried so far didn’t work as well as on 8266s.

The board above shows a Vin. That suggests you can use a 5v input supply voltage to that pin. My experience btw has been the reverse, esp32’s are my goto. If it works on an 8266 then it should work on a 32. Esp 32’s also have 2 i2c buses and real pwm vs software on the 8266.

Take it one component at a time, get one thing working, add another. Keep in mind the total length of the i2c line shouldn’t exceed ~10 feet in total per bus.

Are you sure that you need (at least two) I2C expanders like the MCP23017?
As far as I see it only the BH1750 sensors (which by the way are not temp/humid/press sensors but light sensors) are using the I2C protocol, and all other components are using different protocols like One Wire for the DS18B20 or dedicated digital pins.

Please ignore my reply.
I was confusing these MPC23017 expanders with a dedicated I2C multiplexer as a TCA9548A.

Honestly i don’t know if this Arduino Mega + ESP8266 board will work with ESPHome, but it definitely may help you with the GPIO pins. Just an idea…

Is there an upside/downside to using something like the MCP23017 (link)?

While I have been tampering with ESPHome, tasmota, etc. for quite some time now, I am no professional IT / engineer person… I thought that keeping my work modular would be a good thing. Let’s say I have a setup like this

Power source → ESP → MCP23017 → sensors/actors

If the ESP breaks, I can keep the setup as is, replace the ESP, but simply re-wire the (existing) MCP23017 to the new ESP and be good to go.

Also, most (all???) ESPs, at least the ones I have looked into, only provide one single analog pin. By using multiple expanders, I’ll have multiple native analog pins that I could use, if I need to.

Either way, this is getting pretty confusing to me. I hope to complete my schematics by the weekend to post the .fzz file. Below is a snapshot of what I have so far, and it is not even close yet (missing multiple components).

I don’t think using MCP23017 will bring any upside/downside. However, if i were you i would have break down this into different nodeMCUs, like using 3 different NodeMCUs. Because i have no idea if one NodeMCU can cope up with so many inputs and interrupts (I am no professional either) with its microcontroller. Analog input will make you no advantage since usage of analog pin with ESPHome is pretty limited.

Breaking down to 2-3 NodeMCU will bring you both more stability and disaster recovery since if ESP or communicaton breaks down, only the sensors/actuators connected to it will be affected; not all. Since NodeMCUs are pretty cheap; if it was me; i would have use different and standalone ESPs, like buttons/relays in one ESP, reeds/PIRs in another and all others in 3rd ESP. Still, it is your call; i also wonder if one NodeMCU will cope up with this many input/outputs without any delays (again, no professional).

We made a resembling setup with so many inputs/outputs to a friend; PIRs/reeds and switches. He used 2 different Arduino Mega one for PIR/reeds and the other for switches. He connected all with wires and used ethernet shields; so no WiFi at all. Connected it to his smarthome system with “mysensors”. It is the most stable system in his setup.

As I understand it, the ESP8266 devices indeed have only one analog pin, but the ESP32 devices have 18 pins that can be used as analog pin.
See: ESP32 vs ESP8266 – Pros and Cons
On that page it is stated:

When it comes to the analog pins, these are static, but the ESP32 supports measurements on 18 channels (analog-enabled pins) versus just one 10-bit ADC pin on the ESP8266. The ESP32 also supports two 8-bit DAC channels.

Further, the ESP32 has more power that the ESP8266, so might be the better choice in your case:

Both chips have a 32-bit processor. The ESP32 is a dual-core 160MHz to 240MHz CPU, whereas the ESP8266 is a single-core processor that runs at 80MHz.

Thanks for your replies, everybody :slight_smile:

This is how things are currently hooked up. One nodeMCU for controlling a relais for different water valves; one for motion detection; one for water level measurement (just boolean whether or not it is still at certain points), etc.

All these MCUs are running ESPHome and are programmed fine (they work), but always wired crappily on DIY PCBs. Which is also fine, they work, and have for quite some time!

But I thought manufacturing some kind of “all purpose” PCB with an overkill of GPIOs (due to the MCP23017s) that can handle everything would be the solution. Use one of those to actually do what I need for this (so, a lot), but since I’d be ordered 20 or so PCBs anyway, have a spare for each room in my house which I would then not use as intended, but rather just for whatever is needed in that particular room it would be in.

This would be my preferred setup as well. I haven’t had any experience with mysensors, but I believe one could even use an ESP32 running ESPHome and use an ethernet shield as well. If it could even be powered via PoE+ (which my switch supports, so not even an extra power cable there), that’d be fantastic.

I will see if I still have a spare ESP32 in my parts box and hook things up to it. When the ESP32 first came out, I remember a lot of people complaining about it’s “high energy use”. I don’t exactly know what they meant by it, but I will look into that as well.