element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Blog New to arduino and programming, 4x3 analog keypad question about making a passcode
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: e14 Contributor
  • Date Created: 10 Jan 2013 11:57 AM Date Created
  • Views 3627 views
  • Likes 0 likes
  • Comments 21 comments
Related
Recommended

New to arduino and programming, 4x3 analog keypad question about making a passcode

e14 Contributor
e14 Contributor
10 Jan 2013

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);

  • Sign in to reply

Top Comments

  • billabott
    billabott over 13 years ago in reply to e14 Contributor +1
    Get some sleep and check out http://www.oomlout.com/a/products/ardx/ tomorrow.
  • ntewinkel
    ntewinkel over 13 years ago in reply to e14 Contributor

    They have a really excellent, and free, Arduino tutorial to help people get started with Arduino basics. I think that's what billabott was suggesting.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • e14 Contributor
    e14 Contributor over 13 years ago

    Oomlout a website that sells Arduino and electronic components. I cannot see how that is going to help?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • ntewinkel
    ntewinkel over 13 years ago in reply to billabott

    Oomlout! - my favourite! image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • billabott
    billabott over 13 years ago in reply to e14 Contributor

    Get some sleep and check out http://www.oomlout.com/a/products/ardx/ tomorrow.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • e14 Contributor
    e14 Contributor over 13 years ago

    Hi billabott. yes they do. I never thought about the library. I will have to get into Norwich and have a look in the millenium library. I will try to get there tomorrow.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
<>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube