#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
uint8_t colPins[COLS] = { 25, 33, 32, 35}; // Pins connected to C1, C2, C3, C4
uint8_t rowPins[ROWS] = { 12, 14, 27, 26 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
// SIM800L Setup
SoftwareSerial sim800lSerial(10, 11); // RX, TX
char key;
String phoneNumber = "";
// SIM MODULE INITALIZE
bool initializeSIM800L() {
sim800lSerial.begin(9600);
delay(1000);
sim800lSerial.println("AT"); // Test AT command
delay(1000);
if (sim800lSerial.find("OK")) {
sim800lSerial.println("AT+CREG?"); // Check network registration
delay(1000);
if (sim800lSerial.find("+CREG: 0,1")) {
return true;
}
}
return false;
}
void setup() {
Wire.begin(21, 22);
lcd.init();
lcd.backlight();
lcd.setCursor(1, 0);
lcd.print("SYSTEM STARTING");
lcd.setCursor(1, 1);
lcd.print("PLEASE WAIT...");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
if (initializeSIM800L()) {
lcd.print("SIM800L initialized");
} else {
lcd.print("Initialization failed");
while (1); // Halt if initialization fails
}
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter number:");
}
void loop() {
key = keypad.getKey();
if (key != NO_KEY) {
lcd.setCursor(0, 0);
lcd.print("Dialing: ");
lcd.print(key);
String phoneNumber;
phoneNumber += key;
while (true) {
char nextKey = keypad.getKey();
if (nextKey != NO_KEY) {
lcd.setCursor(0, 1);
lcd.print(phoneNumber);
lcd.print(nextKey);
phoneNumber += nextKey;
}
if (nextKey == '#') {
break;
}
delay(100);
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Calling...");
delay(1000);
dialNumber(phoneNumber);
}
}
void dialNumber(String number) {
sim800lSerial.print("ATD");
sim800lSerial.print(number);
sim800lSerial.println(";");
delay(1000);
while (sim800lSerial.available()) {
char c = sim800lSerial.read();
Serial.write(c);
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Call ended");
delay(2000);
lcd.clear();
}