Skip navigation

Arduino

1 Post authored by: jezza103

Hi to you all.I am a 47 year old man who due to an accident am disabled and bought myself an Arduino to keep myself busy. I am  new to arduino and have written some basic sketches. and have made some nice projects. I have an UNO R3 board and I have made an analog keypad using 12 tactile buttons and 7 resistors with a 1nf capacitor to help with bouncing. i did this so that all my digital pins are free to use. My idea is to make an alarm system using 2 PIR sensors, 4 LED's, a buzzer and a siren.(I may want to add more components later) I have no problem in writing the code except for the 4x3 keypad. I want to make a passcode eg 1234 but this is the part I am struggling with. The push buttons return a value when they are pressed so how would I go about that part I have written code to serial print the code to my pc and give them a number. please see the code examples below but I have looked all over the internet and asked on the Arduino forum for some help with the keypad. If anyone can help I would appreciate it.

Thank you for taking the time to read this.

void readkeyboard(){
   keyboardValue = analogRead(keyboardPin); // read the value (0-1023)
   if (keyboardValue <25){keypressed = 0;}
   if ((keyboardValue >25) && (keyboardValue < 67)){keypressed = 1;}
   if ((keyboardValue >67) && (keyboardValue < 108)){keypressed = 2;}
   if ((keyboardValue >108) && (keyboardValue < 162)){keypressed = 3;}
   if ((keyboardValue >162) && (keyboardValue < 253)){keypressed = 4;}
   if ((keyboardValue >253) && (keyboardValue < 361)){keypressed = 5;}
   if ((keyboardValue >361) && (keyboardValue < 479)){keypressed = 6;}
   if ((keyboardValue >479) && (keyboardValue < 619)){keypressed = 7;}
   if ((keyboardValue >619) && (keyboardValue < 765)){keypressed = 8;}
   if ((keyboardValue >765) && (keyboardValue < 819)){keypressed = 9;}
   if ((keyboardValue >819) && (keyboardValue < 899)){keypressed = 0;}// this is the * key
   if ((keyboardValue >889) && (keyboardValue < 955)){keypressed = 0;}
   if (keyboardValue >965){keypressed = 0;}  // this is the # key

}

when the keys are pressed they return these values

 

1=58, 2=96, 3=145,   4=228,  5=335,  6=447, 7=598,  8=720,  9=809,  *=890,  0=941, #=970

 

I have Written to the buttons like this just to test the keypad works as it should

   if (keyboardValue >25 && keyboardValue < 67) digitalWrite (12,HIGH);
   if (keyboardValue >67 && keyboardValue < 130) digitalWrite (11,HIGH);
   if (keyboardValue >162 && keyboardValue < 253) digitalWrite (9,HIGH);
   if (keyboardValue >108 && keyboardValue < 162) digitalWrite (10,HIGH);
   if (keyboardValue >253 && keyboardValue < 361) digitalWrite (8,HIGH);

Filter Blog

By date: By tag: