Advertisement
pleasedontcode

"Arduino GSM" rev_19

Jun 13th, 2024
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "Arduino GSM"
  13.     - Source Code compiled for: Arduino Pro Mini 5V
  14.     - Source Code created on: 2024-06-13 11:06:09
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Develop a system to control a SIM800L GSM module */
  21.     /* using an Arduino. The system should handle */
  22.     /* incoming calls via the RING pin and manage power */
  23.     /* states using the RST and DTR pins. Communication */
  24.     /* occurs over SoftwareSerial on pins A0 and A1. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <SoftwareSerial.h>
  30. #include <Sim800L.h> // https://github.com/vittorioexp/Sim800L-Arduino-Library-revised
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35. void updateOutputs(void);
  36.  
  37. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  38. const uint8_t tre_SIM800L_RING_PIN_D3 = 3;
  39.  
  40. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  41. const uint8_t tre_SIM800L_RST_PIN_D2 = 2;
  42. const uint8_t tre_SIM800L_DTR_PIN_D4 = 4;
  43.  
  44. /***** DEFINITION OF Software Serial *****/
  45. const uint8_t tre_SIM800L_Serial_PIN_SERIAL_TX_A0 = A0;
  46. const uint8_t tre_SIM800L_Serial_PIN_SERIAL_RX_A1 = A1;
  47. SoftwareSerial tre_SIM800L_Serial(tre_SIM800L_Serial_PIN_SERIAL_RX_A1, tre_SIM800L_Serial_PIN_SERIAL_TX_A0);
  48.  
  49. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  50. /***** used to store raw data *****/
  51. bool tre_SIM800L_RST_PIN_D2_rawData = 0;
  52. bool tre_SIM800L_DTR_PIN_D4_rawData = 0;
  53.  
  54. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  55. /***** used to store data after characteristic curve transformation *****/
  56. float tre_SIM800L_RST_PIN_D2_phyData = 0.0;
  57. float tre_SIM800L_DTR_PIN_D4_phyData = 0.0;
  58.  
  59. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  60. Sim800L GSM(&tre_SIM800L_Serial, tre_SIM800L_RST_PIN_D2, tre_SIM800L_DTR_PIN_D4, tre_SIM800L_RING_PIN_D3);
  61.  
  62. void setup(void) {
  63.   // Initialize serial communication for debugging
  64.   Serial.begin(9600);
  65.  
  66.   // Set pin modes
  67.   pinMode(tre_SIM800L_RING_PIN_D3, INPUT_PULLUP);
  68.   pinMode(tre_SIM800L_RST_PIN_D2, OUTPUT);
  69.   pinMode(tre_SIM800L_DTR_PIN_D4, OUTPUT);
  70.  
  71.   // Initialize the software serial for GSM communication
  72.   tre_SIM800L_Serial.begin(9600);
  73.  
  74.   // Initialize the GSM module
  75.   GSM.begin(4800);
  76.  
  77.   // Set minimum functionality mode
  78.   if (!GSM.setFunctionalityMode(0)) Serial.println("ERROR");
  79.   else Serial.println("Minimum functionality");
  80.  
  81.   Serial.print("Functionality mode: ");
  82.   Serial.println(GSM.getFunctionalityMode());
  83.   delay(5000);
  84.  
  85.   // Set full functionality mode
  86.   if (!GSM.setFunctionalityMode(1)) Serial.println("ERROR");
  87.   else Serial.println("Full functionality");
  88.  
  89.   Serial.print("Functionality mode: ");
  90.   Serial.println(GSM.getFunctionalityMode());
  91.   delay(5000);
  92.  
  93.   // Set flight mode (disable RF function)
  94.   if (!GSM.setFunctionalityMode(4)) Serial.println("ERROR");
  95.   else Serial.println("Flight mode (disable RF function)");
  96.  
  97.   Serial.print("Functionality mode: ");
  98.   Serial.println(GSM.getFunctionalityMode());
  99.   delay(5000);
  100. }
  101.  
  102. void loop(void) {
  103.   // Refresh output data
  104.   updateOutputs();
  105.  
  106.   // Check for incoming calls via the RING pin
  107.   if (digitalRead(tre_SIM800L_RING_PIN_D3) == LOW) {
  108.     Serial.println("Incoming call detected!");
  109.     // Handle the incoming call as needed
  110.   }
  111. }
  112.  
  113. void updateOutputs() {
  114.   // Update the output pins with the raw data
  115.   digitalWrite(tre_SIM800L_RST_PIN_D2, tre_SIM800L_RST_PIN_D2_rawData);
  116.   digitalWrite(tre_SIM800L_DTR_PIN_D4, tre_SIM800L_DTR_PIN_D4_rawData);
  117. }
  118.  
  119. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement