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.
- 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.
If the LED is placed into the circuit the wrong way round, current ceases to flow, and the LED no longer lights up.
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|
You will use the two pins labelled on this diagram:
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.
- Take one of your female-to-male jumper cables. Connect the female end to the 3V3 pin on your Raspberry Pi.
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.
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.
- 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.
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:
- Take another female-to-male jumper cable and push the male end into the same row as the resistor’s second leg.
- Take the female end of the jumper cable and plug it into your ground pin.
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.