A
Arduino•3mo ago
jmzahra19

How to connect 5v digital signal to ESP32 GPIO (3.3v) pin

Complete beginner here. I have an ESP32 dev board, powered by a MicroUSB cable, connected to a breadboard. I also have a YF-S201 Hall Effect Flow sensor, powered by 5v and outputs digital pulses that correspond to flow, also at 5v. I understand that the ESP32 needs 3.3v inputs. How do I go about doing this? I am currently powering the sensor using the VIN/GND pins off the ESP32 board. Google badly wants me to use a logic-level shifter, which I purchased. However, when I wired it up as Google suggests, it clearly messes something up with the board. I am feeling overwhelmed and frustrated and just need someone to point me in the right direction! Thank you! It is possible I fried either the logic level shifter or the YF-S201. When I started, I could get variable voltage off the signal wire by blowing through the valve. Not so much anymore... Or was I seeing ghost voltage? Can I read digital pulses with a multimeter? I have so many questions 😭
No description
31 Replies
AnonEngineering
AnonEngineering•3mo ago
glad you did some research and got the level shifters, 3.3v pins are not happy with 5v logic 🙂 on the shifter, connect ground, all things in the project use a common ground as a voltage reference. then connect "HV" to the sensor 5v supply, "LV" to the esp 3.3v. when the shifter sees 3.3v on the LV side it puts out 5v on the HV side, and vice versa https://learn.sparkfun.com/tutorials/bi-directional-logic-level-converter-hookup-guide/all
jmzahra19
jmzahra19OP•3mo ago
Thanks for your response! Initially, I connected the shifter as follows (ESP32 > shifter): VIN > HV GND next to 5v > GND on top 3V3 > LV GND next to 3V3 > GND on bottom When I plugged the ESP32 back in, it seemed like it was shorted out or something.
AnonEngineering
AnonEngineering•3mo ago
not Vin, use "5v" (Vin might be anywhere from 7 to 12v)
jmzahra19
jmzahra19OP•3mo ago
No description
jmzahra19
jmzahra19OP•3mo ago
I don't see any pins labeled 5v... also I do have a multimeter and see a solid 5v between VIN and GND
AnonEngineering
AnonEngineering•3mo ago
ok, could be on your esp board Vin = Vusb = 5v so run that 5v to the red rail, ground to the blue rail connect shifter ground to the blue rail, shifter HV to the red rail, then run esp 3.3v pin to shifter LV the sensor output goes to one of the HV inputs on the shifter, the corresponding LV output goes to the esp GPIO pin
jmzahra19
jmzahra19OP•3mo ago
OK, that's what I thought. Is the above photo, is the GND on the right side (next to 3V3) different than the one on the right side (next to Vin)? I understand I need a common ground for the whole project.
AnonEngineering
AnonEngineering•3mo ago
nope, ground = ground = ground
jmzahra19
jmzahra19OP•3mo ago
So if I plug everything in and the LEDs dim (and the ESP32 board disconnects from the laptop), then I have a loose connection maybe?
AnonEngineering
AnonEngineering•3mo ago
more likely a bad connection, sounds like smth is shorted if that happens
jmzahra19
jmzahra19OP•3mo ago
OK, I'm going to try this again. I was second guessing my logic when that happened.
AnonEngineering
AnonEngineering•3mo ago
"dimming" is always bad, see that happening, disconnect immediately and recheck wiring
jmzahra19
jmzahra19OP•3mo ago
Confirmed, and I did exactly that 😂
AnonEngineering
AnonEngineering•3mo ago
maybe to start, just wire power to the shifter (5v, 3.3v, ground) and power up, all should be well then add your sensor power, all should still be well, then add the signal wires
jmzahra19
jmzahra19OP•3mo ago
OK
AnonEngineering
AnonEngineering•3mo ago
a common troubleshooting technique, add stuff until it goes wrong 😉
jmzahra19
jmzahra19OP•3mo ago
Sorry, my internet just went down 😤 im on mobile. Thanks for your patience
AnonEngineering
AnonEngineering•3mo ago
np
jmzahra19
jmzahra19OP•3mo ago
No description
jmzahra19
jmzahra19OP•3mo ago
I should be able to measure voltage across the pins directly from the shifter currect?
AnonEngineering
AnonEngineering•3mo ago
if it's powered up applying 5v to one of the inputs (i.e. HV1) should result in 3,3v on the output (LV1). similarly 3.3v on LV1 should give you 5v on HV1 (all voltages referenced to ground ofc)
jmzahra19
jmzahra19OP•3mo ago
Ok. So far so good Well, I've got everything connected again, and no dimming. It would seem like i had it wired incorrectly before. Thanks for your help! If you have time I have one additional question I can also see data appearing in HA! On the right track again. I am trying to build a DIY irrigation system flow sensor that will report to home assistant. I'd like to place the esp32 indoors near power, and the flow sensor outdoors at the water source, where there is no power, 150 ft away. Is this doable? Some research suggests i can run a direct-burial cat5e cable for both power and data, doubling up individual wires to reduce resistance.
AnonEngineering
AnonEngineering•3mo ago
you can probably get away with that, the sensor doesn't draw much current so IR drop shouldn't be an issue, and a 0 - 5v signal will be relatively noise immune try not to co-locate it with pump power, if any
jmzahra19
jmzahra19OP•3mo ago
I was planning to add a master valve at the water source location, but that will connect to the irrigation controller. It that ok? Controller and esp32 would have distinct power sources
AnonEngineering
AnonEngineering•3mo ago
the biggest issue with long runs is the chance that any other electrical signal can couple into the signal lead, it's a "try it and see" situation other option is an esp on both ends and send signal over wifi
jmzahra19
jmzahra19OP•3mo ago
Ok, makes sense. Alternately, i can move the esp32 to the outdoor location and just run power out to it over cat5e, so all data is local (the location has WiFi coverage). Would this be more reliable,
AnonEngineering
AnonEngineering•3mo ago
the esp draws some power, so long runs might result in a voltage sag (IR drop). if going that way feed a higher voltage to to Vin (up to whatever the board is rated for) I'd try the indoor / cat5 option first, see if it's reliable enough
jmzahra19
jmzahra19OP•3mo ago
That is exactly the reason i chose to move the esp32 closer to the power source, but didn't realize i could start at a higher voltage to account for drop over the run. This is great information. Ok one last question, I promise! You've been so helpful. I have seen some recommendations to use a capacitor to smooth out any spikes or drops. Gemini actually suggests connecting a capacitor directly across Vin and GND. Does this make any sense at all? (I'm very skeptical of AI)
AnonEngineering
AnonEngineering•3mo ago
good to be skeptical of it, but in this case a 10 to 100uF electrolytic cap across Vin / ground will tend to reduce noise getting onto the esp's power bus
jmzahra19
jmzahra19OP•3mo ago
Very interesting! Ok, well you've confirmed that it seems to have pointed me in the right direction. Thank you very much for your help, i was quite frustrated earlier!
AnonEngineering
AnonEngineering•3mo ago
np, good luck with it! (back to work for me)

Did you find this page helpful?