Reply to topic  [ 2 posts ] 
Membrane Keypads (HCPROJ0001/HCPROJ0003/HCPROJ0004) 
Author Message
Site Admin

Joined: Sun Aug 05, 2012 4:02 pm
Posts: 633
Post Membrane Keypads (HCPROJ0001/HCPROJ0003/HCPROJ0004)


Our range of ultra-thin self adhesive membrane matrix keypads, ideal for panel mounting. Flexible cable allows for discrete routing behind the keypad. Keypads are currently supplied in 3x4, 4x4, and 4x5 arrangements.

- 8-pin 2.54mm pitch connector
- Cable Length: 8cm
- Self-adhesive back provides easy mounting
- 3x4 Dimensions: 69.2 x 76.9 x 0.8mm
- 4x4 Dimensions: 160 x 60 x 0.8 mm
- 4x5 Dimensions: 75 x 85 x 0.8 mm

Thu Jun 27, 2013 6:38 pm

Joined: Wed Jun 26, 2013 4:57 pm
Posts: 2
Post Re: YwRobot Serial I2C LCD 1602 Module (HCARDU0023)
This post is related to 4x5 Membrane Keypad. If Mr. Admin reads this, please move it to new topic as I can not create one on my own.

If you are new to Arduino/Electronics and you bought this keyboard because layout looked like something you might need, here is few tips and some code that might save you some head scratching:

    Wiring - normaly people google "membrane keyboard wiring" but there is not much info to be found. There is too many sorts of membrane keyboards with different plugs and wiring patterns... Bright side is, almost all of them works in the same way and you can not damage keyboard by applying "try and error" method. Lest focus on this particular keyboard.

    Uploaded with

    Simple math applies here, we have 5 rows and 4 columns if you have a look on plug you will notice 5 pins with black markers, those are our rows. Most left one is row 1 and the most right is column 1. Lets have a look on wiring photo.


    Uploaded with
    I know its not very clear to read but I don't have time to create a schematic for wiring. The left white jump wire is connected to digital pin no. 30 on my Arduino mega. Right jump wire is connected to digital pin 34. Ok, lets see some code.

    Code - Here we go:

    /* @file MultiKey.ino
    || @version 1.0
    || @author Mark Stanley
    || @contact
    || @description
    || | The latest version, 3.0, of the keypad library supports up to 10
    || | active keys all being pressed at the same time. This sketch is an
    || | example of how you can get multiple key presses from a keypad or
    || | keyboard.
    || #
    #include <Wire.h>
    #include <LCD.h>
    #include <LiquidCrystal_I2C.h>

    #define I2C_ADDR 0x27 // <<----- Add your address here. Find it from I2C Scanner
    #define BACKLIGHT_PIN     3
    #define En_pin  2
    #define Rw_pin  1
    #define Rs_pin  0
    #define D4_pin  4
    #define D5_pin  5
    #define D6_pin  6
    #define D7_pin  7

    int n = 1;

    LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

    #include <Keypad.h>

    const byte ROWS = 5; //four rows
    const byte COLS = 4; //three columns
    char keys[ROWS][COLS] = {
      {'1','2','3', 'C'},
      {'4','5','6', 'D'},
      {'7','8','9', 'E'},
      {'L','0','R' , 'R'}
    byte rowPins[ROWS] = {34, 35, 36, 37, 38}; //connect to the row pinouts of the keypad
    byte colPins[COLS] = {30, 31, 32, 33}; //connect to the column pinouts of the keypad

    Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

    void setup() {
      lcd.begin (16,2); // <<----- My LCD was 16x2

      // Switch on the backlight
      lcd.home (); // go home

    unsigned long loopCount = 0;
    unsigned long startTime = millis();
    String msg = "";

    void loop() {

      if ( (millis()-startTime)>1000 ) {
          startTime = millis();
          loopCount = 0;

      // Fills kpd.key[ ] array with up-to 10 active keys.
      // Returns true if there are ANY active keys.
      if (kpd.getKeys())
        for (int i=0; i<LIST_MAX; i++) // Scan the whole key list.
          if ( kpd.key[i].stateChanged ) // Only find keys that have changed state.
            switch (kpd.key[i].kstate) { // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
                case PRESSED:
                    msg = " PRESSED.";
                case HOLD:
                    msg = " HOLD.";
                case RELEASED:
                    msg = " RELEASED.";
                case IDLE:
                    msg = " IDLE.";
            Serial.print("Key ");
      // Backlight on/off every 3 seconds
      lcd.setCursor (0,1); // go to start of 2nd line
      //lcd.setBacklight(LOW); // Backlight off
      lcd.setBacklight(HIGH); // Backlight on
    }  // End loop

    This code supports lcd display and keyboard, I did not hat time to remove lcd code, but it will work for you even if you don't have lcd connected to Arduino. To run this code you will require keyboard library from here

    Here's top tip:

    Uploaded with
    This is your keyboard and you would normally design your keys array in code like this:
    const byte ROWS = 5; //four rows
    const byte COLS = 4; //three columns
    char keys[ROWS][COLS] = {
      {'1','2','3', 'Up'},
      {'4','5','6', 'Down'},
      {'7','8','9', 'Esc'},
      {'Left','0','Right' , 'Ent'}

    But sadly Keyboard class can not cope with more than one character per key at the moment, which means your "F1", "F2", "Ent" etc.... would return 1 instead of value that you assigned to the key. Simple workaround:

    const byte ROWS = 5; //four rows
    const byte COLS = 4; //three columns
    char keys[ROWS][COLS] = {
      {'1','2','3', 'C'},
      {'4','5','6', 'D'},
      {'7','8','9', 'E'},
      {'L','0','R' , 'R'}

I think that's about it and I covered the basics, if you have any questions, don't hesitate to ask.

Thu Jun 27, 2013 6:38 pm
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Thank you to &
Design created by Florea Cosmin Ionut.
© 2011 All contents of this site are © Hobby Components LTD