Keypad Input Display and Store to Use Further in Program

Hello folks,

I hope you all are doing well.

At first I am totally new to this forum and to Arduino, I am sorry for any mistakes (if made) regarding the forum rules.

Coming on to the point, I am using a program to measure moisture content in which I want to add/input a separate number from keypad to 16x2 LCD for further calculations.

What I need to do is input a 2 digit number by 3x4 keypad and then use the number to multiply it with the moisture percentage and then divide by 100.

Please help I’m a newbie.

I looked up for examples.
looked in for a calculator code, basic input and display on lcd program etc.
but nothing’s working for me.
Please help!

#include <LiquidCrystal.h>
// include the LCD library
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Set pins as 12,11,7,6,5,4. It might be different for your LCD, check the producer catalog
int potPin = A0; 
//input pin 
int moisture=0;
void setup() {
lcd.begin(16, 2);
// lcd rows and columns
lcd.print("Moisture :"); 
}
void loop() { 
// map the values
int moisture = analogRead(potPin) ;
moisture = constrain(soil, 485, 1023);
moisture = map(soil, 485, 1023, 100, 0);
lcd.setCursor(0, 1);
//display final numbers
lcd.print(soil);
//print the percent symbol at the end
lcd.print("%");
//wait 0.1 seconds
delay(75); 
//wipe the extra characters
lcd.print(" ");
delay(1);
}

Starting from here…
pins are connected in this way and working fine for basic programs and I’m getting display on my lcd too.

#include <LiquidCrystal.h>
#include <Keypad.h>
LiquidCrystal lcd (12, 11, 5, 4, 3, 2);

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {9, 10, 7, 8}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {A3, A4, A5}; //connect to the column pinouts of the kpd

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

int potPin = A0; // soil sensor connected to this pin
//input pin 
int moisture=0;


void setup()
{

lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Enter Number:"); // the number which multiplies with moisture sensor value.

void loop()
{

char number = kpd.getKey();
lcd.setCursor(0,1);
lcd.print(mynumber);
delay(1000);
lcd.clear();


// map the values
int moisture = analogRead(potPin) ;
moisture = constrain(moisture, 485, 1023);
moisture = map(moisture, 485, 1023, 100, 0);
lcd.setCursor(0, 1);

//display final numbers
lcd.print(moisture * mynumber / 100);
//print the percent symbol at the end
lcd.print("%");
//wait 0.1 seconds
delay(75); 
//wipe the extra characters
lcd.print(" ");
delay(1);
}

it doesn’t seem to be working but this is an idea what i want to do.
Please help me soon i have to submit this project day after tomorrow.

    char number = kpd.getKey();
    lcd.setCursor(0, 1);
    lcd.print(mynumber);

You read a single character from the keypad, put it into a variable then print a completely different variable. Is that deliberate ?

UKHeliBob:    char number = kpd.getKey();    lcd.setCursor(0, 1);    lcd.print(mynumber);

You read a single character from the keypad, put it into a variable then print a completely different variable. Is that deliberate ?

Its nice to see your reply..Thankyou:)

No I want at least two digits for example; "10" to "99"..what to do for this?

I want at least two digits for example; "10" to "99"..what to do for this?

Read characters until you have 2 of them and put each of them into a separate variable or level of an array.

Once you have them stored you can turn them into a 2 digit number if you want. Note that as received the digits will be characters representing the digits. You need to subtract '0' from each of them to get the actual digit then multiply the tens digit by 10 and add it to the units digit to get the final number.