electronic components for raspberry pi

Raspberry Pi GPIO Basics: Components You Need to Know

If you click our links and make a purchase, we may earn an affiliate commission. Learn more

When you first plug a few wires into the Raspberry Pi’s GPIO pins, it feels like magic—until you realize you have no idea what’s going on. What’s a resistor? Why did that LED burn out? Don’t worry, we’ve all been there. If you’ve ever wanted to build simple circuits but felt lost with breadboards and color bands, this guide is for you.

Typical components used with Raspberry Pi GPIO projects include breadboards, resistors, LEDs, push buttons, diodes, and transistors. Each plays a specific role in controlling current, handling inputs or outputs, and protecting the board from damage.

In this guide, we’ll look at what these parts do, how they look, and how to use them safely with the Raspberry Pi. You’ll see real examples, wiring tips, and common mistakes to avoid; when you’re done, you’ll have everything you need to start building circuits with confidence.

If you’re like me and sometimes mix up syntax between programming languages, I’ve got just the thing for you. I’ve put together a Python cheat sheet with all the essential syntax in one place, so you can keep it handy and avoid any confusion. Download it here for free!

Understanding the Basics

Before we get into the different types of components, there are a few fundamentals that we need to understand first. Don’t worry, I won’t go into too much technical detail. We only need to understand a few basics.

You can skip these portions if you’re already conversant with these topics.

GPIOs

The first thing that we need to understand is what GPIOs are.

GPIO stands for General Purpose Input Output. GPIOs are a set of pins (40 in number) available on your Raspberry Pi that can be used to communicate/ interface with external components electrically.

gpio pins raspberry pi

There are many different communication protocols the GPIO can support, and most pins have specialized secondary functions.

You can read our guide to Raspberry Pi GPIOs for an in-depth understanding.

Prefer reading without ads and popups?
Members get an ad-free version of every guide, plus exclusive project support.
Join the Community | Sign In

For now, all you need to understand is that each GPIO is a binary bit; it can be either 1 or 0 (high or low). When a specific GPIO is set to 1 (high), the voltage at that pin is 3.3V; when it is set to 0 (low), the voltage is 0V or Gnd.

Furthermore, each GPIO can be configured as an Input or an Output (via software).

  • Output: the software sets the pin to high or low, and the voltage (3.3V or 0V) is applied to that pin; external components can then interact with this voltage.
  • Input: The external component/circuit applies a voltage to the pin, which the software reads and translates to either a high (3.3V) or a low (0V).

Breadboard

The next thing we need to understand is the breadboard. A breadboard holds and connects different components; it is composed of rows and columns of interconnected holes.

There are two main parts of a breadboard: the power rails and the terminal strip.

The power rails consist of two columns on either side of the breadboard. All the holes in each column of a power rail are connected. Power rails are commonly used to distribute the Vcc (3.3V or 5V) and Gnd supplies to the rest of the circuit.

Conventionally, the Vcc is connected to the column marked with red (+), and the Gnd is connected to the column marked with blue (-). However, it is not a fixed rule, and you can connect them however you prefer.

The terminal strip is the central area where most components are placed. Each row of the terminal strip is composed of two sets of five connected holes on either side of the central channel.

The central channel of the terminal strip is ideal for straddling multiple ICs or components so their pins do not short together.

If you are a complete beginner to electronics and wondering what the significance of having connected holes is, all you need to understand for this tutorial is that, in electronics, signals are communicated through connectivity.

What this means is that, if the legs of two components are connected, then they will both have the same voltage level/ signal. This concept can be used to communicate a signal (voltage level) from one component (source) to another component (sink).

If you don’t already have a breadboard, you can get one here.

You might also like: I've tested hundreds of Linux apps, here are the ones I recommend.

Grab my Python cheat sheet!
If like me, you always mix the languages syntax, download my cheat sheet for Python here!
Download now

Power Supply

The final concept we need to understand before we can start looking at the components is the Raspberry Pi Power Supply.

A wall adapter typically powers the Raspberry Pi. This adapter converts the 220V or 115V AC from your house’s main supply to 5V at the USB end. The Raspberry Pi takes this 5V from its USB connector, and an onboard regulator IC converts it to 3.3V for internal use.

Consequently, the GPIOs of your Raspberry Pi expect 3.3V as the high signal. If you apply a voltage greater than 3.3V to any GPIO, it can permanently damage your Raspberry Pi.

For this guide, we can ensure our Raspberry Pi remains safe by using 3.3V from its onboard regulator as Vcc by connecting the 3.3V pin of the GPIO to the red power rail of the breadboard, and the Gnd pin of the GPIO to the blue power rail.

Resistors

Controlling the flow.

The first component that we will cover is the Resistor. Resistors are the basic building block for any electronic circuit. Resistors restrict the flow of current, and Ohm’s law governs the amount of current that flows through a circuit: I = V/R.

Resistors come in different packages. However, the most common through-hole packaging resistors look like elongated beads with color coding in the form of circular ribbons.

Each resistor has a rated resistance (R) that it provides to the current. The resistance value can be measured with an Ohm meter or a Multimeter, or calculated manually using the color coding scheme.

Image from EEPower.com

The primary function of a resistor is to restrict current flow, and the key principle (Ohm’s law) states that the greater the resistance, the lower the current.

However, for easier understanding, I like to think of them like mechanical springs. When a force (voltage) is applied to a spring (resistor), it stretches to a specific deformity (current) based on the spring’s stiffness (resistance).

This analogy can help understand more complex circuits involving resistors as well.

Resistors are rarely used as components on their own. Most of the time, they are connected in series with other elements to limit the current flowing through them.

One unique example of a circuit that uses resistors alone is the voltage divider circuit.

This circuit steps down the voltage. For example, we can use this circuit to connect a component/sensor that produces 5V or greater, and step it down to 3.3V for the GPIO of our Raspberry Pi.

However, we have to carefully calculate the resistance values for a specific Input-to-Output Voltage ratio. The general formula for a voltage divider is: Output Voltage = R1/(R1 + R2) x Input Voltage.

A fun thought experiment: try to visualize the voltage divider circuit using the spring analogy that we used earlier.

Resistors are the fundamental building blocks of any circuit, and we will continue to see examples of their use along with other components throughout this guide.

You can purchase a 1000-piece resistor kit from this Amazon Link.

Related: How To Connect and Code a Motion Sensor with Raspberry Pi

LEDs

Lighting it up.

Grab my Python cheat sheet!
If like me, you always mix the languages syntax, download my cheat sheet for Python here!
Download now

The next component that we will discuss is LEDs. LEDs are the primary output stimulus used in any electronic circuit. LEDs can be in two states: lit (High) or not lit (Low).

LEDs look like small bulbs that have two pins sticking out of the bottom. Each LED has two pins, the long one (Anode or Positive) and the short one (Cathode or Negative). They come in many different colors.

The LED lights up when you apply a voltage across its terminals in the correct polarity. The correct polarity means connecting the long leg of the LED to the positive voltage, such as 3.3V, and the short leg to Gnd.

The brightness of an LED depends on its color and the current passing through it. As we learned previously, resistors can be used to restrict and control the current flow. Therefore, we can use resistors to limit the current through an LED as well.

You can try using resistors of different values and observe how the LED’s brightness varies. You can then choose a resistance value that suits you.

To control this simple LED-and-resistor circuit with your Raspberry Pi, connect it to a GPIO pin, then use the GPIO Zero library (Python) to set that pin high or low.

If you are not sure how to write a Python program for this, consult this tutorial on programming the GPIOs with the GPIO Zero library. Alternatively, if you want to program in C++, you can follow this tutorial on controlling GPIO with C++ on a Raspberry Pi.

LEDs are the primary means by which electronic circuits communicate with us. For example, the Raspberry Pi reports its boot status via its onboard LED. It is one of the most basic electronic components that you should know how to use with your Raspberry Pi.

You can purchase a 500-piece LED kit from Amazon.

Want even more ideas? I put together a free resource with over 75 Raspberry Pi project ideas, each with a quick description, tutorial link, and hardware requirements. Whether you’re just starting out or looking for something to do this weekend, this list will keep you busy for a while. Just click here to get instant access.

Push Buttons and Switches

Input to the Pi.

Having understood how to make our Raspberry Pi communicate with us, the next step is to learn how to communicate with it. This can be done via Push Buttons and Switches.

Push Buttons and Switches come in a variety of sizes and shapes. The most common ones include the dip switch, the push button switch, and the toggle switch.

Remember when we were talking about the breadboard, and we discussed how, in electronics, everything is communicated through connectivity. The switches basically control this connectivity.

A switch has two states: on and off. When the switch is on, both of its contacts, pins, or legs are in a continuous state, and vice versa.

The simplest way to use a switch is to connect one of its pins to a high signal (Vcc or 3.3V) and the other to a GPIO on the Raspberry Pi. In addition, the second pin (connected to the GPIO) should also be connected to Gnd through a resistor.

This way, when the button is in the on state, the 3.3V will be applied across the resistor, pulling the GPIO to a high state. However, when the button is off, the GPIO will be pulled down to Gnd (low). This configuration is commonly called a pull-down configuration.

You can also invert this configuration by connecting the first pin of the switch to Gnd and the other pin to GPIO, along with a pull-up resistor to 3.3V. This configuration is commonly called a pull-up configuration.

However, the pull-down configuration is more intuitive since an on state translates to a high state and vice versa. While in a pull-up configuration, the inverse is true.

Lost in the terminal? Grab My Pi Cheat-Sheet!
Download the free PDF, keep it open, and stop wasting time on Google.
Download now

Now you can write a Python program using the GPIO Zero library to read input from the pin that you have connected to your push button.

Push buttons and switches are available in more advanced packaging as well, with some offering multiple poles. For example, a switch with various states and connections, not just on and off.

If you are planning to build an electronic circuit, push buttons and switches are the primary and most commonly used methods to provide input to your Raspberry Pi. Think about it, the keyboard and mouse that we use every day are just fancy push buttons themselves.

You can find breadboard-compatible momentary push buttons from this Amazon link.

Diodes

Protect circuits from reverse voltage.

The next component—the diode—is a bit difficult to understand. Diodes, like resistors, form the backbone of all advanced electronic circuits. In fact, the LEDs we studied above are Light-Emitting Diodes.

Diodes come in packaging similar to that of resistors. However, unlike resistors, they do not have colored circular bands. Diodes only have one band, which indicates their polarity.

Diodes are analogous to flow control valves in that they allow current to flow in one direction only, i.e., from the anode to the cathode (the side with the small silver band).

Diodes are rarely used as a standalone component. They are instead used in complex circuits to control current flow.

One simple example of how diodes can be used with your Raspberry Pi is to connect diodes to your GPIOs to protect them from reverse current flow or incorrect power-supply connections.

This type of protection is conventional when using any inductive load (like a motor), since when the motor’s magnetic field collapses, reverse current can flow, damaging your GPIO pins. However, such protection is not required when the load is simple LEDs.

Typically, motors are not connected directly to the Raspberry Pi’s GPIO pins, as shown above. The circuit is shown only as a demonstration to understand the purpose of a diode.

Diodes form the backbone of all electronic circuits. There is a reason all complex electronics are generally categorized as semiconductors —the exact material from which diodes are made.

Although they are not used in a standalone configuration, we will see a configuration in the next section that combines them with transistors to control an analog or inductive load safely.

You can find an assortment of diodes with different ratings on Amazon.

Transistors

Act as an electronic switch.

The final component that we will discuss in this guide is the transistor.

Slight correction on what I said earlier, actually, transistors form the backbone of all higher electronic circuits. But the previous statement was not wrong either, since transistors themselves are a combination of diodes.

Transistors are a three-legged component. The three legs are named Collector, Emitter, and Base. They come in various sizes and shapes. However, the two most common packaging types are TO-92 and TO-220.

Lost in the terminal? Grab My Pi Cheat-Sheet!
Download the free PDF, keep it open, and stop wasting time on Google.
Download now

The exact pinout of the transistor varies by packaging type and manufacturer. The best way to determine the pinout is to read the IC’s part number and look up its datasheet.

Additionally, transistors come in two configurations: NPN and PNP.

Image from Byjus.com

We will not go into the full depth of what a transistor can do, because that would get too complex for this guide. In this guide, we will only see how an NPN transistor can be used as a switch.

