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
Arduino Forum Keypad Controlled LED
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 1 reply
  • Subscribers 416 subscribers
  • Views 734 views
  • Users 0 members are here
Related

Keypad Controlled LED

e14 Contributor
e14 Contributor over 12 years ago

KeypGood Day,

 

     Any help integrating this code

 

// How To Connect A Keypad To Arduino: Simple Example
// by Sebastian Tomczak 19 October 2011

// setup value for serial printing
byte value;

// setup pin names and numbers for cols and rows
byte row1 = 2;
byte row2 = 3;
byte row3 = 4;
byte row4 = 5;
byte col1 = 6;
byte col2 = 7;
byte col3 = 8;


void setup() {
  Serial.begin(57600);

  // setup row outputs
  pinMode(row1, OUTPUT);
  pinMode(row2, OUTPUT);
  pinMode(row3, OUTPUT);
  pinMode(row4, OUTPUT);

  // setup col inputs
  pinMode(col1, INPUT);
  pinMode(col2, INPUT);
  pinMode(col3, INPUT);

  // setup internal resistors
  digitalWrite(col1, HIGH);
  digitalWrite(col2, HIGH);
  digitalWrite(col3, HIGH);

  // initialise rows
  digitalWrite(row1, HIGH);
  digitalWrite(row2, HIGH);
  digitalWrite(row3, HIGH);
  digitalWrite(row4, HIGH);
}

