Are Logic Level Converters required with 5v sensors on a 3v3 NodeMCU ESP8266 v3?

I am trying to connect several 3.3v and 5v sensors to a NodeMCU Lolin V3 board which will be powered via USB (5v)

It seems that the VV ( or VU as it is also called in some forums) provides 5v from the USB, while the board runs on 3.3v and provides three 3.3v pins.

I don't feel like powering several (around 5) 5v sensors is recommended from VV, connecting the digital or analogue data pins, as required, from the sensors to the D0-D10 / A0 pins of the board, like if all sensors were 3.3v (it would be too easy, right?)

I have found Logic Level Converters, where 5v and 3.3v are connected on each side and the data pins are 'transformed' to the other voltage.

logic_level_converter.jpg

Is like this, with logic level converters, the normal usage of 5v sensors on a 3.3v board?
Are the NodeMCU Lolin V3 pins somehow '5v tolerant', so data pins can be directly connected?
Is an external 5v power supply connected to the 5v sensors whose data pins are connected to the board via a logic level converter the preferred solution?

Thank you for your help!

logic_level_converter.jpg

Most 5V sensors need logic level conversion, but whether you need it and what method to use depends on the sensor in question.

While those "logic level converters" might work, they are inappropriate. They are specifically for interfacing I2C busses at different logic levels, their only selling point is that they are bidirectional which you do not need here. Mind you I have used them as a convenience to interface a MFRC522 RFID reader with SPI. :grinning:

Clearly you need to reveal to what "sensors" you are referring in order to get any useful answers. :roll_eyes:

Paul__B:
While those "logic level converters" might work, they are inappropriate.

How do you know they're inappropriate? OP didn't tell what kind of sensors. If it's an I2C sensor, they are appropriate. If it's another sensor, maybe - maybe not.

Until comes back with a list of which exact sensors they intend to connect we can't really say much either way.

First of all one should check if the sensors aren't working well at 3,3V.
Most do.

First of all, apologies for the poor questions. As wvmarle's signature says, it's difficult to give good answers with s****y questions like mine.

My project is around an AeroGarden hydroponic system, an old model which is not connected to any IoT system. It just switches on/off the lights and cycle the water inside the tank.

As I am learning the amazing world of microcontrollers and sensors and got a few of them, I am planning to connect the following sensors to the NodeMCU V3 (and possibly a MEGA2560) which will be connected to my Wi-Fi and send data to my MQTT server connected to Home Assistant:

  • A MPX5010DP to detect water level. It runs on 5v only and uses an Analog pin.

  • A 18B20 Temperature Sensor to get the temperature of the water. I want to plant chillies (and basil, coriander and mint) and it seems water temp is important. It can work on 3.3v and uses a single Digital pin for data.

  • A BME280 Temp, Pressure and Humidity Sensor for the room's temp and humidity, requires 3.3v and communicates over SPI

  • A Photo cell (CDS Photoresistor) to log when lights are on/off. 3.3v and 1 Analogue pin.

  • A MQ-2 Gas sensor. The hydroponic garden will be placed next to the flat's boiler and I want to monitor a possible leakage. 5v, 1 Analogue + 1 Digital pins

  • An active buzzer as an alarm.

  • A 2 colour LED as a visual indicator of the system

I also have a MEGA2560 and a TFT screen shield for it, which I wanted to use as a monitor of the system with a HC-SR501 PIR Motion Sensor to switch the screen on and off when someone is in front of it. All the 5v sensors were going to be connected to the MEGA and the rest to the NodeMCU. But the screen doesn't support to switch the backlight on/off, so maybe I scrap the MEGA and get another screen which can be controlled directly from the NodeMCU.

Maybe all of this is too much for a single NodeMCU board, but I prefer to aim high and then, learn from the problems I may face. I am learning about MOSFETs (thank you, Paul__B!), logic level converters, how screens work, powering the NodeMCU and the MEGA, communicating between them, growing chillies and, hopefully, to ask better questions.

Plan A is NodeMCU + MEGA + current screeen.
Plan B is NodeMCU + new screen.
Plan C is NodeMCU + MEGA + new screen 3.

The main problem so far with plan A is the screen. Tested all sensors successfully. I'm still thinking about how to power the boards, probably will split a single 5V 2A PSU and power the boards via USB. They may communicate over I2C (or maybe PJON?)

Plan B's challenge is to learn how to use 5v sensors with the 3.3v NodeMCU. I see this as basic knowledge with Arduinos, so I'm eager to try. Logic level converters are not the solution like I initially thought. Voltage dividers? I've got a PCF8574 digital expansion board and a CD74HC4067 analog mux. I have used them before but not on the NodeMCU. Also, I would like to learn about calculating and measuring current in the circuit, so this could be a good chance to do it.

Plan C looks more feasible to me. Still a lot of chances to learn new things...

Any feedback is very welcome. Thank you for your help!

MiOiM:

  • A MPX5010DP to detect water level. It runs on 5v only and uses an Analog pin.

The MP3V version of the at sensor operates at 3.3V. Connection to the analog input through a voltage divider needs extra care as the NodeMCU has a voltage divider already (100k & 220k iirc): the ESP8266 uses a fixed 1V internal reference.

That sensor can also operate on I2C. The level shifter as you showed would work in that case, it doesn't work for SPI.

  • A Photo cell (CDS Photoresistor) to log when lights are on/off. 3.3v and 1 Analogue pin.

You can use a digital pin for this. Adjust the series resistor for appropriate level.

  • A MQ-2 Gas sensor. The hydroponic garden will be placed next to the flat's boiler and I want to monitor a possible leakage. 5v, 1 Analogue + 1 Digital pins

You may also be able to do this on a digital pin.

NodeMCU seems to be running out of pins if you add the rest and a display - you can consider the ESP32 boards; those definitely have enough pins and also more analog inputs. It'll happily run everything on one board (much easier for programming) and you'll be able to do much more with the display than on the low memory Mega.

Thank you for the tips, wvmarle!

  • I will try to use the MPX5010 unless I have no other option. I already have it and I don't want to spend much more money on this. However, thanks a lot for the heads up regarding the 1V internal reference. I read something about this but almost forgot.

This is probably a crazy idea, but would it be possible (theoretically, I don't think I will go in this direction) to use the CD74HC4067 Analog/Digital MUX on A0 to have more analogue pins, then limit the signal from the mux to A0 to 0-to-1V?

  • The BME280 runs on 3.3V, so the level shifter should not be necessary with it. Maybe I use a DHT11 instead, for simplicity. Not sure yet...

  • Also, thank you for the suggestion of using a resistor to control the level of an analogue signal and use it as a digital one. I didn't know if it is possible.

  • As I still have the 5V - 3.3V problem, I am considering using a PRO MICRO board which runs on 5V, and to communicate it with the NodeMCU via I2C (this time using the level shifter). As the little screen I've got goes over I2C as well, is this correct?

Cheers!

MiOiM:
Thank you for the tips, wvmarle!

  • The BME280 runs on 3.3V, so the level shifter should not be necessary with it. Maybe I use a DHT11 instead, for simplicity. Not sure yet...

Only do so if you really don't care about the actual readings.

  • Also, thank you for the suggestion of using a resistor to control the level of an analogue signal and use it as a digital one. I didn't know if it is possible.

Remember that a digital signal is merely two voltage levels. Below a certain voltage it's read as zero/low, above a (slightly higher) voltage it's read as one/high. The change-over point is somewhere in between those two, usually with some hysteresis.

Your LDR is for light/dark detection. Pick the resistor such that a the light level you would call neither light nor dark the voltage is at about that change-over point. When it becomes brighter, it goes one way, when it becomes darker, the other way.

The MPX5010 produces a voltage of about 0.5-4.5V I remember (see datasheet). I'm not sure, but I think it is in fact ratiometric. So to get accurate readings you must keep your 5V supply really stable. As the NodeMCU has a voltage divider on the analog input, you have to add a resistor between the MPX5010 output and the A0 pin (no complete divider!) of appropriate value. If the lower value is indeed 100k (check schematics) the top resistor should be 400k for a 4:1 divider. As there is 220k already, you have to add a 180k resistor.

wvmarle:
Only do so if you really don't care about the actual readings.

Ok, I get it. I will use the BME280 over I2C.

My question regarding the analogue pin of the NodeMCU was more my curiosity about using the mux, but I understand that each sensor will have its own signal range which has to be limited with specific resistors to the 0 to 1V range of A0, so nope.

I think I will do a test with the PRO MICRO and the NodeMCU over I2C and the logic level converter and see if I can make it work together with the I2C screen.