Get started with electronics and Raspberry Pi

By Mark Vanstone. Posted

Over the past few years, Raspberry Pi has gone from a small experimental computer to a very capable all-round system, while still retaining its small footprint. It has embedded itself in the hearts and minds of makers, coders, educators, inventors, and electro-artists around the world. Its flexibility and computing power now makes it the go-to platform for embedded systems (like smart devices) and workhorse tasks such as controlling other network systems or even robotics. The range of tasks Raspberry Pi can achieve becomes wider all the time as the community creates new ways to use it.

Raspberry Pi is the gateway to electronics and computing

Raspberry Pi has made a huge impact, not only on computer science education but also in the realm of makers and inventors. As well as being a really good-value computer, it gives the owner endless possibilities of connecting other electronics to it to produce useful gadgets and impressive demonstrations.

Raspberry Pi is your gateway to the new frontier of creative technology. If you can master the basics of how to connect electronics to a Raspberry Pi, you can use the same techniques to start inventing your own gadgets and electronic tools. If these are your first steps into electronics, you have a very exciting journey ahead.

See also:

Expand and experiment

In the early days of home computers, most models had expansion ports of one sort or another and, very often, upgrading them involved opening up the case and soldering new circuits, or at least plugging in chips into empty slots. These days, you are lucky if your home computer has USB connectors for accessories, and plugging in home-made contraptions is definitely not recommended.

Raspberry Pi is different because its design encourages the owner to plug in extra devices and even experiment with your own prototype circuits. Raspberry Pi has standard USB and Ethernet ports, a camera connector, WiFi, and HDMI video output. But the crowning glory of connectivity is its GPIO (general-purpose input/output) 40-pin header, which provides the tinkerer with access to the inner workings of Raspberry Pi. You can even write code to control electronics that are plugged in to the GPIO pins.

Getting started with GPIO electronics: what you’ll need

If you are lucky enough to have a local electronics or hobby store, you will no doubt be able to find all the electronic components we will talk about for a few pounds, dollars, or euros. Failing that, there are many fully stocked online outlets that can provide them. All you will need to start with is a breadboard, some jumper leads, a resistor (200 Ω to 470 Ω), and an LED.

Raspberry Pi GPIO pins

You can use Raspberry Pi’s GPIO pins to pass electrical voltage to and from other components. Some of the pins have specific uses, such as power or ground connections, and others can be configured with software programs to send signals between Raspberry Pi and the rest of the circuit. Above is a breakdown of all the pins. Look carefully at physical pins 1 and 6: these will be the pins we use in our LED circuit later. Note that the pin numbers aren’t the same as the GPIO numbers; for example, GPIO 2 is actually physical pin 3.

GPIO Pins on Raspberry Pi

Prototype circuits with breadboards

Breadboards come in several different sizes and are made of plastic with a matrix of holes. In each hole is a connector which joins it to other holes on the same row.

Breadboards come in several sizes to enable prototyping of a wide variety of projects

The larger breadboards have two long rows of holes at the top and bottom. Sometimes called ‘rails’, these are generally used for power and ground connections. They are connected together as indicated on the diagram above.

The inner part of the breadboard has two sections of holes. Each section has rows of five holes which are connected as indicated on the diagram. The two halves of the breadboard are a mirror image of each other.

The break along the centre of the breadboard, often known as the ‘gutter’, enables mounting of integrated circuits (chips) with the legs of the chip going either side of the break.

Click here for a more detailed article on using a breadboard.

A breadboard is used to connect electronics. All five holes in a row are connected; all the long blue and red lines on the end are all connected (and are used to for power)

Basic prototyping components

Here are the common prototyping components you will find:

Jumper lead

These connect your components to the Raspberry Pi. They can either have male or female end connectors (you need female for the GPIO pins) and it’s a good idea to have a mix of both.

LED

Light-emitting diodes come in various colours. They glow when electricity flows through them. Because they are a diode, the current will only flow in one direction, so make sure that it is connected the right way round: the longer leg is the positive one and should be connected to the power (or GPIO output) pin. Always use a resistor in series with LEDs, otherwise they are likely to draw more current than they can handle and burn out.

LED

Resistor

Resistors are available in various formats, but this is the most common format for prototyping. The coloured rings around the resistor indicate how much resistance it provides. For more details about how to read resistor values, see The MagPi magazine issue 64.

Use resistors to control the amount of electricity flow around your circuits

Switch

Switches make and break circuits. When connected in series in a circuit, a switch will allow or stop the flow of electricity. You can get switches that stay in the position in which they are set, or ones that you need to keep your finger on to keep the circuit connected.

Speaker

