top of page

How to make pattern lock using ir sensor



How to work IR sensor:


Circuit:



Download Programming:



#include<Keypad.h>

int lock=2;

int ledBlue=3;

int ledRed=4;

int count=0;

const byte numRows=4;

const byte numCols=3;

char keymap[numRows][numCols]={

{'1','2','3'},

{'4','5','6'},

{'7','8','9'},

{'*','0','#'},

};

byte rowPins[numRows]={5,6,7,8};

byte colPins[numCols]={9,10,11};

Keypad myKeypad=Keypad(makeKeymap(keymap),rowPins,colPins,numRows,numCols);




void setup() {

  

Serial.begin(9600);

pinMode(lock,OUTPUT);

pinMode(ledRed,OUTPUT);

pinMode(ledBlue,OUTPUT);

digitalWrite(lock,HIGH);

}


void loop() {

char keypressed=myKeypad.getKey();

if(keypressed!=NO_KEY)

{

  Serial.println(keypressed);

  if(keypressed=='3')

  {

    count=count+1;

  }

  if(count>3)

  {

    count=0;

  }

  if((keypressed=='*')&&(count==4))

  {

    digitalWrite(lock,LOW);

    digitalWrite(ledBlue,HIGH);

    digitalWrite(ledRed,LOW);

    count=0;

  }

  if(keypressed=='#')

  {

    digitalWrite(lock,HIGH);

    digitalWrite(ledRed,HIGH);

    digitalWrite(ledBlue,LOW);

    count=0;

  }

}

}




Demo Video:


282 views0 comments

Recent Posts

See All

Comments


bottom of page