You see, one of the key properties of the transistor is that when current is applied across its Base and Emitter, the impedance between the Collector and Emitter becomes zero.

What this means is that whenever you apply a high (3.3V or 5V) voltage to the Base pin of the transistor and the Collector is pulled down (Gnd), the connection between the Emitter and Collector becomes continuous (the same as when we pushed a switch).

Using this transistor property, we can solve a common problem with the GPIO pins of our Raspberry Pi: how to drive loads that require more than 3.3V and/or higher current.

For this, you can use the circuit as shown below:

As you can see, we can use the 3.3V from the Raspberry Pi’s GPIO and apply it to the transistor’s base to enable its switching, thereby completing the circuit for the motor.

Also, notice how we smartly placed the diode to protect the circuit from the motor’s flyback current.

This circuit is not limited to driving motors; you can use a transistor as a digitally controlled switch to drive loads that the Raspberry Pi’s 3.3V GPIOs cannot directly drive.

Overall, transistors are useful components that can perform a wide range of tasks. However, the most common use case for interfacing with a Raspberry Pi is to use it as a switch to connect devices that operate at different voltage levels.

You can find an assortment of transistors on Amazon.


🛠 This tutorial doesn't work anymore? Report the issue here, so that I can update it!

Want to connect with other Raspberry Pi fans? Join the RaspberryTips Community. Ask questions, share your projects, and learn from each other. Join now.

Going Further

Now that you know what each of these basic components does, it’s time to start combining them to build something useful. You can think of it like learning words before making sentences—resistors, LEDs, buttons, diodes, and transistors are your building blocks, and together they can create complete circuits.

A great beginner example is building a simple motor control circuit. You can use a push button as the input, a transistor as the electronic switch, a diode for protection, and, of course, a resistor to limit the base current going into the transistor.

When you press the button, the transistor activates, current flows through the motor, and it spins. When you release the button, the diode safely handles the backflow of current from the motor’s coil.

You can use this Python code to enable this circuit, or write your own:

from gpiozero import LED, Button, OutputDevice
from signal import pause

# Pin configuration
led = LED(16)             # LED connected to GPIO 16
button = Button(12)       # Button connected to GPIO 12 (pulled down)
motor = OutputDevice(18)  # Motor (via transistor) controlled by GPIO 18

# Define behavior
def start_motor():
    led.on()
    motor.on()
    print("Button pressed: Motor and LED ON")

def stop_motor():
    led.off()
    motor.off()
    print("Button released: Motor and LED OFF")

# Link button actions
button.when_pressed = start_motor
button.when_released = stop_motor

print("System ready. Press the button to turn on the motor and LED.")
pause()

With just a few parts and a little Python program, you’ve created a working system that takes input, performs an action, and protects itself from damage.

Once you’re comfortable with these basics, you can move on to pre-made modules and sensors. These often include the same parts you’ve just learned about—resistors, transistors, and diodes—but packaged neatly with connectors and control circuitry.

They make it easier to add features like motion detection, temperature sensing, or sound input to your Raspberry Pi projects. If you’re curious about sensors, check out our dedicated guide on using sensors with Raspberry Pi for more ideas and step-by-step examples.

By now, you’ve learned how each basic electronic component works and how to use them safely with your Raspberry Pi. With these building blocks, you can confidently start experimenting, combining parts, and exploring more advanced circuits and sensors in your future projects.

Whenever you’re ready, here are other ways I can help you:

Test Your Raspberry Pi Level (Free): Not sure why everything takes so long on your Raspberry Pi? Take this free 3-minute assessment and see what’s causing the problems.

The RaspberryTips Community: Need help or want to discuss your Raspberry Pi projects with others who actually get it? Join the RaspberryTips Community and get access to private forums, exclusive lessons, and direct help.

Master your Raspberry Pi in 30 days: If you are looking for the best tips to become an expert on Raspberry Pi, this book is for you. Learn useful Linux skills and practice multiple projects with step-by-step guides.

Master Python on Raspberry Pi: Create, understand, and improve any Python script for your Raspberry Pi. Learn the essentials step-by-step without losing time understanding useless concepts.

You can also find all my recommendations for tools and hardware on this page.

Similar Posts