How can I interface an ultrasonic sensor with a MCU with 3.3 V GPIO like the NodeMCU? I tried powering the sensor with both 5 V and 3.3 V from the MCU. Both failed to show any results as the distance appeared to be 0 V. In both cases the trig pin of the sensor was given 3.3 V input from the GPIO pin. I assume I need to level shift the echo pin output from 5 V to 3.3 V. How can I do that? Or is something else the issue? The code I used is fine as it works with Arduino.


The datasheet I found says the logic is TTL, which as far as I know is 2 V - Vcc, so 3.3 V should be fine. Is Trig just constantly given 3.3 V? According to the datasheet, it needs a 10 us pulse. Perhaps that is your issue? Code or schematics could help if that isn't it.

| improve this answer | |
  • I have given trig pulse High and Low at 10us interval. The code is not the issue as I have used the same code with Arduino and it works fine. – maheshmt Mar 15 '19 at 4:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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