void loop() {
  // read row 1
  digitalWrite(row1, LOW); // activate row 1
  value = digitalRead(col1); // read row 1 & col 1 = button 1
  if(value == 0) { // if the button is pressed...
    Serial.println("Button 1 Pressed");
  }
  digitalWrite(row1, HIGH); // deactivate row 1

  // repeat above for buttons 2 - 12 (i.e. rows 1 - 4 and cols 1 - 3)

  digitalWrite(row1, LOW);
  value = digitalRead(col2);
  if(value == 0) {
    Serial.println("Button 2 Pressed");
  }
  digitalWrite(row1, HIGH);


  digitalWrite(row1, LOW);
  value = digitalRead(col3);
  if(value == 0) {
    Serial.println("Button 3 Pressed");
  }
  digitalWrite(row1, HIGH);


  digitalWrite(row2, LOW);
  value = digitalRead(col1);
  if(value == 0) {
    Serial.println("Button 4 Pressed");
  }
  digitalWrite(row2, HIGH);


  digitalWrite(row2, LOW);
  value = digitalRead(col2);
  if(value == 0) {
    Serial.println("Button 5 Pressed");
  }
  digitalWrite(row2, HIGH);


  digitalWrite(row2, LOW);
  value = digitalRead(col3);
  if(value == 0) {
    Serial.println("Button 6 Pressed");
  }
  digitalWrite(row2, HIGH);


  digitalWrite(row3, LOW);
  value = digitalRead(col1);
  if(value == 0) {
    Serial.println("Button 7 Pressed");
  }
  digitalWrite(row3, HIGH);


  digitalWrite(row3, LOW);
  value = digitalRead(col2);
  if(value == 0) {
    Serial.println("Button 8 Pressed");
  }
  digitalWrite(row3, HIGH);


  digitalWrite(row3, LOW);
  value = digitalRead(col3);
  if(value == 0) {
    Serial.println("Button 9 Pressed");
  }
  digitalWrite(row3, HIGH);


  digitalWrite(row4, LOW);
  value = digitalRead(col1);
  if(value == 0) {
    Serial.println("Button * Pressed");
  }
  digitalWrite(row4, HIGH);


  digitalWrite(row4, LOW);
  value = digitalRead(col2);
  if(value == 0) {
    Serial.println("Button 0 Pressed");
  }
  digitalWrite(row4, HIGH);


  digitalWrite(row4, LOW);
  value = digitalRead(col3);
  if(value == 0) {
    Serial.println("Button # Pressed");
  }
  digitalWrite(row4, HIGH);

}

 

     to make an external led light up for every button?

  • Sign in to reply
  • Cancel
  • e14 Contributor
    e14 Contributor over 12 years ago

    I could have thought before asking, anyways if this is a concern, heres the code to do so. You can inoput as many leds but all I neded was to run 2 leds.

     

    // 3x4 Keypad Controlled LED Array by Alvin Blanco Mioten


    // setup value for serial printing
    byte value;

    // setup pin names and numbers for led
    int led_1 = 13;
    int led_2 = 12;

    // setup pin names and numbers for cols and rows
    byte row1 = 2;
    byte row2 = 3;
    byte row3 = 4;
    byte row4 = 5;
    byte col1 = 6;
    byte col2 = 7;
    byte col3 = 8;


    void setup() {
    Serial.begin(57600);

    //setup led outputs
    pinMode(led_1, OUTPUT);

    // setup row outputs
    pinMode(row1, OUTPUT);
    pinMode(row2, OUTPUT);
    pinMode(row3, OUTPUT);
    pinMode(row4, OUTPUT);

    // setup col inputs
    pinMode(col1, INPUT);
    pinMode(col2, INPUT);
    pinMode(col3, INPUT);

    // setup internal resistors
    digitalWrite(col1, HIGH);
    digitalWrite(col2, HIGH);
    digitalWrite(col3, HIGH);

    // initialise rows
    digitalWrite(row1, HIGH);
    digitalWrite(row2, HIGH);
    digitalWrite(row3, HIGH);
    digitalWrite(row4, HIGH);
    }

    void loop() {
    // read row 1
    digitalWrite(row1, LOW); // activate row 1
    value = digitalRead(col1); // read row 1 & col 1 = button 1
    if(value == 0) { // if the button is pressed...
    Serial.println("Button 1 Pressed");
    digitalWrite(led_1, HIGH);
    }
    digitalWrite(row1, HIGH); // deactivate row 1

    // repeat above for buttons 2 - 12 (i.e. rows 1 - 4 and cols 1 - 3)

    digitalWrite(row1, LOW);
    value = digitalRead(col2);
    if(value == 0) {
    Serial.println("Button 2 Pressed");
    digitalWrite(led_2, HIGH);
    }
    digitalWrite(row1, HIGH);


    digitalWrite(row1, LOW);
    value = digitalRead(col3);
    if(value == 0) {
    Serial.println("Button 3 Pressed");
    }
    digitalWrite(row1, HIGH);


    digitalWrite(row2, LOW);
    value = digitalRead(col1);
    if(value == 0) {
    Serial.println("Button 4 Pressed");
    }
    digitalWrite(row2, HIGH);


    digitalWrite(row2, LOW);
    value = digitalRead(col2);
    if(value == 0) {
    Serial.println("Button 5 Pressed");
    }
    digitalWrite(row2, HIGH);


    digitalWrite(row2, LOW);
    value = digitalRead(col3);
    if(value == 0) {
    Serial.println("Button 6 Pressed");
    }
    digitalWrite(row2, HIGH);


    digitalWrite(row3, LOW);
    value = digitalRead(col1);
    if(value == 0) {
    Serial.println("Button 7 Pressed");
    }
    digitalWrite(row3, HIGH);


    digitalWrite(row3, LOW);
    value = digitalRead(col2);
    if(value == 0) {
    Serial.println("Button 8 Pressed");
    }
    digitalWrite(row3, HIGH);


    digitalWrite(row3, LOW);
    value = digitalRead(col3);
    if(value == 0) {
    Serial.println("Button 9 Pressed");
    }
    digitalWrite(row3, HIGH);


    digitalWrite(row4, LOW);
    value = digitalRead(col1);
    if(value == 0) {
    Serial.println("Button * Pressed");
    }
    digitalWrite(row4, HIGH);


    digitalWrite(row4, LOW);
    value = digitalRead(col2);
    if(value == 0) {
    Serial.println("Button 0 Pressed");
    digitalWrite(led_1, LOW);
    digitalWrite(led_2, LOW);
    }
    digitalWrite(row4, HIGH);


    digitalWrite(row4, LOW);
    value = digitalRead(col3);
    if(value == 0) {
    Serial.println("Button # Pressed");
    }
    digitalWrite(row4, HIGH);

    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • 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