URGENT! Need help with Key Pad

Hello,
We need help with an issue with our key pad and LCD display. The code is attached below, our problem is that the 1, 2, 3 keys in the key pad doesn’t get registered to display when pressed.

#include <LiquidCrystal.h> //include LCD library (standard library)
#include <Keypad.h> //include keypad library - first you must install library (library link in the video description)

const byte rows = 4; //number of the keypad's rows and columns
const byte cols = 4;

char keyMap [rows] [cols] = { //define the cymbols on the buttons of the keypad

{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};

byte rowPins [rows] = {1, 2, 3, 4}; //pins of the keypad
byte colPins [cols] = {5, 6, 7, 8};

long Num1,Number;
char key,action;
boolean result = false;
float constant = 0.623;

Keypad myKeypad = Keypad( makeKeymap(keyMap), rowPins, colPins, rows, cols);

LiquidCrystal lcd(A0, A1, A2, A3, A4, A5); 

void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
lcd.setCursor(3, 0);
lcd.print("WaterRight");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Area:");


}
void loop() {

key = myKeypad.getKey(); //storing pressed key value in a char

if (key!=NO_KEY)
DetectButtons();

if (result==true)
CalculateVolume();

DisplayResult();   
}

void DetectButtons() {
  lcd.clear(); //Then clean it
  if (key=='*') {
    Serial.println ("Clear"); 
    Number=Num1=0; 
    result=false;
    }
  
  if (key == '0'){
    Serial.println ("Button 0"); 
  if (Number==0)
    Number=0;
  else
    Number = (Number*10) + 0; //Pressed twice
  }
  
  if (key == '1'){
    Serial.println ("Button 1"); 
  if (Number==0)
    Number=1;
  else
    Number = (Number*10) + 1; //Pressed twice
  }

  if (key == '2'){
    Serial.println ("Button 2"); 
  if (Number==0)
    Number=2;
  else
    Number = (Number*10) + 2; //Pressed twice
  }
  
  if (key == '3'){
    Serial.println ("Button 3"); 
  if (Number==0)
     Number=3;
  else
     Number = (Number*10) + 3; //Pressed twice
  }
  
  if (key == '4'){
    Serial.println ("Button 4"); 
  if (Number==0)
    Number=4;
  else
    Number = (Number*10) + 4; //Pressed twice
  }

  if (key == '5'){
    Serial.println ("Button 5"); 
  if (Number==0)
    Number=5;
  else
    Number = (Number*10) + 5; //Pressed twice
  }
  
  if (key == '6'){
    Serial.println ("Button 6"); 
  if (Number==0)
    Number=6;
  else
    Number = (Number*10) + 6; //Pressed twice
  }
  
  if (key == '7'){
    Serial.println ("Button 7");
  if (Number==0)
    Number=7;
  else
    Number = (Number*10) + 7; //Pressed twice
  } 
  
   if (key == '8')
  {
    Serial.println ("Button 8"); 
   if (Number==0)
  Number=8;
  else
  Number = (Number*10) + 8; //Pressed twice
  }   

  if (key == '9'){
    Serial.println ("Button 9");
  if (Number==0)
    Number=9;
  else
    Number = (Number*10) + 9; //Pressed twice
  }  

  if(key=='#'){
    while(true){
    lcd.clear();
    lcd.print("Watering...");
    delay(1000);
    lcd.noDisplay();
    delay(1000);
    lcd.display();
  }
  }
}
 
void CalculateVolume(){
 
}
void DisplayResult()
{
lcd.setCursor(0, 0);
lcd.print("Enter Area:");   
lcd.print(Number); 
lcd.setCursor(0, 1);  
lcd.print("Volume:");
lcd.print(Number*constant); 
}

Thank You

To make it easy for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

Your code is too long for me to study quickly without copying to a text editor.

Also use the AutoFormat tool to indent your code for easier reading,

…R

On UNO and similar Arduinos, pin 1 is used for Serial transmission. Your use of pin 1 for the first row of the keypad will conflict with this and probably explains why you can’t get the 1, 2, 3 keys to work.
Whether or not that is the problem, you should read How to post code properly and then use the </> icon to create

[code]...[/code]

tags around your code so that it is easier to read.

