کد کامل
کد:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
#define GSMReset 5
void setup() {
Serial.begin(19200); //Скорость порта для связи Arduino с компьютером
Serial.println("Goodnight moon!");
mySerial.begin(19200); //Скорость порта для связи Arduino с GSM модулем
pinMode(GSMReset, OUTPUT);
digitalWrite(GSMReset, HIGH);
delay(10);
digitalWrite(GSMReset, LOW);
delay(100);
digitalWrite(GSMReset, HIGH);
delay(7000);
// sendCommand("AT+IPR=2400", 200);
// mySerial.begin(2400);
sendCommand("AT+CFUN=1", 2000);
sendCommand("AT+CREG?", 100);
// sms("salam","+980000000000");
sendCommand("ATD00000000000;", 100);
//ensms();
//delay(500);
//farsisms();
}
void loop() {
readSerial();
}
void readSerial() {
while (mySerial.available())
Serial.write(mySerial.read());
}
void sendCommand(String cmd, int t)
{
mySerial.println(cmd);
delay(t);
readSerial();
}
void ensms()
{
mySerial.println("AT+CSCS=\"IRA\"");
delay(200);
readSerial();
mySerial.println("AT+CMGF=1");
delay(200);
readSerial();
mySerial.println("AT+CSMP=17,167,0,0");
delay(200);
readSerial();
mySerial.println("AT+CMGS=\"+980000000000\"");
delay(500);
readSerial();
mySerial.print("Salam\r\n AftabRayaneh !\x1A");
}
void farsisms()
{
//mySerial.println("AT+CSCS=\"UCS2\"");
mySerial.println("AT+CSCS=\"HEX\"");
delay(100);
readSerial();
mySerial.println("AT+CMGF=1");
delay(100);
readSerial();
mySerial.println("AT+CSMP=17,167,0,8");
delay(100);
readSerial();
mySerial.println("AT+CMGS=\"+980000000000\"");
delay(500);
readSerial();
mySerial.print("0633064406270645060C002006220641062A0627062800200631062706CC062706460647\x1A");
}