Want to keep learning?

This content is taken from the Raspberry Pi Foundation & National Centre for Computing Education's online course, Teaching Physical Computing with Raspberry Pi and Python. Join the course to learn more.

Physical computing essentials

Now that you are equipped with your handy tools, both hardware and software, it’s time for you to learn some electronic basics. This foundational circuit theory will equip you for the rest of the course.

Some circuit theory

The following image shows a simple circuit consisting of four basic components connected together with wires.

A circuit consisting of two batteries, an LED, a resistor and a switch, all connected in a single loop.

  • The cell (battery) provides energy to the circuit in the form of electricity. A cell has a positive and a negative side. Electric current flows from the positive side of the cell, around the circuit, to the negative side of the cell.
  • The light-emitting diode (LED) is a type of output component. When current flows through it, the LED emits light.
  • The resistor helps protect the LED by reducing the current going through the LED. Without the resistor, the LED could burn out, in much the same way as a fuse does in many of your household appliances.
  • The switch acts as a break in the circuit. When the switch is open, no current can flow through the resistor and LED. When the switch is closed, the circuit is complete and current can flow, causing the LED to switch on.

Animation of the circuit with current flowing and the LED lit only when the switch is closed.

If the LED is placed into the circuit the wrong way round, current ceases to flow, and the LED no longer lights up.

An animation of the circuit with the switch closed and the LED connected two different ways. No current flows when the LED is connected the  incorrect way around.

The clue to why this happens is in the name light-emitting diode. A diode is a component that only lets current flow through it in one direction. You’ll need to remember this when you set up your own circuit.

Building a simple circuit

To build the circuit you just learnt about, you will need the following components:

Breadboard Male-to-female jumper wires LED 330-ohm resistor
Picture of breadboard Picture of jumper wires Picture of LED Picture of resistor

You will use the two pins labelled on this diagram:

Illustration of the pins on a Raspberry Pi, placed next to a battery. The top left pin (labelled 3V3) and the right bin on the third row (labelled GND) are highlighted.

3V3 means 3.3 volts; this pin is needed to provide power to the circuit, just like the positive side of a battery. GND means ground, and when using Raspberry Pi, a circuit can only be complete if the current can flow to a ground pin.

  1. Take one of your female-to-male jumper cables. Connect the female end to the 3V3 pin on your Raspberry Pi.
  2. Plug the male end into your breadboard, in row 1.

    If you were to remove the back of a breadboard, you would see that every hole of each row (with the board in portrait orientation) is connected by a small strip of metal that acts just like a wire in the circuit. The rows are separated by a gap in the middle, called the ravine.

    Cross-section of breadboard showing metal bars across the rows (but not the ravine or the two outermost lines on each side) and metal rails going lengthways along the two outermost lines of pins on each side.

    Look at your LED. You should see that one leg is longer than the other. The long leg is sometimes called the anode, and this leg should always be connected to the positive side of a circuit (the 3V3 pin). One way to remember this is to imagine the longer leg as having had something added (positive), and the shorter leg as having had something taken away (negative). The LEDs might sometimes have legs the same length, in which case you can tell which side is the anode because the plastic rim of the LED will be mostly round, while the negative side (called the cathode) is slightly flattened.

    Image showing the flattened side of an LED labelled "Negative"

  3. Push the long leg of the LED into row one, close to the ravine. Place the shorter leg into row one on the other side of the ravine.
  4. Now find your resistor. A resistor is a non-polarised component, so it doesn’t matter which way round it goes. Push one leg into the same row as the shorter one of the LED legs, so that it connects to the LED, and the other leg into any other free row. Your circuit should now look a little like this:

    An LED straddles the ravine of a breadboard, with the longer leg on the left hand side. In the same row, a red wire goes from another hole on the breadboard on the left hand side to the 3V3 pin of a Rasbperry Pi. A resistor connects two rows of the breadboard on the right hand side of the ravine, one of these rows contains the shorter leg of the LED.

  5. Take another female-to-male jumper cable and push the male end into the same row as the resistor’s second leg.
  6. Take the female end of the jumper cable and plug it into your ground pin.

Animation showing a black wire being added to the circuit above. The wire goes from the GND pin on a Raspberry Pi to a row on the right hand side of the ravine, which one end of the resistor is also plugged into (but not the LED). When it is connected, current flows and the LED turns on.

If your LED doesn’t light up, try the following:

  • Check your Raspberry Pi is on
  • Check all your components are firmly in the breadboard
  • Check your LED is the right way round
  • Try another LED

If you are still having trouble, leave a comment below and our facilitation team will help you out.

But what about the switch?

We mentioned earlier that Raspberry Pi could act like both the cell and the switch, but in your circuit, the pin we’re using (3.3V) is always on. However, other pins can be switched on and off.

To change the state of the pin, you’re going to need a few lines of Python code, which you’ll write in the next step.

Share this article:

This article is from the free online course:

Teaching Physical Computing with Raspberry Pi and Python

Raspberry Pi Foundation