Before you start any band
Identify Which part have I got?
Two sketches that tell you what is in your hand, for the two parts in this kit that come in more than one kind.
Sketches for this project
Every file opens with a plain-English header saying what it does and how to wire it, hole by hole.
Two parts, two kinds each
Most of what is in your box is exactly one thing. A resistor is a resistor. An LED is an LED.
Two parts are not like that. Each comes in two kinds that look almost the same and behave completely differently, and kits ship whichever kind was cheapest that month. If nobody has told you which you have, you will find out the hard way in the middle of a build.
Two sketches settle it: about ten minutes for the buzzer and fifteen for the RGB light. Do them once, write the answers on a slip of paper, and put the paper in the box.
Who needs to do this
The facilitator, once, for the whole hub, is ideal. Label the bags and nobody else ever has to think about it.
If you are working alone and nothing is labelled, do the buzzer one before Band 3 and the RGB one before Band 2. Twenty-five minutes for both, and they save you an hour of the wrong kind of confusion.
Which buzzer have I got?
10 minThere are two kinds of buzzer and they are the same size, the same colour, and have the same two legs.
Look first
Turn the buzzer over and look at the bottom.
Almost certainly an active buzzer. There is a tiny circuit sealed inside it whose only job is to switch back and forth thousands of times a second, which is what a sound is. Because that circuit is already in there, the buzzer makes its own note: switch it on and it beeps. It knows one note, and it cannot be persuaded otherwise.
Almost certainly a passive buzzer. There is no such circuit inside, so it has no note of its own. Switch it on and it clicks once and then sits there. You have to do the switching back and forth yourself, from the board, which is exactly what tone does, and that is why you get to choose the note.
“Almost certainly” is not certainly, and some buzzers are sealed either way. So prove it.
Then prove it
Wire it. If one leg is longer than the other, or one is marked +, that leg goes to pin 8 and the other to the − rail. If both legs are the same length and nothing is marked, either way round works, and that on its own is a hint that yours is the passive kind, because a bare piezo disc has no right way round. Then one wire from the − rail to a GND pin.
Upload id_01_which_buzzer.ino and open the serial monitor (Tools, then Serial Monitor, 9600). Then listen while you read, because the sketch tells you what it is about to do before it does it.
Step 1 switches the pin on for a second. Step 2 asks for 440 Hz for a second. Watch which is which and listen to both.
It beeped both times, and both beeps sounded the same. You have an active buzzer. It made its own note in step 1, and in step 2 it ignored your request and made the same note again.
It clicked once in step 1, then played a clear note in step 2. You have a passive buzzer. There was nothing inside it to make a sound in step 1; in step 2 you gave it one.
Write it down, then read this
| Band | With a passive one | With an active one |
|---|---|---|
| Band 3, the lock | Works, once you make two swaps. The sketch is written for an active buzzer, so change every digitalWrite(buzzerPin, HIGH) to tone(buzzerPin, 1000) and every LOW to noTone(buzzerPin). Band 3 Part 11 stage three walks you through it. | Works as written. This is the kind Band 3 asks for. |
| Band 5, the game | Works fully. Four lights, four different notes. | Works, with one note instead of four. The game is still a game; you lose the pitch, which is a real loss but not a blocking one. |
| Band 7, the guard | Works fully. Beep rate and a rising note. | Works. You get the beep rate, which is the part that matters, and not the rising note. |
If you have two buzzers, test both. Kits very often contain one of each, and if that is true of yours then nothing in this course is closed to you at all. Mark them, keep them apart, and you never think about it again.
Which RGB light have I got?
15 minThis one has two questions inside it, and Band 2 needs both answered.
Question one: what shape is it?
Tip the bag out and look. You may find one of these, or both.
A discrete RGB LED. Three lights inside one case, sharing one leg. You fit three resistors yourself, one per colour.
→ Band 2's core build is written for this. Use it.
An RGB module. The same three lights, on a board. Usually, but not always, with the three resistors already fitted.
→ Build the module Swap instead, after the check in the next box.
If you have both, build the core with the loose one first. The module afterwards takes twenty minutes and makes a good second look at the same idea.
If you have only the module, that is fine and Band 2 still works. What you would have missed is why the resistors are there, so the module page makes you go and find them on the board instead of fitting them.
Before you power a module: turn it over
Two kinds of RGB module are sold in the same kits and they look alike from the front. Only one of them has the resistors. Getting this wrong damages the light and the pin, which is exactly what the resistors were for.
The resistors are fitted. This is the common kind.
→ Wire the three colour pins straight to Arduino pins. No resistors of your own.
This module has no resistors. Wired straight to a pin at 255 it would pull something like five times what a pin is rated for.
→ Put a 220 ohm resistor in each of the three colour wires yourself, exactly as the loose LED needs. Then carry on as normal. Write on your slip of paper that yours is the bare kind.
If you cannot tell, add the three resistors anyway. A module that already has them will simply look a little dimmer, and nothing is harmed. That is the safe direction to be wrong in, and choosing the safe direction when you are unsure is a habit worth building now.
Question two: which way round is it?
Both shapes come in two wirings, and you cannot tell by looking. This is the one you have to test.
The shared leg goes to ground. 0 is off and 255 is bright, which is what everything in Band 2 assumes.
The shared leg goes to 5V. It is backwards: 0 is bright and 255 is off. Everything still works, but two things have to change: the shared leg moves to 5V, and then the numbers turn upside down in the code.
The test
Wire whichever one you have, following the wiring comment at the top of id_02_which_rgb.ino. It gives both, hole by hole.
Upload it, then open the serial monitor (click Tools, then Serial Monitor, and set the speed box at the bottom right to 9600). Watch the light while you read the words it prints. It shows red, green, blue, all-on and all-off, and names each one as it goes.
Which way round. If “all on” looked white and “all off” looked dark, it is common cathode and there is nothing to change. If “all on” was dark and “all off” was white, it is common anode.
Whether the colours are in the order the sketch thinks. If it said red and you saw green, your legs are in a different order. Nothing is broken.
Which pin turned out to be which colour, if they were not in order. Write the three down.
On a loose LED: take the wire running from
j6 to the − rail and move that end to the + rail — the outer strip along the same top edge, the one marked with a red line and a +, not the inner one you have used all band. Then run one new wire from that same + rail to the Arduino's 5V pin. Leave the three resistors and the three pin wires exactly where they are. On a module: move the fourth pin's wire from GND to 5V.Then check it by eye before the USB goes back in. This is the only step in the whole band that puts five volts onto the breadboard, and the one mistake that can damage the board is joining 5V to GND. So look: no wire runs from the + rail to a GND pin, and no wire runs from the − rail to 5V. If both of those are true, plug in. Run the sketch again. It will light this time, and “all on” will now be the dark one.
f6. On a module it is the pin marked -, GND, VCC or +. Then check that the − rail really reaches a GND pin.If yours is common anode, there are two steps and you need both
Everything in Band 2 still works. Do both of these, in this order.
Step one, the wiring, and it is not optional. The shared leg must go to 5V, as the box above described. A common-anode part with its shared leg on the − rail cannot light in any state at all, because the shared leg has to sit above the three colour legs for anything to flow through them. This is what Band 2 Part 12 tells you to do, and it is what makes the light work.
Step two, the numbers, and this is the part people miss. Rewiring makes it light. It does not un-invert it. With 5V on the shared leg, 255 puts five volts on both ends of the light and you get nothing, while 0 gives you full brightness. So turn every number upside down inside showColour as well:
analogWrite(redPin, 255 - r);
analogWrite(greenPin, 255 - g);
analogWrite(bluePin, 255 - b);
Subtracting from 255 undoes exactly what the hardware did, and from then on every number on every page in this course means what it says again. You can also just live with the inversion and remember that 0 is bright, which is where Band 2 Part 12 leaves you. That works, and it will catch you out about once a fortnight for the rest of the course. Write on your slip of paper which of the two you chose.
A module works exactly the same way. A module whose fourth pin is marked VCC or + is the common-anode kind: that pin goes to 5V, and its numbers are then upside down. b2_05_rgb_module.ino says the same.
Notice what just happened. It looked like a choice between a hardware fix and a software fix, and it was not: the hardware step was compulsory and it only got you half way there. That pattern is very common. The habit worth building is to ask, after any fix at all, what exactly did that change, and what did it leave alone?
The slip of paper
Write these seven things and put the paper in the box:
- Buzzer 1 is active or passive
- Buzzer 2 is active or passive
- RGB shape: loose LED, module, or both
- If a module: does it have its own resistors, or did you add three
- RGB wiring: common cathode or common anode
- Which pin is red, which is green, which is blue
- The date, so the next person knows whether to trust it
That is twenty-five minutes now against an hour of everybody's confusion later, and it is the single highest-value thing a facilitator can do before a cohort starts.