Advertisement
microrobotics

SIM800

Jul 27th, 2021 (edited)
7,784
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <softwareserial.h>
  2. #define SIM800_TX_PIN 2  //SIM800 TX is connected to Arduino D2  
  3. #define SIM800_RX_PIN 3 //SIM800 RX is connected to Arduino D3
  4.  
  5. //Create software serial object to communicate with SIM800
  6. SoftwareSerial serialSIM800(SIM800_TX_PIN,SIM800_RX_PIN);
  7.  
  8. int PWX = 4;  
  9.  
  10. void setup() {
  11.    
  12.   pinMode(PWX, OUTPUT);
  13.    
  14.   //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
  15.   Serial.begin(9600);   //Begin serial communication with Arduino
  16.   while(!Serial);       //Monitor Comms on Arduino IDE (Serial Monitor)  
  17.    
  18.   //Being serial communication with Arduino and SIM800
  19.   serialSIM800.begin(9600);
  20.   delay(1000);
  21.    
  22.   Serial.println("Setup Complete!");
  23.  
  24.   digitalWrite(PWX, HIGH);
  25.   delay(3000);
  26.   digitalWrite(PWX, LOW);    
  27.   delay(1000);
  28.   Serial.println("Start");
  29. }
  30.  
  31. void loop() {
  32.   //Read SIM800 output (if available) and print it in Arduino IDE Serial Monitor
  33.   if(serialSIM800.available()){
  34.     Serial.write(serialSIM800.read());
  35.   }
  36.   //Read Arduino IDE Serial Monitor inputs (if available) and send them to SIM800
  37.   if(Serial.available()){    
  38.     serialSIM800.write(Serial.read());
  39.   }
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement