Arduino Nano communicate with SIM800C

Thank

  Original author: https: //blog.csdn.net/weixin_44481398/article/details/86596933#commentBox

  For a long time I did not find, using his code it once.

  My tutorial may not understand, do not understand is recommended to view the original link.

Start of Text

First pictures (not the same SIM800C):

 

 

 wiring:

 overall:

 

 

 Arduino:

 Description:

  1. SIM800c Sim card that side is negative, the chip that positive side. Pin for the next
  2. 6 pinhole below (only use 4) were 3.3V, GND, RX, TX
  3. Arduino used to 3.3V, GND, 10 (RX), 11 (TX)

 

 wiring:

  1. Sim800c 3.3V -> 3.3V Arduino
  2. Sim800c GND -> Arduino GND
  3. Sim800c RX -> Arduino TX
  4. Sim800c TX -> Arduino RX

Code :

#include <SoftwareSerial.h>        // 采用软件的串口

SoftwareSerial SIM800C(10, 11);     // Serial RX, TX
boolean bState, bOldState;
int incomingByte = 0;               // for incoming serial data

void setup() {
  // put your setup code here, to run once:
  // Open serial communications and wait for port to open
  pinMode(13, OUTPUT);
  Serial.begin(9600);
  while (!Serial) {
    ;   // wait for serial port to connect. Needed for native USB port only
  } 

  Serial.println("Good Morning, my old friend!");
  
  SIM800C.begin(9600);
  SIM800C.println("AT+CMGF=1");
  
}

void loop() {
  // put your main code here, to run repeatedly:
  if (SIM800C.available()) {
    Serial.write(SIM800C.read());
    digitalWrite(13, HIGH);// 如果通信成功,则把Arduino上面的L13 LED 灯打开
  }
  if (Serial.available()) {
    SIM800C.write(Serial.read());
//    incomingByte = Serial.read();
//    Serial.print("I received: ");
//    Serial.println(incomingByte, DEC);
//    digitalWrite(13, !digitalRead(13));
  }
  
}

 测试:

  

  

  在这里我们发送了一个AT命令,SIM800C返回一个Ok。再发送一个AT+GSV,返回:
  13:33:20.943 -> SIMCOM_Ltd
  13:33:20.943 -> SIMCOM_SIM800C
  13:33:20.979 -> Revision:1418B06SIM800C24
  通讯成功。任务初步完成。

备注:

  AT命令可以百度查找,如:https://blog.csdn.net/bihaiqiyuan/article/details/17595327,https://blog.csdn.net/wzt_007/article/details/78557268。

  只要根据教程如输入AT 返回OK即表示连线正确和程序正常运行。命令格式: AT, AT+GSV等

 

 

Guess you like

Origin www.cnblogs.com/xiaqiuchu/p/11568269.html