microrobotics

Untitled

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