06-24-2023, 12:29 AM
Hello,
I am having difficulty for coding my script, I would like to make a GSM relay which activates the GPIO 15 relay upon the module receipt a call ! but I cannot do it can you help me?
I think my problem is from the command of call detection.
Thanks
I am having difficulty for coding my script, I would like to make a GSM relay which activates the GPIO 15 relay upon the module receipt a call ! but I cannot do it can you help me?
I think my problem is from the command of call detection.
Thanks
Code:
#include <SoftwareSerial.h>
// Create software serial object to communicate with A6
SoftwareSerial mySerial(13, 34); // A6 Tx & Rx is connected to Arduino #3 & #2
int relayPin = 15; // GPIO 15 connected to the relay
void setup()
{
// Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(115200);
// Begin serial communication with Arduino and A6
mySerial.begin(115200);
Serial.println("Initializing...");
pinMode(relayPin, OUTPUT); // Set the relay pin as an output
digitalWrite(relayPin, LOW); // Initialize the relay as OFF
}
void loop()
{
updateSerial();
checkCall();
}
void updateSerial()
{
delay(500);
while (Serial.available())
{
mySerial.write(Serial.read()); // Forward what Serial received to Software Serial Port
}
while(mySerial.available())
{
Serial.write(mySerial.read()); // Forward what Software Serial received to Serial Port
}
}
void checkCall()
{
if (mySerial.available())
{
String response = mySerial.readString();
if (response.indexOf("+CLCC: 1,1,2,4,0") != -1) // Check if "+CLCC: 1,1,2,4,0" is present in the response
{
activateRelay();
}
}
}
void activateRelay()
{
digitalWrite(relayPin, HIGH); // Turn ON the relay
delay(5000); // Keep the relay ON for 5 seconds
digitalWrite(relayPin, LOW); // Turn OFF the relay
}