1

I'm trying to connect a PIR motion sensor. In the tutorials I've found, I've seen people connect it to the Pi's GPIO using either a breadboard and resistors, or direct to GPIO pins using jumper wires. Which is better? How do you determine if you need resistors (I know how to calculate with Ohm's law) or capacitors or the breadboard or anything beyond the equipment you know you want, like a motion sensor.

3

The answer, I'm afraid, is experience.

Resistors are often used to restrict current flow to a maximum level.

For instance if you connect a power source to a LED it will flash briefly and then die. It has consumed too much current and burnt itself out (just like old fashioned fuse wire). You would use a resistor in series with the LED to limit the current flow.

Say you had a modern LED. It would probably shine very brightly (perhaps too brightly) with just 5 mA of current flow. Say it's powered from 3.3V (a gpio). Then Ohms law says current is voltage divided by resistance. A resistor of 660 ohms will limit the current to 5 mA (3.3/660 = 0.005 amps, = 5 mA).

This is an over simplification as the actual current flow will be less because of the LEDs forward voltage drop, but you get the picture.

Quite often a resistor will be placed in series with a gpio if there is a chance of misconfiguration. For instance if a gpio is connected to ground (via a button say) and is intended to be used as an input there will be a short circuit if it is accidentally set as a high output. A resistor would also limit the current to a non-damaging level in this case.

Resistors are also used to give a gpio a stable value. If nothing is connected to a gpio set as an input it will randomly return high or low. You might use a pull-up or pull-down resistor to make sure the gpio defaults to a high or low value.

Another use for resistors is to provide a voltage divider. You might have a sensor which outputs a 5V digital signal. You should not connect that to the Pis 3.3V gpios. You could use a pair of resistors as a voltage divider to drop the voltage from 5V to a Pi safe 3V3.

I am learning myself so have probaly missed quite a lot of reasons to use resistors.

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.