Sign in
Outline · Arduino Uno

Crack the Code

Crack the Code is the NSW Technology Mandatory 7–8 design project, rebuilt as a self-paced course on Little Bird. You'll go from your first `digitalWrite(LED, HIGH)` to a complete alarm/alert system using a real Arduino + ThinkerShield kit. By the end you'll be reading buttons, potentiometers and light sensors, driving LEDs and piezos, and writing real Arduino C++ — the same code your kit ships with.

Reference

Snippets · pin map · gotchas

Common imports & pin setup

// The ThinkerShield wires the LEDs to D12-D9, the button to D7, and
// the buzzer to D3. We use friendly names so the code reads better.
const int LED_PIN = 12;
const int BUTTON_PIN = 7;
const int BUZZER_PIN = 3;
const int POT_PIN = A5;

Read a button

pinMode(BUTTON_PIN, INPUT);
int pressed = digitalRead(BUTTON_PIN);   // HIGH (1) or LOW (0)

Read a potentiometer or LDR

int value = analogRead(POT_PIN);          // 0..1023
Serial.println(value);                    // open the Serial Monitor at 9600 baud

Play a tone on the piezo

tone(BUZZER_PIN, 600, 30);                // 600 Hz for 30 ms
delay(150);
noTone(BUZZER_PIN);

Pin cheatsheet

PinUsed forNotes
D12 LED · onboard ThinkerShield red
D11 LED · second LED yellow
D10 LED · third LED green
D9 LED · fourth LED blue
D7 Button momentary push
D3 Piezo buzzer PWM-capable
A5 Potentiometer 0..1023
A4 LDR (light sensor) 0..1023

Gotchas the comments thread learned the hard way

1
Always set the board's pinMode in setup() before you digitalWrite or digitalRead it — otherwise the pin can float and read garbage.
2
Buttons are usually wired active-low on the ThinkerShield: digitalRead == 0 means pressed, 1 means released. Use INPUT_PULLUP to make this work without external resistors.
3
analogRead returns 0..1023 (not 0..255). When you map it into delay(...), you'll get up to a one-second pause — your LED looks frozen at high readings.
4
Serial.begin(9600) must match the baud rate set in the Serial Monitor's drop-down — mismatched baud is the #1 cause of garbage characters.
5
Powering the Arduino from USB while also plugging in a 12V supply can damage the regulator. Use one source at a time until you understand the jumper.