Input and store user input to set a variable

Hello Everyone,
I have a project with SIM800L, Keypad(4x4) and LCD(16x2). I want to input phone number with keypad(number phone - 12 digits) show to LCD, set that to a variable to send sms to another number phone. Please help me complete project, Thank you!

Please show us your work to date.


Always show us a good schematic of your proposed circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.


In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.

Use the < CODE / > icon from the ‘posting menu’ to attach the copied sketch.

1 Like

I'm a newbie and i just coding arduino recently. My project now complete call and send sms to someone, but i need to change the phone number to another and set as a variable when i need. i don't know this.

#include <SoftwareSerial.h>

//Create software serial object to communicate with SIM800L
SoftwareSerial mySerial(3, 2); //SIM800L Tx & Rx is connected to Arduino #3 & #2
const int pinButton = 11;
int running = 0;
void setup()
{
  pinMode(pinButton, INPUT);

  //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
  Serial.begin(9600);
  
  //Begin serial communication with Arduino and SIM800L
  mySerial.begin(9600);

  Serial.println("Initializing..."); 
  delay(1000);

  mySerial.println("AT"); //Once the handshake test is successful, it will back to OK
  updateSerial();

}

void loop()
{
    int stateButton = digitalRead(pinButton);
    if (stateButton == 1 && running == 0)
    {
    Serial.println("BUTTON PRESSED");
    updateSerial();
    mySerial.println("AT+CMGF=1"); 
    updateSerial();
    mySerial.println("AT+CMGS=\"+phone number\"");
    updateSerial();
    mySerial.print("Message"); 
    updateSerial();
    mySerial.write(26);
    delay(100);
    running ++;
    delay(100);
    }
    else if (stateButton == 1 && running >= 1 && running <= 6)
    {
    mySerial.println("ATD+ +phone number;");
    delay(1000);
    updateSerial();
    delay(60000);
    mySerial.println("NO ONE PICKUP");
    delay(100);
    mySerial.println("ATH"); //end call
    delay(500);
    updateSerial();
    delay(100);
    mySerial.println("END CALL");
    delay(500);
    running ++;
    delay(1000);
    }
   else
    { 
    Serial.println("END CODE");
    }
  delay(500);
}

void updateSerial()
{
  delay(500);
  while (Serial.available()) 
  {
    mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
  }
  while(mySerial.available()) 
  {
    Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
  }
}

Please edit your post #4, select all code and click the <CODE> button to apply so-called code tags and next save your post. It makes it easier to read, easier to copy and the forum software will display it correctly.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.