Coding Blog

Combination Lock Box

We built the combination lock box with passcode Arduino coding. The red LED light shows that the lock is still secured. When we push the button 1 -> 2 -> 3 -> 2 in order, the green LED will read that it is unlocked.

Here’s the Arduino code for the combination lock box!

#define NOTE_A6 1760

#define NOTE_B5 988

#define NOTE_C7 2093

//define pins

const int redButton = 11;

const int blueButton = 12;

const int greenButton = 10;

const int redLed = 9;

const int greenLed = 8;

const int buzzer = 7;

int toneLength = 2;

int correctTones[] = {988, 1760};

int incorrectTones[] = {208, 196};

int code[] = {1,2,3,2}; //this is the code that we set for our lock

int userEntered[4]; //empty array to store the values entered by the user

int buttonCheck; //counter to store number of times buttons have been pressed