Level 1Unit C · Session 18
18

Unit C · Circuits and sensing

Your own circuit

What we are making: the same blink, but on a light you wired up yourself on the breadboard — not the one the factory put there.

Photo: a breadboard with a single red LED lit, wired to an Arduino
Photo: a breadboard with a single red LED lit, wired to an Arduino

The idea

Electricity has to go round in a circle. It leaves the board through a pin, travels through whatever you have wired up, and comes back into the board through the hole marked GND. If the circle is broken anywhere, nothing happens at all.

An LED only works one way round: the long leg is positive and faces the pin. Backwards, it simply does not light. It is not broken.

Why the resistor is there

A pin pushes out more than an LED can survive. The resistor narrows the flow, like a nozzle on a hosepipe. Without one the LED glows brilliantly for a second, then dies for good.

⚠ Careful
Every LED in this book gets a resistor. Every single time. There is no situation this year where you connect an LED straight to a pin.

Wire it up

1
Breadboard
1
LED
1
Resistor 220Ω
2
Jumper wires
1
Arduino board
+−+−jihgfedcba151015202530+GNDpin 9
Copy this exactly. The LED's long leg goes in column 10, the short leg in column 12.
  1. Push the LED's long leg into hole e10 and the short leg into e12. The two legs must be in different columns — if they share a column the electricity skips straight past the LED.
  2. Push one end of the resistor into b12 (the same column as the short leg) and the other end into b16.
  3. Run a black jumper wire from c10 to the GND pin on the Arduino.
  4. Run a blue jumper wire from d16 to pin 9 on the Arduino.
  5. Check every one of those four before you plug in the USB.
Pins used9GND

The code

Last session's program with one change: pin 13 becomes pin 9.

Your program
when the board starts up
forever
set digital pin (9) to HIGH
wait (1) seconds
set digital pin (9) to LOW
wait (1) seconds
💡 Tip
You did not have to rebuild the program from scratch. Changing one number moved the whole thing to a different pin. Programs are meant to be changed, not retyped.
Screenshot: the same blink program in mBlock with the pin number changed to 9
Screenshot: the same blink program in mBlock with the pin number changed to 9

Try it

What should happen: your LED blinks once a second. The board's own one stays dark — nothing is talking to pin 13 any more.

🔮 Try this
Move the whole circuit along to different columns — say columns 20 and 22 instead of 10 and 12 — and make it work again. The column numbers do not matter. What matters is which holes are joined to which.

If it goes wrong

Almost nobody gets this first time. Finding the fault is the skill.

What you seeWhyWhat to do
Nothing lights at allThe LED is in backwards. This is the most common fault by a long way.Pull the LED out, turn it round, push it back in. Long leg in column 10.
Still nothingA leg is in the wrong column, so the circle is broken.Follow the path with your finger: pin 9 → resistor → LED → GND. Say each hole out loud.
Still nothing, and the wiring looks rightThe jumper wire is not pushed all the way in.Press each wire end down firmly. They should not wobble.
It lights but never blinksIt is wired to 5V instead of pin 9.5V is always on. Move the wire to pin 9, which your program can switch.
It lit once, very brightly, then went dark foreverThe resistor was missing or in the wrong column. The LED is gone.Get a new LED from the spares tray. Tell your teacher — nobody is in trouble for this.

What you learned

  • Electricity needs a complete circle: out of a pin, through the parts, back to GND.
  • An LED only works one way round. Long leg towards the pin.
  • A resistor protects the LED from too much current.
  • A column on the breadboard joins five holes together.
Challenge optional — only if you finish early
  • Make the two LEDs alternate, then make them both fade instead of switching.
17. First blink