The safe

You now have all the know-how to build our safety box!

Let's start with the code:

//Initializing a variable to store the value of the button state 
int lidState = 0; 
int keyState = 0; 
int lidPin = 2; 
int keyPin = 3; 
int alarmPin = 9; 
 
// the setup function runs once when you press reset or power the board 
 
 
void setup() { 
  // initialize digital I/O pins 
  pinMode(lidPin, INPUT); 
  pinMode(keyPin, INPUT); 
  pinMode(alarmPin, OUTPUT); 
} 
 
// the loop function runs over and over again forever 
void loop() { 
 
  lidState = digitalRead(lidPin); 
  if ( lidState == LOW ) 
  { 
    keyState = digitalRead(keyPin); 
    if ( keyState == HIGH ) 
      digitalWrite(alarmPin, LOW); 
    else 
      digitalWrite(alarmPin, HIGH); 
  } 
  else 
    digitalWrite(alarmPin, LOW); 
} 

We start by storing the pin numbers ...

Get Arduino for Kids now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.