I have a B+ connected to a H-bridge which is connected to 4 AA batteries and 4 motors, and they work fine, but now I want to add a distance sensor, which requires 5v, so do I need any extra batteries?
You can use the 5v output on the gpios of the Raspberry Pi. However be careful, you mustn't connect the echo pin directly to the gpio. Instead you can make a voltage divider on the wire connecting the echo pin because the b+ can't handle anything over 3.3v. Not using a voltage divider will damage your Raspberry Pi.
You can use a 470 Ohm and a 1K Ohm resistor with the 1K connecting echo and ground. Refer to the diagram below if you are unsure.
-
-
@Vedbot It is risky, I can't guarantee the voltage will be around 3.3v without a voltage divider. Maybe someone else can tell you. – Linus Oct 25 '15 at 14:46
-
The official line has always been that any current at a voltage greater than 3.3V will eventually kill the GPIO/Pi. I can't see the official line changing. A voltage divider is safest. If you can only use 1 resistor I suggest a value of 10k or more. – joan Oct 25 '15 at 14:52