Send SMS if an input is HIGH,and visualize it in the LCD

Hello All,

I want to send SMS from my GSM sheild sim 900 attached with arduino uno.

If an input (D2, D3, D4, D5, D6) is HIGH,the GSM send SMS of each high input (for 1 time) and visualize it in the LCD(until the input will be LOW) . and if there is more than one input are HIGH , I want send SMS for each for them and visualize them in the LCD.

I wrote this code , it’s ok in the compilation, but in the reality nothing is happening.

Can someone help me to solve this problem.

Thank you in advance.

#include<SoftwareSerial.h>
#include<Wire.h>
#include<LCD.h>
#include<LiquidCrystal_I2C.h>

SoftwareSerial SIM900(7, 8);
LiquidCrystal_I2C  lcd(0x27,2,1,0,4,5,6,7);

const int error1 = 2;                                  // Input D2 named error1
const int error2 = 3;                                  
const int error3 = 4;                                  
const int error4 = 5;                                  
const int error5 = 6;                                  

int SMS_error1 = 0;                                    // Variable for reading error1
int SMS_error2 = 0;                                    
int SMS_error3 = 0;                                    
int SMS_error4 = 0;                                    
int SMS_error5 = 0;                                    

void setup() { 
  pinMode(error1, INPUT);                              // Initialize error1 pin as an input
  pinMode(error2, INPUT);                             
  pinMode(error3, INPUT);                              
  pinMode(error4, INPUT);                              
  pinMode(error5, INPUT);                              
  
  // Activate LCD module
  lcd.begin(16,2);                                     // For 16 x 2 LCD module
  lcd.setBacklightPin(3,POSITIVE);                     
  lcd.setBacklight(HIGH);                              // Backlight on of the lcd module                         
  
  // activate GSM Sheild
  SIM900.begin(19200);                                 // Start the exchange between GSM Sheild and arduino Uno by speed of 19200 baud
  SIM900power();                                       // Wake up the GSM Sheild
  delay(20000);                                        // Give time to log on to network
}

void SIM900power(){   
// Software equivalent of pressing the GSM shield "power" button  
  digitalWrite(9 ,HIGH); 
  delay(1000);
  digitalWrite(9 ,LOW);
  delay(5000); 
}

void loop() {
  SMS_error1 = digitalRead(error1);                    // Reading of the input error1 and put it in SMS_error1
  SMS_error2 = digitalRead(error2);                   
  SMS_error3 = digitalRead(error3);                 
  SMS_error4 = digitalRead(error4);                    
  SMS_error5 = digitalRead(error5);                   
  
  if(SMS_error1 == HIGH){
    err1();
  }
  else if(SMS_error2 == HIGH){
    err2();
  }
  else if(SMS_error3 == HIGH){
    err3();
  }
  else if(SMS_error4 == HIGH){
    err4();
  }
  else if(SMS_error5 == HIGH){
    err5();
  }
  else{
    lcd.clear();                                       // Clear the lcd module
    lcd.home();                                        // Set cursor in ( line 0 , column 0)
    lcd.print ("Step130:No error");                    // Message to print into the lcd
    delay(10000);                                      // Waiting for 10 seconds
    lcd.clear();                                       // Clear the lcd module
    delay(100);                                        // Waiting for 0.1 second
    lcd.print("Waiting ...");                          // Message to print into the lcd
    delay(10000);                                      // Waiting for 10 seconds
  }
}
  
void err1(){
  lcd.clear();
  lcd.home();
  lcd.print("Step130:error1");
  lcd.setCursor(0, 1);
  lcd.print("Sending SMS ...");
  SendSMS_error1();
  do{} while(1);
  delay(5000);
  lcd.clear();
  lcd.home();
  lcd.print("Error1 SMS sended");
}

void err2(){
  lcd.clear();
  lcd.home();
  lcd.print("Step130:error2");
  lcd.setCursor(0, 1);
  lcd.print("Sending SMS ...");
  SendSMS_error1();
  do{} while(1);
  delay(5000);
  lcd.clear();
  lcd.home();
  lcd.print("Error1 SMS sended");
}