Speakers can be huge and very loud or they can be very small – small enough to fit on a breadboard. These small speakers are called piezoelectric and are great for making robotic noises, but not much good for hi-fi music applications.

Speaker

Capacitor

Capacitors store and release electrical charge. They can be used to even out the electrical current or provide a greater flow for a short time. Be careful when using capacitors, as they can still hold charge after the circuit has been disconnected.

Transistor

Transistors are used in many types of circuits. They can be used either as an amplifier, which means that a small current goes in but a bigger current comes out, or as an electrical switch to change the amount of electricity flowing through circuit. A transistor has three legs or connectors: the emitter, the collector, and the base.

Servo

Servos are used a lot in robotics for making things move. They can be connected directly to Raspberry Pi via the GPIO pins, but there are also extra plug-in boards (or HATs) that make it easier to connect many servos and control them more easily. Normally we use digital servos which use PWM (pulse-width modulation) signals to turn the armature on the servo from one position to another.

Servo

Battery

Batteries can be all kinds of shapes and sizes, but for simple electronics projects you will normally be using 1.5 V AA or AAA type cylindrical batteries or 9 V square ones. Make sure you always have some spares or perhaps you may want to use rechargeable ones. Rechargeable batteries cost more, but can be used over and over. Make sure you connect batteries correctly and never directly connect the two contacts together, as even small voltage batteries can get very hot or even explode if ‘short-circuited’.

Potentiometer

Potentiometers are variable resistors and usually have a twisting knob or a slider to change the resistance. They have three connectors and can be used as game controllers or volume controls. Be careful if you are using a potentiometer instead of a resistor in your LED circuit: if you turn the resistance right down to zero, you may burn out your LED.

Potentiometer

Prototyping kits for Raspberry Pi electronics

Instead of buying components separately, you will find it a lot easier to buy a kit packed with electronic components especially selected for Raspberry Pi.

CamJam EduKits

There are currently three CamJam EduKits available: a starter kit with all the components and more to make our LED circuit, a sensors kit to explore getting input from the world around you, and a robotics kit with wheels and motors to make your Raspberry Pi into a robot.

CamJam EduKit

Adafruit Parts Pal

The Adafruit Parts Pal is a more comprehensive kit. It contains many popular components and prototyping parts, including LEDs, resistors, cables, sensors, and mechanical parts.

Adafruit Parts Pal

Elecrow CrowPi Educational Kit

This is the daddy of all-in-one experimentation kits. There are chips and sensors, dials, speakers, numeric displays, and even a 7-inch HDMI touchscreen. It was developed with a Kickstarter appeal and is available directly from Elecrow in the US, or Amazon in the UK.

Elecrow CrowPi

Make an LED light circuit

Building an electronic LED light circuit is a good way to start with electronics projects. To build this simple LED circuit you need the following:

  • Breadboard

  • LED

  • 470 Ω resistor

  • 2 × male-to-female jumper wires

Everything can be found in the CamJam EduKit #1 (£5)

Let’s dive into some practical circuit making with an example of how we can use the GPIO pins on the Raspberry Pi to make a circuit. We will go into the details of what the components are in a little while, but let’s look at what a circuit actually looks like on a diagram. We will use the power source of Raspberry Pi to light an LED (light-emitting diode). When electricity is passed through an LED, it glows. We will also need a resistor in our circuit to limit the amount of electricity that goes through the LED. If too much electricity flows, the LED may burn out.

WARNING: When connecting components to the Raspberry Pi, it is always best to have the power off and unplugged in case you make a mistake with your wiring.

The wires we use to connect components are called jumper leads. We connect components by mounting them on a breadboard. When the resistor and LED are placed in the circuit correctly, the LED will light up.

Step 1: Turn off the power

Make sure you have shut down your Raspberry Pi and unplugged its power cable. Plugging in jumper leads while switched on may be tolerated by Raspberry Pi, but in some cases it can cause a system crash or even damage to the hardware.

Build the circuit

Connect the components as shown in the wiring diagram below. Take careful note of the GPIO pins that you are connecting. The precise positioning of components on the breadboard is not so important, but make sure that the LED’s longer (positive) leg is connected to the 3V3 power pin via the jumper lead.

Light it up

When you are sure that you have connected everything correctly, plug in your Raspberry Pi. After a short time, the LED should light up as soon as the power GPIO pins are energised. If the LED does not light up, try connecting it the other way around, as it will only work one way.

You'll find two Raspberry Pi electronics projects in The MagPi magazine issue 91: Cheerlights and Reaction timer, by Dr. Simon Monk. Follow these tutorials to continue your Raspberry Pi electronics journey.

From The MagPi store

Subscribe

Subscribe to the newsletter

Get every issue delivered directly to your inbox and keep up to date with the latest news, offers, events, and more.