user45166: I am trying to input 11 numbers only by the use of keypad but the problem is whenever i use this code. It gave me this error.
Here's my code. Help please.
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
SoftwareSerial mySerial(6, 5);
int table[] = { 0, 0, 0 };
#include <Keypad.h>
#include <Wire.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
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] = { 2, 3, 17, 16 }; //connect to the row pinouts of the keypad
byte colPins[COLS] = { 15, 14, 13 }; //connect to the column pinouts of the keypad
int count = 0;
Keypad kpd = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
char entryStr[13]; // This can hold up to 4 digits
int i = 0;
char n1, n2, n3;
char buf[15]; // i put here***
void setup()
{
    Wire.begin();
    Serial.begin(9600);
    Serial.begin(9600);
    lcd.begin(20, 4);
    ask();
}

void loop()
{
    Wire.requestFrom(2, 3); // request 6 bytes from slave device #2 for(int i=0;i<3;i++) {

    int c = Wire.read(); // receive a byte as character
    Serial.print(c);
    table[i] = c;
    Serial.print('\t');
    // print the character } Serial.print('\n'); Serial.print(table[0]); Serial.print('\t'); Serial.print(table1); Serial.print('\t'); Serial.print(table[2]); Serial.print('\n');

    //if(table[0]<=8) //{ //Serial.print("Flame Detected!"); //Serial.println("Level1");
}
void ask()
{

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Enter no1.:");
    lcd.setCursor(0, 1);
    lcd.print("(starts with 0)");
    lcd.setCursor(1, 2);
    n1 = GetNumber(buf, sizeof(buf) - 1);

    Serial.print(n1);

    delay(1);

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Enter no2.:");
    lcd.setCursor(0, 1);
    lcd.print("(starts with 0)");
    lcd.setCursor(1, 2);
    n2 = GetNumber(buf, sizeof(buf) - 1);

    Serial.println(n2);
    delay(1);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Enter no3.:");
    lcd.setCursor(0, 1);
    lcd.print("(starts with 0)");
    lcd.setCursor(1, 2);
    n3 = GetNumber(buf, sizeof(buf) - 1);

    Serial.println(n3);
    delay(1);
    Serial.println(n1);
    Serial.println(n2);
    Serial.println(n3);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("list of numbers ");
    lcd.setCursor(0, 1);
    lcd.print("will be shown press");
    lcd.setCursor(1, 2);
    lcd.print("reset if wrong");

    delay(7000);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Numbers Stored:");
    lcd.setCursor(0, 1);
    lcd.print("no1.:0");
    lcd.print(n1);
    lcd.setCursor(1, 2);
    lcd.print("no2.:0");
    lcd.print(n2);
    lcd.setCursor(2, 3);
    lcd.print("no3.:0");
    lcd.print(n3);
}
void GetNumber(char* result, const int maxLength)
{
    char key = kpd.getKey();
    int i = 0; // how far through buffer we are
    while (key != '#') {
        switch (key) {
        case NO_KEY:
            break;

        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':

            lcd.print(key);
            if (i < maxLength) {
                result[i++] = key;
                result[i] = 0; // terminating null
            }
            break;

        case '*': // backspace
            if (i > 0) {
                i--;
                result[i] = 0; // terminating null
            }

            break;
        }

        key = kpd.getKey();
    }

} // end of GetNumber



user27653: The GetNumber() function is coded in such a way as to pass the collected value back through the result parameter.

void GetNumber(char* result, const int maxLength)


So, when you use the GetNumber() function, you pass it buf, and after the call returns, you will find the result in the buf char array.
However, you appear to be trying to store the result in n1, n2, and n3, which are char type variables, and can hold only one character, or a number between 0 and 255, neither of which can hold an 11-digit string of numbers like you wish.
A char is an 8-bit variable. An int (on Arduino Uno) is a 16-bit value and can hold at most 32,768. Even an unsigned long, a 32-bit variable of all positive numbers, can hold a maxiumum value of 4,294,967,295, which gets at most all 9-digit numbers, and some 10-digit numbers.
You would probably be better off holding the numbers as character arrays just like buf, and passing those as the first parameter of GetNumber() instead of buf:
char n1[15], n2[15], n3[15];
...
GetNumber(n1, sizeof(n1) - 1);
...
GetNumber(n2, sizeof(n2) - 1);
...
GetNumber(n3, sizeof(n3) - 1);

If you do that, then you can get rid of buf entirely.
Alternatively, you can keep buf as the temporary holder of the incoming string and use strncpy() to copy the string from buf to n1 (etc.):
GetNumber(buf, sizeof(buf) - 1);
strncopy(n1, buf, sizeof(n1));

This method uses more memory, as you have buf taking up space, but it has an advantage that you can later do validation or error checking on the user input before you overwrite n1 or the others with the new value.

user359: Your GetNumber function is defined to return void (nothing) while you use it as if it returns the number typed.
change GetNumber to return a int and the end of it do a atoi using the buffer and return the result.

45166: <p>I am trying to input 11 numbers only by the use of keypad but the problem is whenever i use this code. It gave me this error.</p>

<p>Here's my code. Help please.</p>

