0

I created an Arduino program that can be send and receive SMS/voice calls. But I do not know how to receive a phone call.

Everything works except the Get_Call() function. I want this function to receive a phone call and stop this call with a serial command like my Send_Call function.

I haven't found how the program can receive phone calls with AT commands.

This is my code:

#include <SoftwareSerial.h>

SoftwareSerial SIM900(7, 8);
char message=0;

void setup() {
  SIM900.begin(19200);
  delay(25000);
  Serial.begin(19200);
  Serial.println("OK");
  digitalWrite(9, HIGH);
  delay(1000);
}

void Send_Call() {
  SIM900.println("ATD 0608446677;");
  delay(100);
  SIM900.println();
  while(Serial.read() != '1') {
    delay(100);
  }
  SIM900.println("ATH");
  delay(1000);
}

void Send_SMS() {
  SIM900.print("AT+CMGF=1\r");
  delay(100);
  SIM900.println("AT+CMGS=\"0608446677\"");
  delay(100);
  SIM900.println("test sms");
  delay(100);
  SIM900.println((char)26);
  delay(100);
  SIM900.println();
  delay(5000);
  Serial.println("SMS sent successfully");
}

void Get_SMS() {
  SIM900.println("AT+CNMI=2,2,0,0,0"); 
  delay(1000);
}

void Get_Call() {
}

void loop() {
  if (Serial.available()>0) {
    if(Serial.read() == 'p') {
      Send_Call();
    }
    if(Serial.read() == 's') {
      Send_SMS();
    }
   Get_SMS();
   Get_Call();
  }

 if (SIM900.available()>0)
   Serial.write(SIM900.read());
}

I tried this for Get_Call():

void Get_Call() {
  SIM900.print("AT+ATA\r\n"); //accept call
  SIM900.print("AT+CLIP=1\r\n"); //view phone number
  while(Serial.read() != '1') {
    delay(100);
  }
  SIM900.println("ATH"); //exit call when send in com '1'
}
dda
  • 6,030
  • 2
  • 25
  • 34
sazearte
  • 349
  • 1
  • 4
  • 12

2 Answers2

1

I found the problem with your code. It resides in the Get_Call. The problem is with the following two lines of codes :

char incoming_char=0;
incoming_char=SIM900.read();

Understand a fact that SIM900.read() returns an integer value or Its character value is not equal to 'R'.

So you need to change the incoming_char to int variable and the if condition also.

code :

 int incoming_char=0;
  incoming_char=SIM900.read();
  if(incoming_char==252)
  {
      SIM900.println("ATA\r\n");

      delay(5000000);
      SIM900.println("ATH");
  }

The above given code is enough to do that.

N.B : It would attend the call automatically after 4 to 5 rings.

Mathews Sunny
  • 1,796
  • 7
  • 21
  • 31
  • the condition if(incoming_char==252) not work for me... But if i remove if condition and i send call the code SIM900.println("ATA\r\n"); accept my call – sazearte Dec 21 '17 at 13:51
  • @sazearte anyways nice work. Because I haven't seen such a try before. Bringing something new is the way to success in IOT. – Mathews Sunny Dec 21 '17 at 13:56
  • So it works for you. ok i am happy to hear that. Accept and upvote the answer if it helps you and if you think it should help others with similar doubt – Mathews Sunny Dec 21 '17 at 13:57
0

Use the command "ATA" to answer the call. In my project, I kept this command in void loop. So whenever there is an incoming call it will automatically answers. You can keep the same in your function. To disconnect the call use "ATH". In your code add: SIM900.println("ATA");

  • I use ata command SIM900.print("AT+ATA\r\n"); maybe i not use correct ? why my function void Get_Call() not work ? what is error ? – sazearte Dec 16 '17 at 14:58
  • @AakhilShaik he has clearly stated that, it didn't worked. he wanted to clear the issue regarding the function (get_call). – Mathews Sunny Dec 17 '17 at 03:16
  • Instead of SIM900.print("AT+ATA\r\n"); / use SIM900.println("ATA"); in your function. It worked for me. – Aakhil Shaik Dec 17 '17 at 03:32
  • I view "ring" message, but how can i accept this call ? SIM900.println("ATA"); not open call for me – sazearte Dec 17 '17 at 19:25
  • You called Get_Call() function only when serial monitor is opened. So Insert Get_Call(); in second if i.e., if (SIM900.available()>0) . – Aakhil Shaik Dec 18 '17 at 03:10