Projects / Escape room puzzle box

Escape room puzzle box

Intermediate4 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. NANOTCS34725

    Test the colour sensor

    Print raw red, green and blue.

  2. NANO

    Test the magnet sensor

    Print the state.

  3. NANO

    Test the keypad

    Print keys.

  4. NANO

    Write the states

    One puzzle at a time.

  5. NANO59°

    Add the servo latch

    Locked and open angles.

  6. NANO

    Add the reset

    A hidden key press.

  7. NANO

    Test with friends

    Watch where they get stuck.

In short

How do you build an escape room puzzle box?

A box opens only after players solve three puzzles: a colour code, a hidden magnet and a keypad number. You need Arduino Nano, 4x4 matrix keypad (membrane), TCS34725 colour sensor, Hall Effect Sensor A3144, SG90 Micro Servo, LED 5 mm green × 3, Resistor 220 Ω × 3, Battery holder 4 × AA with switch and Resistor 10 kΩ. It takes 7 steps and about 240 minutes.

Level
Intermediate
Time
About 240 min
Parts
9

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Keypad rows and columnsNano D2 to D9Keypad
TCS34725 SDA and SCLNano A4 and A5Colour sensor
TCS34725 VIN and GNDNano 5V and GNDPower
A3144 outputNano D10, with 10 kΩ to 5VMagnet sensor
Servo signalNano D11Latch
Puzzle LEDsNano D12, D13 and A0 through 220 ΩOne per puzzle
4 AA holder plusServo plus and Nano VIN6 V supply
4 AA holder minusNano GND and servo groundCommon ground

Code

Each puzzle is a state, so the box can only move forward in order; a state machine is just a variable holding the current stage, with a small test for each one. The colour puzzle checks that red clearly dominates the other channels, so adjust that rule for your lighting and cards. The A3144 pulls its output low near a magnet, so hide a small magnet in a prop and hold it to the marked spot. Change the CODE to your own number. The servo needs a stronger supply than the Nano's regulator should give, so the 6 V battery pack runs the servo directly and also feeds the Nano's VIN pin. Arduino IDE, board "Arduino Nano" (try the Old Bootloader option if the upload fails). Make sure the box can always be opened from inside the lid with a hidden release, so nobody is ever locked out of anything important.

Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

// Escape box: colour card, hidden magnet, keypad code, then the servo latch opens.
// Libraries: Keypad, Adafruit TCS34725, Servo. Board: Arduino Nano.
#include <Keypad.h>
#include <Wire.h>
#include <Adafruit_TCS34725.h>
#include <Servo.h>
const byte ROWS = 4, COLS = 4;
char keys[ROWS][COLS] = {{'1','2','3','A'},{'4','5','6','B'},{'7','8','9','C'},{'*','0','#','D'}};
byte rowPins[ROWS] = {2, 3, 4, 5};
byte colPins[COLS] = {6, 7, 8, 9};
Keypad pad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
Adafruit_TCS34725 tcs(TCS34725_INTEGRATIONTIME_154MS, TCS34725_GAIN_4X);
Servo latch;
const int LED1 = 12, LED2 = 13, LED3 = A0, HALL = 10;
const char CODE[] = "4721";
int stage = 0;
String entry = "";
void setup() {
  pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); pinMode(LED3, OUTPUT); pinMode(HALL, INPUT);
  latch.attach(11); latch.write(0);                // locked
  tcs.begin();
}
void loop() {
  if (stage == 0) {                                // puzzle 1: show a mostly red card
    uint16_t r, g, b, c;
    tcs.getRawData(&r, &g, &b, &c);
    if (c > 200 && r > g * 2 && r > b * 2) { stage = 1; digitalWrite(LED1, HIGH); }
  } else if (stage == 1) {                         // puzzle 2: hidden magnet pulls the sensor low
    if (digitalRead(HALL) == LOW) { stage = 2; digitalWrite(LED2, HIGH); }
  } else if (stage == 2) {                         // puzzle 3: keypad number
    char k = pad.getKey();
    if (k) {
      if (k == '#') entry = "";
      else entry += k;
      if (entry.length() == 4) {
        if (entry == CODE) { stage = 3; digitalWrite(LED3, HIGH); latch.write(90); }
        entry = "";
      }
    }
  } else if (stage == 3 && pad.getKey() == '*') {  // hidden reset: press * once the box is open
    stage = 0; latch.write(0);
    digitalWrite(LED1, LOW); digitalWrite(LED2, LOW); digitalWrite(LED3, LOW);
  }
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Red cardFirst LED lights
Magnet at the spotSecond LED lights
Correct codeThird LED and the latch opens
Hidden resetBox relocks and the LEDs go out

If it does not work

Colour never triggers

Adjust the red rule for your light.

Servo jitters

Power it from the battery pack, not the Nano.

Keypad ghosts

Check the row and column order.

Magnet not seen

Use a stronger magnet or move it closer.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the escape room puzzle box?

Arduino Nano, 4x4 matrix keypad (membrane), TCS34725 colour sensor, Hall Effect Sensor A3144, SG90 Micro Servo, LED 5 mm green × 3, Resistor 220 Ω × 3, Battery holder 4 × AA with switch and Resistor 10 kΩ.

How long does the escape room puzzle box take to build?

About 240 minutes for a intermediate maker, in 7 steps.

How do I know the escape room puzzle box works?

Red card: First LED lights. Magnet at the spot: Second LED lights. Correct code: Third LED and the latch opens.

Colour never triggers: what should I check?

Adjust the red rule for your light.

Servo jitters: what should I check?

Power it from the battery pack, not the Nano.

Keypad ghosts: what should I check?

Check the row and column order.

Magnet not seen: what should I check?

Use a stronger magnet or move it closer.