Pete

    if (key == '0'){
      Serial.println ("Button 0"); 
    if (Number==0)
      Number=0;
    else
      Number = (Number*10) + 0; //Pressed twice
    }
    
    if (key == '1'){
      Serial.println ("Button 1"); 
    if (Number==0)
      Number=1;
    else
      Number = (Number*10) + 1; //Pressed twice
    }

    if (key == '2'){
      Serial.println ("Button 2"); 
    if (Number==0)
      Number=2;
    else
      Number = (Number*10) + 2; //Pressed twice
    }
etc, etc

Do you notice that your code is basically the same for each digit pressed ?

All you need to do is to test that the key pressed is between '0 and '9', subtract '0' from the key value to get an actual number then add it to 10 times the current total.

if (Number==0)
      Number=0;

If the bottle is empty, empty it 8)

No matter what we do the key pad does not display or register the 1, 2, 3 keys while all the other keys like 4, 5, 6 works. Please look over the code and see if something is amiss

#include <LiquidCrystal.h> //include LCD library (standard library)
#include <Keypad.h> //include keypad library - first you must install library (library link in the video description)

const byte rows = 4; //number of the keypad's rows and columns
const byte cols = 4;

char keyMap [rows] [cols] = { //define the cymbols on the buttons of the keypad

{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};

byte rowPins [rows] = {1, 2, 3, 4}; //pins of the keypad
byte colPins [cols] = {5, 6, 7, 8};

long Num1,Number;
char key,action;
boolean result = false;
float constant = 0.623;

Keypad myKeypad = Keypad( makeKeymap(keyMap), rowPins, colPins, rows, cols);

LiquidCrystal lcd(A0, A1, A2, A3, A4, A5); 

void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
lcd.setCursor(3, 0);
lcd.print("WaterRight");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Area:");


}
void loop() {

key = myKeypad.getKey(); //storing pressed key value in a char

if (key!=NO_KEY)
DetectButtons();

if (result==true)
CalculateVolume();

DisplayResult();   
}

void DetectButtons() {
  lcd.clear(); //Then clean it
  if (key=='*') {
    Serial.println ("Clear"); 
    Number=Num1=0; 
    result=false;
    }
  
  if (key == '0'){
    Serial.println ("Button 0"); 
  if (Number==0)
    Number=0;
  else
    Number = (Number*10) + 0; //Pressed twice
  }
  
  if (key == '1'){
    Serial.println ("Button 1"); 
  if (Number==0)
    Number=1;
  else
    Number = (Number*10) + 1; //Pressed twice
  }

  if (key == '2'){
    Serial.println ("Button 2"); 
  if (Number==0)
    Number=2;
  else
    Number = (Number*10) + 2; //Pressed twice
  }
  
  if (key == '3'){
    Serial.println ("Button 3"); 
  if (Number==0)
     Number=3;
  else
     Number = (Number*10) + 3; //Pressed twice
  }
  
  if (key == '4'){
    Serial.println ("Button 4"); 
  if (Number==0)
    Number=4;
  else
    Number = (Number*10) + 4; //Pressed twice
  }

  if (key == '5'){
    Serial.println ("Button 5"); 
  if (Number==0)
    Number=5;
  else
    Number = (Number*10) + 5; //Pressed twice
  }
  
  if (key == '6'){
    Serial.println ("Button 6"); 
  if (Number==0)
    Number=6;
  else
    Number = (Number*10) + 6; //Pressed twice
  }
  
  if (key == '7'){
    Serial.println ("Button 7");
  if (Number==0)
    Number=7;
  else
    Number = (Number*10) + 7; //Pressed twice
  } 
  
   if (key == '8')
  {
    Serial.println ("Button 8"); 
   if (Number==0)
  Number=8;
  else
  Number = (Number*10) + 8; //Pressed twice
  }   

  if (key == '9'){
    Serial.println ("Button 9");
  if (Number==0)
    Number=9;
  else
    Number = (Number*10) + 9; //Pressed twice
  }  

  if(key=='#'){
    while(true){
    lcd.clear();
    lcd.print("Watering...");
    delay(1000);
    lcd.noDisplay();
    delay(1000);
    lcd.display();
  }
  }
}
 
void CalculateVolume(){
 
}
void DisplayResult()
{
lcd.setCursor(0, 0);
lcd.print("Enter Area:");   
lcd.print(Number); 
lcd.setCursor(0, 1);  
lcd.print("Volume:");
lcd.print(Number*constant); 
}

Thank you

digital pin 1 is used for serial output, you can't share it with the button pad and expect both serial and the button pad to work

Why did you start a new thread? One answer in your other thread gave the same answer about pin 1.

Threads merged.