This post was last edited by xiyue521 on 2019-11-21 08:20
This content is originally created by EEWORLD forum user xiyue521 . If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source
Note: The board was obtained from the EEWorld event and provided by DFRobot.
Product link: http://www.dfrobot.com.cn/goods-1442.html 、
1. Initialization
#include <SoftwareSerial.h>
SoftwareSerial mySerial(11, 10); // TX-Pin11, RX-Pin10
void updateSerial()
{
delay(2000);
while (Serial.available()) {
mySerial.write(Serial.read());//如果Serial收到数据则通过mySerial输出
}
while(mySerial.available()) {
Serial.write(mySerial.read());//如果mySerial收到数据则通过Serial输出
}
}
void setup()
{
Serial.begin(9600);
mySerial.begin(9600);
}
void loop()
{
mySerial.println("AT"); //握手测试,成功则返回OK
updateSerial();
mySerial.println("AT+CSQ"); //信号质量测试,值为0-31,31表示最好
updateSerial();
mySerial.println("AT+CCID"); //读取SIM,可以检测是否有SIM卡或者是否接触良好
updateSerial();
mySerial.println("AT+CREG?"); //检测是否注册网络
updateSerial();
mySerial.println("AT+SNFS=0"); //调整为耳机模式(AT+SNFS=1 表示扬声器模式)
updateSerial();
mySerial.println("AT+CRSL=2"); //调整音量,值为0-15,15表示音量最大
updateSerial();
while(1)
{
if(mySerial.available())
{
Serial.write(mySerial.read());//如果mySerial收到数据则通过Serial输出
}
if(Serial.available())
{
mySerial.write(Serial.read());//如果Serial收到数据则通过mySerial输出
}
}
}
2. Send AT commands through the Ardunio serial port to make and receive calls
ATD+dial number; //dial the specified number
Ring //Incoming call
ATA //Answer incoming calls
ATH //Hang up the current call
3. Send SMS
#include <SoftwareSerial.h>
SoftwareSerial mySerial(11, 10); // TX-Pin11, RX-Pin10
void updateSerial()
{
delay(2000);
while (Serial.available()) {
mySerial.write(Serial.read());//如果Serial收到数据则通过mySerial输出
}
while(mySerial.available()) {
Serial.write(mySerial.read());//如果mySerial收到数据则通过Serial输出
}
}
void setup()
{
Serial.begin(9600);
mySerial.begin(9600);
}
void loop()
{
mySerial.println("AT"); //握手测试,成功则返回OK
updateSerial();
mySerial.println("AT+CMGF=1"); //配置短信模式为TEXT模式,只能发送英文短信!
updateSerial();
mySerial.println("AT+CMGS=\"xxxxxxxxxxx\"");//xxxxxxxxxxx为电话号码
updateSerial();
mySerial.print("Hello, this is a test"); //短信内容
updateSerial();
mySerial.write(26);
while(1)
{
if(mySerial.available())
{
Serial.write(mySerial.read());//如果mySerial收到数据则通过Serial输出
}
if(Serial.available())
{
mySerial.write(Serial.read());//如果Serial收到数据则通过mySerial输出
}
}
}