Hello everybody,
I've been working on an Arduino MKR GSM 1400 to automatically answer an intercom and open a gate that is connected to the intercom via an external GSM module.
The reason for this is that the intercom was connected to a mobile phone that rang all damn day.
All we had to do was to press "#" when the intercom number called.
Or, if we wanted to manually open the gate we had to call the number and it would open automatically too.
Now, see below how I've written this down into the following code to answer the call, redial the number again in order to also open the gate if we would call with an external number:
// Define LED's and Buttons
const int ledConnected = 0; // Turns on if the GSM connection is estabilished
const int ledIncoming = 1; // Turns on when there is an incoming call
const int ledOutgoing = 2; // Turns on when there is an outgoing call
const int ledNoGSM = 3; // Turns on if there is no connection
const int buttonPin = 4; // To manually open the gate, pin this wire from the switch end towards 5V
const int ledPin = 13; // the number of the LED pin
int buttonState = 0; // variable for reading the pushbutton status
#include <MKRGSM.h>
GSM gsmAccess;
GSMVoiceCall vcs;
// Parameters definition
#define PINNUMBER "0000" // Fill in the PIN code when the SIM card has a pin code
const char gatenumber[] = "0612345678"; // Number of the gate to call open, by default number is 0612345678
char incomingnumber[20]; // Array to hold the number for the incoming call
void setup() { // Start setup script
Serial.begin(9600); // Start serial monitor
pinMode(ledConnected, OUTPUT); // LED will light up once the connection has been made to the GSM network
pinMode(ledIncoming, OUTPUT); // LED will light up if there is an incoming call
pinMode(ledOutgoing, OUTPUT); // LED will light up if the gate will be opened
pinMode(ledNoGSM, OUTPUT); // LED will light up if there is no GSM connection
pinMode(LED_BUILTIN, OUTPUT); // LED will be used as a status LED for the board if nothing is happening
pinMode(buttonPin, INPUT);
// Initialise GSM connection
boolean notConnected = true;
Serial.print("Setting up GSM connection...");
while (notConnected) {
digitalWrite(ledNoGSM, HIGH);
if (gsmAccess.begin(PINNUMBER) == GSM_READY) { // Uncomment this line if you have a SIM card with PIN code
notConnected = false;
Serial.println("Connected!");
digitalWrite(ledNoGSM, LOW);
digitalWrite(ledConnected, HIGH); // LED will show that connection has been made
} else {
Serial.println(" Not connected!");
digitalWrite(ledNoGSM, HIGH);
delay(1000);
}
}
vcs.hangCall(); // This makes sure the modem correctly reports incoming events
Serial.println("Ready to take a call and open the gate!");
}
void loop() { // Actual loop script that runs over and over untill eternity
// Script that runs while we are waiting for a call
switch (vcs.getvoiceCallStatus()) { // Check current voice call status
default: // Nothing is happening
break;
case RECEIVINGCALL: // Gate is being called either from the intercom or an external number
Serial.println("Receiving call");
vcs.retrieveCallingNumber(incomingnumber, 20); // Get the callers number and print on the serial monitor, maybe in later development print it on a LED screen
Serial.print("Number:");
Serial.println(incomingnumber);
delay(250);
// Answer the phone, establish the call
vcs.answerCall();
delay(250);
break;
case TALKING: // In this case the call would be established
Serial.println("Call estabilished");
vcs.retrieveCallingNumber(incomingnumber, 20); // Get the callers number and print on the serial monitor
if (incomingnumber == gatenumber) {
delay(1500);
vcs.writeDTMF('#');
delay(4000);
vcs.hangCall();
} else {
delay(1500);
Serial.println("Hanging the call and call the gate again to open...");
vcs.hangCall();
delay(1500);
// Call the gate again
vcs.voiceCall(gatenumber); {
while (vcs.getvoiceCallStatus() == TALKING); // Check if the receiving end has picked up the call
Serial.println("Call Established. gate will be opened automatically.");
}
delay(2000);
vcs.hangCall(); // Hang up after 2,5 seconds
Serial.println("Gate succesfully opened, ready for the next call");
break;
}
break;
}
}
I still only have the following problem: I want to speed up things such that if the incoming number is equal to the gatenumber, it would write the DTMF tone for "#". Else, it should redial the number again to manually open the gate like in all other cases.
However, I can't get my equal sign to work with the incomingnumber vs gatenumber comparison, as shown below.
case TALKING: // In this case the call would be established
Serial.println("Call estabilished");
vcs.retrieveCallingNumber(incomingnumber, 20); // Get the callers number and print on the serial monitor
if (incomingnumber == gatenumber) {
delay(1500);
vcs.writeDTMF('#');
delay(4000);
vcs.hangCall();
} else {
delay(1500);
Serial.println("Hanging the call and call the gate again to open...");
vcs.hangCall();
delay(1500);
// Call the gate again
vcs.voiceCall(gatenumber); {
while (vcs.getvoiceCallStatus() == TALKING); // Check if the receiving end has picked up the call
Serial.println("Call Established. gate will be opened automatically.");
}
delay(2000);
vcs.hangCall(); // Hang up after 2,5 seconds
Serial.println("Gate succesfully opened, ready for the next call");
break;
}
Does anybody know a solution for this problem? Maybe my definition of char is not correct or the equal signs?
Thanks!