Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Zachary SenecalJack Workman
Published

Wireless Keypad Password

Type in a password and watch the LED light up green if you got your password correct, or red if incorrect.

BeginnerShowcase (no instructions)96
Wireless Keypad Password

Things used in this project

Hardware components

Photon 2
Particle Photon 2
×2
Parallax 16 Key Keypad
×1
SparkFun Generic RGB LED 4 pins
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

adafruit.io
Live feed
Youtube.com
Summary and presentation of project

Story

Read more

Schematics

Adafruit Feed

1 = correct code input
0 = incorrect code input
Useful to see when your keypad is being used and if they got in or not.

Flowchart for Photon #1 and #2

Photon #1 deals with the keypad and processing the inputs
Photon #2 deals with taking these inputs and lighting up the LED and sending the data to adafruit

Circuit Diagram

Code

Keypad code (Photon 1)

C/C++
Connect the keypad in accordance to lines 17 and 18 (and following the circuit diagram). Sends a signal to the other photon whether or not the code is correct.
// These #include statements were automatically added by the Particle IDE.
#include <SparkJson.h>
#include <Keypad_Particle.h>

// Define the keypad layout
const byte ROW_NUM    = 4; 
const byte COLUMN_NUM = 4; 

char keys[ROW_NUM][COLUMN_NUM] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

byte pin_rows[ROW_NUM]    = {D7, D6, D5, D4}; // pins used for the row connections
byte pin_column[COLUMN_NUM] = {D3, D2, D1, D0}; // pins used for the column connections

// initialize the keypad
Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM);

// change the secret 4 digit password here
const char correctCode[] = "3171"; 

// variables to store correct/incorrect entries
char enteredCode[5] = ""; 
char incorrectEntries[5] = ""; 
byte enteredDigits = 0;

void setup() {
  Serial.begin(9600);
  Particle.subscribe("OUTPUT", ledFeedbackHandler, MY_DEVICES);
}

// deletes the memory after a password attempt
void resetCode() {
    memset(enteredCode, 0, sizeof(enteredCode));
    enteredDigits = 0;
}

void ledFeedbackHandler(const char *event, const char *data) {
  if (strcmp(data, "CORRECT") == 0) {
    Particle.publish("You typed in the code right");
  } else if (strcmp(data, "INCORRECT") == 0) {
    Particle.publish("You didn't type the code right");
  }
}

void loop() {
  char key = keypad.getKey();
  
  if (key) {
    if (strlen(enteredCode) < 4) {
      enteredCode[strlen(enteredCode)] = key;
    }
    
      if (strlen(enteredCode) == 4){ // checks to see if length is 4
        if (strcmp(enteredCode, correctCode) == 0) { // compares user input to password (0 means they are the same)
            Particle.publish("CODE", "1", PRIVATE); // correct password is 1
            resetCode();
        }
        
            else {
                Particle.publish("CODE", "0", PRIVATE); // incorrect password is 0
                strcat(incorrectEntries, enteredCode);
                //Particle.publish("ATTEMPT", "You entered: " + String(incorrectEntries)); (used for troubleshooting keypad presses on events tab)
                delay(3000);
                resetCode();
             }
    }
  }
  
  }

Adafruit and LED Code (Photon 2)

C/C++
This code receives the signal from Photon 1 and uses it to control the LED light and then sends the signal to the Adafruit feed via Webhook.
// This #include statement was automatically added by the Particle IDE.
#include <SparkJson.h>


// Define the RGB LED pins
const int redPin = D0;  
const int greenPin = D1;
const int bluePin = D2;

void setup() {
  Serial.begin(9600);
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);

  // Subscribe to the "CODE" event
  Particle.subscribe("CODE", codeHandler, MY_DEVICES);
  
  } 
  
  void codeHandler(const char *event, const char *data) {
      
  if (strcmp(data, "1") == 0) {
    setRGBColor(0, 255, 0); // Green
    Particle.publish("OUTPUT","Correct", PRIVATE);
    delay(3000);
    setRGBColor(0, 0, 255);
    
  } else if (strcmp(data, "0") == 0) {
    setRGBColor(255, 0, 0); // Red
    Particle.publish("OUTPUT","Incorrect", PRIVATE);
    delay(3000);
    setRGBColor(0, 0, 255);
  }
}





void setRGBColor(int red, int green, int blue) {
  digitalWrite(redPin, red);
  digitalWrite(greenPin, green);
  digitalWrite(bluePin, blue);
}

void loop() {
}

Credits

Zachary Senecal

Zachary Senecal

1 project • 1 follower
Jack Workman

Jack Workman

1 project • 1 follower

Comments