void err3(){
  lcd.clear();
  lcd.home();
  lcd.print("Step130:error3");
  lcd.setCursor(0, 1);
  lcd.print("Sending SMS ...");
  SendSMS_error1();
  do{} while(1);
  delay(5000);
  lcd.clear();
  lcd.home();
  lcd.print("Error1 SMS sended");
}

void err4(){
  lcd.clear();
  lcd.home();
  lcd.print("Step130:error4");
  lcd.setCursor(0, 1);
  lcd.print("Sending SMS ...");
  SendSMS_error1();
  do{} while(1);
  delay(5000);
  lcd.clear();
  lcd.home();
  lcd.print("Error1 SMS sended");
}

void err5(){
  lcd.clear();
  lcd.home();
  lcd.print("Step130:error5");
  lcd.setCursor(0, 1);
  lcd.print("Sending SMS ...");
  SendSMS_error1();
  do{} while(1);
  delay(5000);
  lcd.clear();
  lcd.home();
  lcd.print("Error1 SMS sended");
}

void SendSMS_error1(){
  SIM900.print("AT+CMGF=1\r");                         // AT command to send SMS message
  delay(100);
  SIM900.println("AT + CMGS = \"+212673157381\"");     // recipient's mobile number, in international format
  delay(100);
  SIM900.println("Step 130: error 1");                 // message to send
  delay(100);
  SIM900.println((char)26);                            // End AT command with a ^Z, ASCII code 26
  delay(100);  
  SIM900.println();
  delay(5000);                                         // give module time to send SMS
  SIM900power();
}

void SendSMS_error2(){
  SIM900.print("AT+CMGF=1\r");                         
  delay(100);
  SIM900.println("AT + CMGS = \"+212673157381\"");     
  delay(100);
  SIM900.println("Step 130: error 2");                 
  delay(100);
  SIM900.println((char)26);                            
  delay(100); 
  SIM900.println();
  delay(5000);                                        
  SIM900power();
}

void SendSMS_error3(){
  SIM900.print("AT+CMGF=1\r");                         
  delay(100);
  SIM900.println("AT + CMGS = \"+212673157381\"");     
  delay(100);
  SIM900.println("Step 130: error 3");        
  delay(100);
  SIM900.println((char)26);                       
  delay(100); 
  SIM900.println();
  delay(5000);                                     
  SIM900power();
}  

void SendSMS_error4(){
  SIM900.print("AT+CMGF=1\r");                         
  delay(100);
  SIM900.println("AT + CMGS = \"+212673157381\"");     
  delay(100);
  SIM900.println("Step 130: error 4");        
  delay(100);
  SIM900.println((char)26);                       
  delay(100); 
  SIM900.println();
  delay(5000);                                     
  SIM900power();
}

void SendSMS_error5(){
  SIM900.print("AT+CMGF=1\r");                         
  delay(100);
  SIM900.println("AT + CMGS = \"+212673157381\"");     
  delay(100);
  SIM900.println("Step 130: error 5");        
  delay(100);
  SIM900.println((char)26);                       
  delay(100); 
  SIM900.println();
  delay(5000);                                     
  SIM900power();
}

If an input (D2, D3, D4, D5, D6) is HIGH

What is connected to whose pins? Is the input guaranteed to be either or high or low? Is it guaranteed to never be floating?

  digitalWrite(9 ,HIGH); 
  delay(1000);
  digitalWrite(9 ,LOW);
  delay(5000);

Naming some pins, but not others, is not indicative of being the sharpest crayon in the box.

  SMS_error1 = digitalRead(error1);                    // Reading of the input error1 and put it in SMS_error1
  SMS_error2 = digitalRead(error2);                   
  SMS_error3 = digitalRead(error3);                 
  SMS_error4 = digitalRead(error4);                    
  SMS_error5 = digitalRead(error5);

Why do these variables need to be global? Why are you NOT using an array and for loop?

  do{} while(1);
  delay(5000);
  lcd.clear();
  lcd.home();
  lcd.print("Error1 SMS sended");
}

Putting code after the "stop here forever" part is not really bright!

What do your Serial.print() statements tell you is happening?