Go Down

Topic: Smart intercom using GSM shield help me improve program !!!! (Read 805 times) previous topic - next topic

rashedalkawari92

Hi guys as the title says i am currently working on the project to make the smart intercom , The main components i am using for this project are Arduino Mega 2560, GSM SHIELD,  JHD 162A LCD Screen 8pin 4x4 Hex keypad,  electric magnet , and some push buttons.

The project should work as follows

1: when i press the button it should call the number .
2: when  i send the sms to GSM shield character 1 it should switch off the magnet
3: when i enter password in keypad it should also switch off the magnet
4: when i press the other push button it should also switch off the magnet

The problem i have is that the system works sometime well and some times some functions lag like lcd prints screen too late or some times when i press the button it does not initiate phone call what i am looking for is the improvement of the Code i am using below would really appreciate :) ...


Below is the program i use:


#include <GSM.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
#include <Password.h>
Password password = Password( "1234" );
// PIN Number
#define PINNUMBER ""

// initialize the library instance
GSM gsmAccess; // include a 'true' parameter for debug enabled
GSMVoiceCall vcs;
GSM_SMS sms;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(33, 31, 29, 27, 25, 23);

char charbuffer[20];
char senderNumber[20];
int callbutton = 35 ;
int indoorbutton = 37 ;
int magnet = 39 ;
int xyz = 0;
const byte ROWS = 4; //four rows
const byte COLS = 4; // four columns
char keys[ROWS][COLS] = {
  {'1','2','3','F'},
  {'4','5','6','E'},
  {'7','8','9','D'},
  {'A','0','B','C'}
};
byte rowPins[ROWS] = {28, 26, 24, 22}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {36, 34, 32,30}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{

  // initialize serial communications
  Serial.begin(38400);
  keypad.addEventListener(keypadEvent);
  lcd.begin(16, 2);
  pinMode(callbutton,INPUT);
  pinMode(magnet,OUTPUT);
  digitalWrite(magnet,HIGH);
  digitalWrite(indoorbutton,HIGH);///// active low
  digitalWrite(callbutton,HIGH); //// Active LOW
  pinMode(indoorbutton,INPUT);
  // connection state
  boolean notConnected = true;

  // Start GSM shield
  // If your SIM has PIN, pass it as a parameter of begin() in quotes
  while(notConnected)
  {
    if(gsmAccess.begin(PINNUMBER)==GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }
  vcs.hangCall(); // This makes sure the modem notifies correctly incoming events
  Serial.println("GSM initialized.");
}
void loop()
{
 //we put all read buttons here !!!!!!
    callbutton = digitalRead(35) ;
    indoorbutton = digitalRead(37);
    keypad.getKey();
     
      if (xyz == 0){
     
        lcd.setCursor(0,0);
      lcd.print("Press the button");
      lcd.setCursor(0, 1);
      lcd.print("to call owner");
      }   
     
       if (xyz == 1) {
    lcd.setCursor(0, 0);              /////////// put timer here would look cooler
    lcd.print("Call established");
   
  }
   
    if (callbutton == LOW){
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Calling Owner");
    vcs.voiceCall("0555566340");
    }
    xyz = 0;
    switch (vcs.getvoiceCallStatus())
    {
    case IDLE_CALL:
    break ;
    case CALLING:
    break ;
    case TALKING:
    xyz = 1;
    break ;
    case RECEIVINGCALL:
    vcs.answerCall();
    break;
   
   
   
 
    }
 



////////////////////// SMS program
   


  char c;

  // If there are any SMSs available()
  if (sms.available())
  {
    Serial.println("Message received from:");

    // Get remote number
    sms.remoteNumber(senderNumber, 20);
    Serial.println(senderNumber);

    // An example of message disposal
    // Any messages starting with # should be discarded
    if (sms.peek() == '#')
    {
      Serial.println("Discarded SMS");
      sms.flush();
    }
    // Read message bytes and print them
    while (c = sms.read())
    {
      Serial.println(c);
      if(c == '1'){
      digitalWrite(magnet,LOW);
      delay(6000);
      digitalWrite(magnet,HIGH);   }
     
    Serial.println("END OF MESSAGE");

    // Delete message from modem memory
    sms.flush();
    Serial.println("MESSAGE DELETED");
   
  }
delay(1000);
 

}
}


//take care of some special events
void keypadEvent(KeypadEvent eKey){

  switch (keypad.getState()){
   case m_key::PRESSED :
  Serial.print("Pressed: ");
  Serial.println(eKey);
  switch (eKey){
    case 'A': checkPassword(); break;
    case 'C': password.reset(); break;
    default: password.append(eKey);
     }
  }
}

void checkPassword(){
  if (password.evaluate()){
    Serial.println("Success");
    digitalWrite(magnet,LOW);
    delay(6000);
    digitalWrite(magnet,HIGH);
   
  }else{
    Serial.println("Wrong");
    //add code to run if it did not work
  }
if(indoorbutton == LOW)
{
  digitalWrite(magnet,LOW);
  delay(6000);
  digitalWrite(magnet,HIGH);
}
 
}


Go Up