PIN PAD LOCK

QUICK PROJECT DESCRIPTION

PROJECT OBJECTIVE: Protect your valuables and your secrets with a simple 4-digit PIN pad build.

HARDWARE REQUIREMENTS: Provided in the Mango Labs Mechatronics Maker Kit: Arduino-compatible board, USB cable, mini breadboard, touch sensor module, micro servo, I2C LCD, RGB LED module, 10 female to male jumper cables, 9 male to male jumper cables.

Additional hardware: It depends on what you want to secure. With the servo included in the kit you can lock drawers, boxes, lockers… The project can be easily modified to activate an electrical lock using the solid state relay connected to the green LED output.

SOFTWARE REQUIREMENTS: Arduino environment (or online editor). Download the liquid crystal library here. The wire and servo libraries are included by default. Unzip and paste the folder in the Arduino libraries folder. It’s in the same location as your default sketches. You can look it up under File/Preferences Sketchbook location.

KNOW-HOW REQUIREMENTS: Basic Arduino environment knowledge (learn more here). Basic electrical skills.

QUICK OVERVIEW
  1. Connect everything as shown in the diagram.
  2. Install the liquid crystal library (if you tested the LCD with the Hello World example you have the library already installed).
  3. Download the sketch, open it in the Arduino environment and set your secret password key.
  4. Compile and upload the sketch to your board.
  5. If you don’t see anything on the LCD screen, calibrate contrast with the blue trim pot on the back.
  6. Test your system by pressing the number sequence. You will see a green light and Welcome message if you got it right, and a red light if you pressed the wrong PIN code. The correct password will turn the servo shaft 180 degrees.
PIN OUT DIAGRAM
1
2
3
4
5
Pin pad lock connection diagram
1

5 VOLTS and Ground power hub

2

Black cable is Ground
Red cable is power (5 volts)
Grey cable is OUT1 and goes to digital 2 on your Arduino compatible board
Purple cable is OUT2 and goes to digital 3 on your Arduino compatible board
Blue cable is OUT3 and goes to digital 4 on your Arduino compatible board
Green cable is OUT4 and goes to digital 5 on your Arduino compatible board

3

Brown cable is Ground
Red cable is power (5 volts)
Orange cable is control and goes to digital 6 on your Arduino compatible board

4

Black cable is Ground
Red cable is power (5 volts)
Blue cable is SDA and goes to analog 4 on your Arduino compatible board
Green cable is SCL and goes to analog 5 on your Arduino compatible board

5

Black cable is Ground
Blue cable is B and goes to digital 11 on your Arduino compatible board
Green cable is G and goes to digital 10 on your Arduino compatible board
Red cable is R and goes to digital 9 on your Arduino compatible board

SETUP

Follow the diagram to make all the connections. If you intend to make a more permanent installation, most of the boards have mounting holes that allow you to secure them with screws. For the connections, a glue gun can be handy to secure the jumper cables.

Pin pad lock

I’m using the mini bread board as a power hub to distribute 5 volts and ground to the different boards. Here, I pinned the RGB LED board on the bread board, but you could use female to male jumper cables to mount the RGB LED board in a more convenient spot.

breadboard power hub

On the touch sensor board I used female to male jumper cables to make the connections. Take care to connect them in the right order. The number sequence in the code begins with 0. However, the key pad begins with 1. Therefore, you have to substract 1 from the key pad password you want to create in order to input it on the code. For example, if the password you choose is 1234, you have to input it as 0123 in the Arduino sketch.

Touch board connections

The micro servo was connected using male to male jumper cables. Because of its low current draw, it can be powered directly from the 5 volt power regulator of the Arduino-compatible board. By default, the code turns it almost 180 degrees and back. However, you can change it easily by modifying the myservo.write statements in the code.

Srvo conections

Once the setup is ready and you have chosen a PIN password, upload the code to your Arduino-compatible board. The wrong password will make the RGB LED flash a red light and the LCD screen will display the text “Invalid PIN”. If the password is correct, the RGB LED will show a green light and the LCD screen will display the text “Valid PIN”, followed by “Welcome”. The servo shaft will turn, allowing you to open the compartment.

Use technology to keep your secrets safe ;-)

Correct pin input

Have Fun!

CODE

//by Dr. Mangus for www.mangolabs.de
//based on code by Constantine32

#include 
#include 
#include 

LiquidCrystal_PCF8574 lcd(0x3f);  // set the LCD address to 0x27 or 
                                  //0x3f for the A model IC
Servo myservo;  // create servo object to control a servo

const int button[] = {2,3,4,5}; //digital inputs
const int ledpin[] = {10,9};  //digital outputs

int ButtonState[] = {0,0,0,0};
int lastButtonState[] = {0,0,0,0};
// set your pin password 
int password[] = {3,1,0,2};// add 1 for key numbers = 4,2,1,3 
int level = 0;

void setup() {
  pinMode(button[0], INPUT);
  pinMode(button[1], INPUT);
  pinMode(button[2], INPUT);
  pinMode(button[3], INPUT);
  pinMode(ledpin[0], OUTPUT);
  pinMode(ledpin[1], OUTPUT);

myservo.attach(6);  // attaches the servo on pin 6 to the servo object
  myservo.write(10); // ensure servo is in closed position
  
  lcd.begin(16, 2);                           // initialize the lcd
   lcd.setBacklight(255);
   lcd.clear();
      lcd.home(); 
 //            1234567891234567    
    lcd.print("INPUT KEYPIN ");
}

void loop() {
  lcd.home(); 
 //            1234567891234567    
    lcd.print("INPUT KEYPIN ");
    
  for(int i=0; i<4; i++){
  ButtonState[i] = digitalRead(button[i]);
  }
//decode input
  for(int i=0; i<4; i++){   
    if(ButtonState[i] != lastButtonState[i]){
      if(ButtonState[i] == 1){
        switch(level){
          case 0: if(i == password[0]) level++;
                  else level=5;
                  break;
          case 1: if(i == password[1]) level++;
                  else level=5;
                  break;
          case 2: if(i == password[2]) level++;
                  else level=5;
                  break;
          case 3: if(i == password[3]) level++;
                  else level=5;
                  break;
          }
      }
      lastButtonState[i] = ButtonState[i];
    }
  }

// if it's valid do:
  if(level==4){
    digitalWrite(ledpin[0], HIGH); //turno on green led
    lcd.home(); 
 //            1234567891234567    
    lcd.print("   VALID PIN    ");
    myservo.write(160); // move servo to open position
    delay(1000);
    lcd.setCursor(0, 1);
    lcd.print("****Welcome****");
    digitalWrite(ledpin[0], LOW);
    delay(1000);
    myservo.write(10); //after 2 seconds move servo
                      //back to closed position
    lcd.clear();
    level=0;
    }

// if it's invalid do:
  if(level==5){
    for(int j=0; j<4; j++){
      digitalWrite(ledpin[1], HIGH); //turn on red led
      lcd.home(); 
 //            1234567891234567    
    lcd.print("INVALID PIN ");
      delay(50);
      digitalWrite(ledpin[1], LOW);
      delay(100);
      lcd.clear();
    }
    level=0;
  }
   //wait a bit
  delay(20);
}

[/c]