<pre><code>#include &lt;SoftwareSerial.h&gt;
#include &lt;LiquidCrystal.h&gt;
SoftwareSerial mySerial(6, 5);
int table[] = { 0, 0, 0 };
#include &lt;Keypad.h&gt;
#include &lt;Wire.h&gt;
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
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] = { 2, 3, 17, 16 }; //connect to the row pinouts of the keypad
byte colPins[COLS] = { 15, 14, 13 }; //connect to the column pinouts of the keypad
int count = 0;
Keypad kpd = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
char entryStr[13]; // This can hold up to 4 digits
int i = 0;
char n1, n2, n3;
char buf[15]; // i put here***
void setup()
{
    Wire.begin();
    Serial.begin(9600);
    Serial.begin(9600);
    lcd.begin(20, 4);
    ask();
}

void loop()
{
    Wire.requestFrom(2, 3); // request 6 bytes from slave device #2 for(int i=0;i&lt;3;i++) {

    int c = Wire.read(); // receive a byte as character
    Serial.print(c);
    table[i] = c;
    Serial.print('\t');
    // print the character } Serial.print('\n'); Serial.print(table[0]); Serial.print('\t'); Serial.print(table1); Serial.print('\t'); Serial.print(table[2]); Serial.print('\n');

    //if(table[0]&lt;=8) //{ //Serial.print("Flame Detected!"); //Serial.println("Level1");
}
void ask()
{

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Enter no1.:");
    lcd.setCursor(0, 1);
    lcd.print("(starts with 0)");
    lcd.setCursor(1, 2);
    n1 = GetNumber(buf, sizeof(buf) - 1);

    Serial.print(n1);

    delay(1);

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Enter no2.:");
    lcd.setCursor(0, 1);
    lcd.print("(starts with 0)");
    lcd.setCursor(1, 2);
    n2 = GetNumber(buf, sizeof(buf) - 1);

    Serial.println(n2);
    delay(1);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Enter no3.:");
    lcd.setCursor(0, 1);
    lcd.print("(starts with 0)");
    lcd.setCursor(1, 2);
    n3 = GetNumber(buf, sizeof(buf) - 1);

    Serial.println(n3);
    delay(1);
    Serial.println(n1);
    Serial.println(n2);
    Serial.println(n3);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("list of numbers ");
    lcd.setCursor(0, 1);
    lcd.print("will be shown press");
    lcd.setCursor(1, 2);
    lcd.print("reset if wrong");

    delay(7000);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Numbers Stored:");
    lcd.setCursor(0, 1);
    lcd.print("no1.:0");
    lcd.print(n1);
    lcd.setCursor(1, 2);
    lcd.print("no2.:0");
    lcd.print(n2);
    lcd.setCursor(2, 3);
    lcd.print("no3.:0");
    lcd.print(n3);
}
void GetNumber(char* result, const int maxLength)
{
    char key = kpd.getKey();
    int i = 0; // how far through buffer we are
    while (key != '#') {
        switch (key) {
        case NO_KEY:
            break;

        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':

            lcd.print(key);
            if (i &lt; maxLength) {
                result[i++] = key;
                result[i] = 0; // terminating null
            }
            break;

        case '*': // backspace
            if (i &gt; 0) {
                i--;
                result[i] = 0; // terminating null
            }

            break;
        }

        key = kpd.getKey();
    }

} // end of GetNumber
</code></pre>

<p><a href="https://i.stack.imgur.com/rHVR9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rHVR9.png" alt="enter image description here"></a></p>
 27653: <p>The <code>GetNumber()</code> function is coded in such a way as to pass the collected value back through the <code>result</code> parameter.</p>

<blockquote>
<pre><code>void GetNumber(char* result, const int maxLength)
</code></pre>
</blockquote>

<p>So, when you use the <code>GetNumber()</code> function, you pass it <code>buf</code>, and after the call returns, you will find the result in the <code>buf</code> char array.</p>

<p>However, you appear to be trying to store the result in <code>n1</code>, <code>n2</code>, and <code>n3</code>, which are <code>char</code> type variables, and can hold only one character, or a number between <code>0</code> and <code>255</code>, neither of which can hold an 11-digit string of numbers like you wish.</p>

<p>A <code>char</code> is an 8-bit variable. An <code>int</code> (on Arduino Uno) is a 16-bit value and can hold at most <code>32,768</code>. Even an <code>unsigned long</code>, a 32-bit variable of all positive numbers, can hold a maxiumum value of <code>4,294,967,295</code>, which gets at most all 9-digit numbers, and some 10-digit numbers.</p>

<p>You would probably be better off holding the numbers as character arrays just like <code>buf</code>, and passing those as the first parameter of <code>GetNumber()</code> instead of <code>buf</code>:</p>

<pre><code>char n1[15], n2[15], n3[15];
...
GetNumber(n1, sizeof(n1) - 1);
...
GetNumber(n2, sizeof(n2) - 1);
...
GetNumber(n3, sizeof(n3) - 1);
</code></pre>

<p>If you do that, then you can get rid of <code>buf</code> entirely.</p>

<p>Alternatively, you can keep <code>buf</code> as the temporary holder of the incoming string and use <code>strncpy()</code> to copy the string from <code>buf</code> to <code>n1</code> (etc.):</p>

<pre><code>GetNumber(buf, sizeof(buf) - 1);
strncopy(n1, buf, sizeof(n1));
</code></pre>

<p>This method uses more memory, as you have <code>buf</code> taking up space, but it has an advantage that you can later do validation or error checking on the user input before you overwrite <code>n1</code> or the others with the new value.</p>
 359: <p>Your <code>GetNumber</code> function is defined to return void (nothing) while you use it as if it returns the number typed.</p>

<p>change GetNumber to return a int and the end of it do a <code>atoi</code> using the buffer and return the result.</p>
