Reputation: 379
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'
}
Upvotes: 0
Views: 3475
Reputation: 1642
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.
Upvotes: 1
Reputation: 89
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");
Upvotes: 0