# powering a sensor usin external power

I' m not electronic or electricity specialist , i'm a developer who tries to make fun stuff on raspberry pi , and this is why i burned two rpi 3 . i'm using my rpi with many electronic stuff , pir sensors , relays etc. All those components are externally powered , and to communicate with my rpi i m connecting the rpi ground to the power source ground , and on any output or input wire i put resistors to avoid any over current going to or from the gpio pins what i m doing is similar to what is schematized here :

Powering a sensor using an external power supply board

the only difference that with data wires coming from sensor i have only one resistance between the sensor data pin and the gpio input pin, i do not add any other resistance connected to the ground between them (like the 2k resistor in the schema ) My question is : is the 2k resistor wired to ground is necessary ? why is it added , how dc current flows in this case . my question may appear stupid , but as i sad i m no electronic/electricity man , an i don't want to burn any rpi in the future.

• The two resistors together make a voltage divider. I'm sorry to sound negative, but it's really essential to understand how an electronic works before making changes to it. – Bob Brown Mar 20 '20 at 17:24
• thank you sir for your feedback , time for me to get a serious electronic course :) – Rha Mar 20 '20 at 21:19

The post you link explains pretty well, but it does not explain how they selected the 2K resistor.

They do explain why, though. At the end of the question:

Since the Raspberry Pi GPIO PINs work with 3.3V, I had to build a voltage divider to convert the 5V output of the sensor to 3.3V. Assuming the left-most resistor on the breadboard is 2K ohm and the right-most resistor is 1K ohm, did I do right?

The sensor outputs its signal with 5V, but connected to a 3.3V input PIN on the Pi. Without knowledge of electronics, this is basically like fitting a triangle shape into a round hole---they don't match. To make that work, they introduce a voltage divider. This is typical pattern in electronics of this type, to divide a higher voltage into a lower voltage (the way around is another pattern).

So how do we divide voltage? This is where electronics knowledge comes into play. And this is very common and basic (basic, because it is usually taught in high school, but it can be far away in the past :-) ), so Wikipedia is a great place to search. The entry on voltage divider just saves the day. The whole entry is a good read if you intend to keep on playing with electronics. The salient part here is basically the image and the formula. The image shows the divider connects a resistor to the ground. The why can be seen through deriving the formula: Current flows like water through the circuit, and the connection to the ground is necessary to avoid leaking (well, to get it to actually work). To derive the formula we basically use current and relations like `U = R・I`.

The 2K comes from the target. The input is `Vin = 5V`, and we want `Vout=3.3V`. Using the formula above, we just need to find a pair of resistor values to get the right output. Usually, we fix one, say `R1`, to a common available resistor. Let's pick 1K and we can calculate that `R2` should be 2K.

I hope this helps. For more information, I would suggest the Electrical Engineering section on StackExchange. This section on the Pi is best for questions specific to the Pi.

• This answer may be mathematically correct BUT ignores the reality of circuit design which needs to consider the tolerance of the external voltage, the resistor values and the input characteristics of the Pi. An Engineer would design a circuit to provide ~1.8V given the worst case tolerances - as suggested equal resistors would do. – Milliways Mar 20 '20 at 4:22
• Yes yes @Milliways. The answer is just intended as a starting point for hobby (to follow the flavour of the question). Do you think necessary to add more pointers toward the end, to include your remarks, or just keep as-is with your comment? – Eric Platon Mar 20 '20 at 4:44
• thank you for your explanation , for the given schema the purpose of voltage devider use is clear, rpi gpio input accepts only 3.3v (or less , i v read that rpi consider v between 2.2v and 3.3v as high) and the sensor outputs 5v . but if we consider a pir sensor that outputs 3.4v , is it considered too high for GPIO IN, do we need a voltage devider . ≈ – Rha Mar 20 '20 at 11:18
• having the same schema and replacing the ultra sound sensor by a pir sensor that outputs 3.4v , is it safe to wire the output of the sensor directly to the gpio, by adding just a 1k resistor between them (sensor output not connected to ground like the schema with the 2k resistor) . actually it worked always like that for me . – Rha Mar 20 '20 at 11:22
• I think you do need the divider in that case too. The resistors help in preventing something bad happens. Having written so, @Milliways' comment is important: My comment is a starting point, and more care is needed, by knowing at least more about the actual tolerances of the Pi (the Pi forum and docs are great). An Electronics course online/book would definitely help, but practice makes a big difference. – Eric Platon Mar 21 '20 at 0:25