mình mới làm quen với arduino uno với module sim900a bạn nào pro giúp mình với
khi sim900 nhận đươc tin nhắn ON1 thì chân 13 = 1 sau đó nó gửi tin nhắn ngược lại ON
code mình copy chỉnh sửa không biết đúng không simm900a của mình hư rồi bạn nào pro làm giúp mình với tại đang gắp
khi sim900 nhận đươc tin nhắn ON1 thì chân 13 = 1 sau đó nó gửi tin nhắn ngược lại ON
code mình copy chỉnh sửa không biết đúng không simm900a của mình hư rồi bạn nào pro làm giúp mình với tại đang gắp
Code:
#include <SoftwareSerial.h>
char inchar; // Will hold the incoming character from the GSM shield
SoftwareSerial SIM900(7, 8);
int led = 13;
void setup()
{
Serial.begin(19200);
// set up the digital pins to control
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
// wake up the GSM shield
SIM900.begin(19200);
delay(20000); // give time to log on to network.
SIM900.print("AT+CMGF=1\r"); // set SMS mode to text
delay(100);
SIM900.print("AT+CNMI=2,2,0,0,0\r");
// blurt out contents of new SMS upon receipt to the GSM shield's serial out
delay(100);
Serial.println("Ready...");
}
void loop()
{
if(SIM900.available() >0)
{
inchar=SIM900.read();
if (inchar=='ON1')
delay(10);
digitalWrite(led, HIGH);
delay(10);
}
}
void sendSMS()
{
SIM900.print("AT+CMGF=1\r"); // AT command to send SMS message
delay(100);
SIM900.println("AT + CMGS = \"+840123456789\""); // recipient's mobile number, in international format
delay(100);
SIM900.println("ON"); // message to send
delay(100);
SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26
delay(100);
SIM900.println();
delay(5000); // give module time to send SMS
}
void loop2()
{
sendSMS();
do {} while (1);
}
