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

Discussion in 'The Projects Forum' started by kayjabbar, Jan 3, 2017.

  1. kayjabbar

    Thread Starter Member

    Sep 8, 2016
    37
    0
    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 (Text):
    1. #include <LiquidCrystal.h>
    2. // include the LCD library
    3. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
    4. // might be different for your LCD, check the producer catalog
    5. int potPin = A0;
    6. //input pin
    7. int moisture=0;
    8.  
    9. void setup() {
    10. lcd.begin(16, 2);
    11. // lcd rows and columns
    12. lcd.print("Moisture :");
    13. }
    14.  
    15. void loop() {
    16. // map the values
    17. int moisture = analogRead(potPin) ;
    18. moisture = constrain(moisture, 485, 1023);
    19. moisture = map(moisture, 485, 1023, 100, 0);
    20. lcd.setCursor(0, 1);
    21. //display final numbers
    22. lcd.print(moisture);
    23. //print the percent symbol at the end
    24. lcd.print("%");
    25. //wait 0.1 seconds
    26. delay(75);
    27. //wipe the extra characters
    28. lcd.print(" ");
    29. delay(1);
    30. }
    Now the program which will go on somewhat like this;

    Code (Text):
    1. #include <LiquidCrystal.h>
    2. #include <Keypad.h>
    3. LiquidCrystal lcd (12, 11, 5, 4, 3, 2);
    4.  
    5. const byte ROWS = 4; //four rows
    6. const byte COLS = 3; //three columns
    7. char keys[ROWS][COLS] = {
    8. {'1','2','3'},
    9. {'4','5','6'},
    10. {'7','8','9'},
    11. {'*','0','#'}
    12. };
    13. byte rowPins[ROWS] = {9, 10, 7, 8}; //connect to the row pinouts of the kpd
    14. byte colPins[COLS] = {A3, A4, A5}; //connect to the column pinouts of the kpd
    15.  
    16. Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
    17.  
    18. int potPin = A0; // soil sensor connected to this pin
    19. //input pin
    20. int moisture=0;
    21.  
    22.  
    23. void setup()
    24. {
    25.  
    26. lcd.begin(16,2);
    27. lcd.setCursor(0,0);
    28. lcd.print("Enter Number:"); // the number which multiplies with moisture sensor value.
    29.  
    30. void loop()
    31. {
    32.  
    33. char number = kpd.getKey();
    34. lcd.setCursor(0,1);
    35. lcd.print(mynumber);
    36. delay(1000);
    37. lcd.clear();
    38. // here I also want to reset the program by pressing " * " button and ENTER by " # " to execute the rest of the program and calculation.
    39.  
    40.  
    41. // map the values
    42. int moisture = analogRead(potPin) ;
    43. moisture = constrain(moisture, 485, 1023);
    44. moisture = map(moisture, 485, 1023, 100, 0);
    45. lcd.setCursor(0, 1);
    46.  
    47. //display final numbers
    48. lcd.print(moisture * mynumber / 100);
    49. //print the percent symbol at the end
    50. lcd.print("%");
    51. //wait 0.1 seconds
    52. delay(75);
    53. //wipe the extra characters
    54. lcd.print(" ");
    55. delay(1);
    56. }
    57.  
    58.  
    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: Jan 3, 2017
Loading...