This sounds as an escape room puzzle.
From an electronic point of view you need something to lock/unlock the box like a servo motor, a stepper motor or (best option) a normally closed solenoid. You might need some components to drive such locking mechanism, like a mosfet or transistor (possibly a darlington), depending on which device you choose and what voltage it requires to operate. Simplest solution is a servo motor which doesn’t require anything, but has a low torque, meaning the box can easily be forced. Most robust and reliable solution is a NC solenoid, common ones are 12V so you’ll need a p-channel enhance mosfet and a couple of resistors to drive it from an Arduino.
To display the time you’ll probably want to go for an LCD, common ones are 16 col x 2 rows, most have an integrated chip to drive them using only a few wires.
Apart from that, you need a battery pack (voltage and power depending on your locking circuit choice) and may be a push button (for safety unlock).
From a software perspective you want to create a loop which starts by locking the box and then counts down the time: when the time left is less than 5 mins it activates the unlocking mechanism circuit.
int current = 0;
const int max = 2 * 60 * 60; // 2hrs in sec
const int grant = 5 * 60; // 5mins in sec
bool unlocked = false;
void setup() {
lock();
}
// executed once every second
void loop() {
// any safety open check should be performed here...
// if still locked and less than 5 mins to end
if (!unlocked && current > max - grant) {
unlock();
}
display(current++);
wait(1000);
}
// does what it is needed to unlock and sets the unlocked variable to true
void unlock() { ... }
// does what it is needed to lock and sets the unlocked variable to false
void lock() { ... }
void display(int secs) {
int h = secs / (60 * 60);
int m = (secs / 60) % 60;
int s = secs % 60;
// display on LCD the values above with the proper formatting
}
A couple of notes:
- if you go for a normally closed solenoid be sure to have a way to get inside the box if something goes wrong with your circuit or if the batteries get drained
- you might want to have a hidden button or other way to force the unlock, especially for debugging and testing