Advertisement
pleasedontcode

"GSM Management" rev_18

Jun 13th, 2024
370
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: "GSM Management"
  13.     - Source Code NOT compiled for: Arduino Pro Mini 5V
  14.     - Source Code created on: 2024-06-13 11:04:24
  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. /****** DEFINITION OF LIBRARIES *****/
  28. #include <SoftwareSerial.h>
  29. #include <Sim800L.h> // https://github.com/vittorioexp/Sim800L-Arduino-Library-revised
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34. void updateOutputs(void);
  35.  
  36. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  37. const uint8_t tre_SIM800L_RING_PIN_D3 = 3;
  38.  
  39. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  40. const uint8_t tre_SIM800L_RST_PIN_D2 = 2;
  41. const uint8_t tre_SIM800L_DTR_PIN_D4 = 4;
  42.  
  43. /***** DEFINITION OF Software Serial *****/
  44. const uint8_t tre_SIM800L_Serial_PIN_SERIAL_TX_A0 = A0;
  45. const uint8_t tre_SIM800L_Serial_PIN_SERIAL_RX_A1 = A1;
  46. SoftwareSerial tre_SIM800L_Serial(tre_SIM800L_Serial_PIN_SERIAL_RX_A1, tre_SIM800L_Serial_PIN_SERIAL_TX_A0);
  47.  
  48. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  49. /***** used to store raw data *****/
  50. bool tre_SIM800L_RST_PIN_D2_rawData = 0;
  51. bool tre_SIM800L_DTR_PIN_D4_rawData = 0;
  52.  
  53. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  54. /***** used to store data after characteristic curve transformation *****/
  55. float tre_SIM800L_RST_PIN_D2_phyData = 0.0;
  56. float tre_SIM800L_DTR_PIN_D4_phyData = 0.0;
  57.  
  58. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  59. Sim800L GSM(&tre_SIM800L_Serial, tre_SIM800L_RST_PIN_D2, tre_SIM800L_DTR_PIN_D4, tre_SIM800L_RING_PIN_D3);
  60.  
  61. void setup(void) {
  62.   // Initialize serial communication for debugging
  63.   Serial.begin(9600);
  64.  
  65.   // Set pin modes
  66.   pinMode(tre_SIM800L_RING_PIN_D3, INPUT_PULLUP);
  67.   pinMode(tre_SIM800L_RST_PIN_D2, OUTPUT);
  68.   pinMode(tre_SIM800L_DTR_PIN_D4, OUTPUT);
  69.  
  70.   // Initialize the software serial for GSM communication
  71.   tre_SIM800L_Serial.begin(9600);
  72.  
  73.   // Initialize the GSM module
  74.   GSM.begin(4800);
  75.  
  76.   // Set minimum functionality mode
  77.   if (!GSM.setFunctionalityMode(0)) Serial.println("ERROR");
  78.   else Serial.println("Minimum functionality");
  79.  
  80.   Serial.print("Functionality mode: ");
  81.   Serial.println(GSM.getFunctionalityMode());
  82.   delay(5000);
  83.  
  84.   // Set full functionality mode
  85.   if (!GSM.setFunctionalityMode(1)) Serial.println("ERROR");
  86.   else Serial.println("Full functionality");
  87.  
  88.   Serial.print("Functionality mode: ");
  89.   Serial.println(GSM.getFunctionalityMode());
  90.   delay(5000);
  91.  
  92.   // Set flight mode (disable RF function)
  93.   if (!GSM.setFunctionalityMode(4)) Serial.println("ERROR");
  94.   else Serial.println("Flight mode (disable RF function)");
  95.  
  96.   Serial.print("Functionality mode: ");
  97.   Serial.println(GSM.getFunctionalityMode());
  98.   delay(5000);
  99. }
  100.  
  101. void loop(void) {
  102.   // Refresh output data
  103.   updateOutputs();
  104.  
  105.   // Check for incoming calls via the RING pin
  106.   if (digitalRead(tre_SIM800L_RING_PIN_D3) == LOW) {
  107.     Serial.println("Incoming call detected!");
  108.     // Handle the incoming call as needed
  109.   }
  110. }
  111.  
  112. void updateOutputs() {
  113.   // Update the output pins with the raw data
  114.   digitalWrite(tre_SIM800L_RST_PIN_D2, tre_SIM800L_RST_PIN_D2_rawData);
  115.   digitalWrite(tre_SIM800L_DTR_PIN_D4, tre_SIM800L_DTR_PIN_D4_rawData);
  116. }
  117.  
  118. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement