Hey guys, I'm trying to build an escape rooms for my friends. I have a box with 5 potentiometers. I'm looking to have an orange light blink constantly. When the knobs are in the wrong order i want a red light on, when the knobs are correct I want the red to shut off and a green to go on. I've watched tutorials and used AI to help but I can't get the thing to work.
// --- Pin Assignments ---
const int potPins[5] = {A0, A1, A2, A3, A4}; // Potentiometers
const int orangeLED = 2; // Always blinks
const int redLED = 3; // ON when any knob is wrong
const int greenLED = 4; // ON only when all knobs are correct
// --- Target values for each knob ---
const int targets[5] = {300, 512, 700, 400, 600}; // Adjust per puzzle
const int tolerance = 40;
/*
Knob Positions:
- Knob 1 (A0): Target = 300 β Acceptable: 260β340 (~1/3 turn)
- Knob 2 (A1): Target = 512 β Acceptable: 472β552 (centered)
- Knob 3 (A2): Target = 700 β Acceptable: 660β740 (~2/3 turn)
- Knob 4 (A3): Target = 400 β Acceptable: 360β440 (~40% turn)
- Knob 5 (A4): Target = 600 β Acceptable: 560β640 (~just past center)
*/
void setup() {
pinMode(orangeLED, OUTPUT);
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(orangeLED, HIGH);
delay(200);
digitalWrite(orangeLED, LOW);
delay(200);
bool allCorrect = true;
for (int i = 0; i < 5; i++) {
int val = analogRead(potPins[i]);
Serial.print("Knob ");
Serial.print(i);
Serial.print(": ");
Serial.println(val);
if (abs(val - targets[i]) > tolerance) {
allCorrect = false;
}
}
if (allCorrect) {
digitalWrite(greenLED, HIGH);
digitalWrite(redLED, LOW);
} else {
digitalWrite(greenLED, LOW);
digitalWrite(redLED, HIGH);
}
}
And this is how I wired it:
POTENTIOMETER WIRING (REPEAT FOR ALL 5)
Pot Pin β Connect To
Left leg β GND rail (blue)
Middle leg β A0βA4 (respectively)
Right leg β 5V rail (red)
Assignments:
-
Pot 1 β A0
-
Pot 2 β A1
-
Pot 3 β A2
-
Pot 4 β A3
-
Pot 5 β A4
LED WIRING
Orange LED (Blinking):
-
Long leg (anode) β D2
-
Short leg β Resistor β GND rail
Red LED (Wrong):
-
Long leg β D3
-
Short leg β Resistor β GND rail
Green LED (Correct):
-
Long leg β D4
-
Short leg β Resistor β GND rail
Anyone know what I'm doing wrong?
