I was making a robot with a raspberry pi 4 which will have four ultrasonic sensors on all its four sides..

I was looking up in google to see the schematic of the connections and noticed that there are 2 resistors connected to the echo pin.


Image Source: https://tutorials-raspberrypi.com/

Note that the image has a raspberry pi 3 but I am working with a raspberry pi 4

I do understand that the resistor is kept to limit the current, but my first question is that will it work without the resistor and is it a must for the resistor? The ultrasonic sensor works fine with the 5V output pin from an Arduino without any resistors, so it should work fine with the 5V of my raspberry pi 4 also right?

Now to my second question..
I want to connect 4 ultrasonic sensors to my rpi4, so should I connect the resistors to all the echo pins of the ultrasonic sensors?

  • 2
    The two resistors are a voltage divider. The echo pin is 5V. The GPIO can only run at 3.3V. You need that on EVERY echo pin or you will destroy your Raspberry Pi with over voltage on the GPIOs. – Dougie Apr 25 at 11:01

The 2 resistors form a voltage divider to reduce the 5V output of the sensor to a value which is safe for the Pi GPIO which is a 3.3V device.

EACH sensor NEEDS its own voltage divider!
NOTE The values are not critical, in fact I would use equal value resistors to produce 2.5V output which is safely above the GPIO threshold.

You might find https://gpiozero.readthedocs.io/en/stable/recipes.html?highlight=distance%20sensor#distance-sensor easier to implement.

  • Thanks for you answer! I do understand it reduces the voltage but my ultrasonic sensors works fine with the 5V ouput pin of an Arduino with no resistors.. why is that the rpi needs resistors? – 404 - Brain Not Found Apr 25 at 7:28
  • 1
    This has NOTHING to do with OUTPUT - the INPUT to the Pi MUST NOT exceed 3.3V – Milliways Apr 25 at 7:29
  • oh.. I understand now.. but what if I use the 3.3V pin for powering the ultrasonic sensors, will the sensors work fine or not? – 404 - Brain Not Found Apr 25 at 7:30
  • 1
    @404-BrainNotFound The basic mathematics seems OK, but I can't confirm anything I haven't tried. I have already posted the link I would use. I definitely wouldn't use sudo. – Milliways Apr 25 at 8:32
  • 1
    These sensors typically will not operate properly from 3V3, they need 5V power. When I tried powering from 3V3 I got random results for the range. – joan Apr 25 at 8:34

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.