Arduino 2 digit Keypad Input , Display and Store to Use Further in Program.

Thread Starter

kayjabbar

Joined Sep 8, 2016
50
Hello folks,

I hope you all are doing well.

At first I am totally new to Arduino, I am sorry for any mistakes (if made) regarding the code (quoted below ''second one").

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.

this is a running code for moisture sensing module for soil
Code:
#include <LiquidCrystal.h>
// include the LCD library
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// 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(moisture, 485, 1023);
moisture = map(moisture, 485, 1023, 100, 0);
lcd.setCursor(0, 1);
//display final numbers
lcd.print(moisture);
//print the percent symbol at the end
lcd.print("%");
//wait 0.1 seconds
delay(75);
//wipe the extra characters
lcd.print(" ");
delay(1);
}
Now the program which will go on somewhat like this;

Code:
#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();
// here I also want to reset the program by pressing " * " button and ENTER by " # " to execute the rest of the program and calculation.


// 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);
}
I looked up for keypad examples.
also reviewed a calculator code (it seems very complex in comparison to this little piece of work )
, basic input and display on lcd program etc.
but nothing's working for me.
Please help!
 
Last edited:
Top