Code is not working (Matrix keypad)
Cited comment:


  Check pin modes. Should be INPUT_PULLUP and OUTPUT. Also, consider
  debouncing. – Mikael Patel


Please, try:



const char keymap[4][4]={
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
 };
const int rpin[]={9,8,7,6};
const int cpin[]={5,4,3,2};
void setup()
{
  Serial.begin(9600);
  Serial.println("Program starting");//for debugging purpose and canbe removed later 
  for(int i=0;i&lt;4;i++)
  {
//Should be INPUT_PULLUP and OUTPUT
    pinMode(rpin[i],OUTPUT);
    pinMode(cpin[i],INPUT_PULLUP);
  }
}
void loop()
{
  char key=getkey();
  if(key!=0)
  {
   Serial.println(key);
   delay(200);              // Also, consider debouncing. 
  }  
}
char getkey()
{
  char key=0;
  for(int i=0;i&lt;4;i++)
  {
    digitalWrite(rpin[i],LOW);
    for(int j=0;j&lt;4;j++)
    {
      if (digitalRead(cpin[j])==LOW)
      key=keymap[i][j];
    }
    digitalWrite(rpin[i],HIGH);
  }
  return key;
}