Advertisement
pleasedontcode

"SMS Control" rev_01

Jul 12th, 2024
152
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: "SMS Control"
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-07-13 01:08:28
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Connecting and disconnecting the power supply, */
  21.     /* when the "SIMcard" module receives the message */
  22.     /* "Soldier: connected", command the "Soldier" module */
  23.     /* to turn on the power, and if the "SIMcard" module */
  24.     /* receives the "Soldier off" message, to the */
  25.     /* "Soldier" */
  26. /****** END SYSTEM REQUIREMENTS *****/
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <SoftwareSerial.h>
  30. #include <Sim800L.h> // https://github.com/vittorioexp/Sim800L-Arduino-Library-revised
  31. #include <Relay.h>   // https://github.com/rafaelnsantos/Relay
  32.  
  33. /****** FUNCTION PROTOTYPES *****/
  34. void setup(void);
  35. void loop(void);
  36. void updateOutputs(void);
  37. void handleSms(void);
  38.  
  39. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  40. const uint8_t simcard_SIM800L_RING_PIN_D3 = 3;
  41.  
  42. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  43. const uint8_t simcard_SIM800L_RST_PIN_D2 = 2;
  44. const uint8_t simcard_SIM800L_DTR_PIN_D4 = 4;
  45. const uint8_t soldier_RelayModule_Signal_PIN_D5 = 5;
  46.  
  47. /***** DEFINITION OF Software Serial *****/
  48. const uint8_t simcard_SIM800L_Serial_PIN_SERIAL_TX_A0 = A0;
  49. const uint8_t simcard_SIM800L_Serial_PIN_SERIAL_RX_A1 = A1;
  50. SoftwareSerial simcard_SIM800L_Serial(simcard_SIM800L_Serial_PIN_SERIAL_RX_A1, simcard_SIM800L_Serial_PIN_SERIAL_TX_A0);
  51.  
  52. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  53. /***** used to store raw data *****/
  54. bool simcard_SIM800L_RST_PIN_D2_rawData = 0;
  55. bool simcard_SIM800L_DTR_PIN_D4_rawData = 0;
  56. bool soldier_RelayModule_Signal_PIN_D5_rawData = 0;
  57.  
  58. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  59. /***** used to store data after characteristic curve transformation *****/
  60. float simcard_SIM800L_RST_PIN_D2_phyData = 0.0;
  61. float simcard_SIM800L_DTR_PIN_D4_phyData = 0.0;
  62. float soldier_RelayModule_Signal_PIN_D5_phyData = 0.0;
  63.  
  64. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  65. Sim800L GSM(simcard_SIM800L_Serial_PIN_SERIAL_RX_A1, simcard_SIM800L_Serial_PIN_SERIAL_TX_A0, simcard_SIM800L_RST_PIN_D2); // Initialize SIM800L object
  66. Relay light(soldier_RelayModule_Signal_PIN_D5, true); // Initialize relay on pin 5, Normally Open
  67.  
  68. void setup(void)
  69. {
  70.     // put your setup code here, to run once:
  71.     pinMode(simcard_SIM800L_RING_PIN_D3, INPUT_PULLUP);
  72.  
  73.     pinMode(simcard_SIM800L_RST_PIN_D2, OUTPUT);
  74.     pinMode(simcard_SIM800L_DTR_PIN_D4, OUTPUT);
  75.     pinMode(soldier_RelayModule_Signal_PIN_D5, OUTPUT);
  76.  
  77.     simcard_SIM800L_Serial.begin(9600);
  78.     GSM.begin(9600); // Initialize the GSM module with baud rate 9600
  79.  
  80.     light.begin(); // Initialize the relay pin
  81. }
  82.  
  83. void loop(void)
  84. {
  85.     // put your main code here, to run repeatedly:
  86.     handleSms(); // Check and handle incoming SMS
  87.     updateOutputs(); // Refresh output data
  88. }
  89.  
  90. void updateOutputs()
  91. {
  92.     digitalWrite(simcard_SIM800L_RST_PIN_D2, simcard_SIM800L_RST_PIN_D2_rawData);
  93.     digitalWrite(simcard_SIM800L_DTR_PIN_D4, simcard_SIM800L_DTR_PIN_D4_rawData);
  94.     digitalWrite(soldier_RelayModule_Signal_PIN_D5, soldier_RelayModule_Signal_PIN_D5_rawData);
  95. }
  96.  
  97. void handleSms()
  98. {
  99.     String textSms = GSM.readSms(1); // Read the first SMS
  100.  
  101.     if (textSms.indexOf("OK") != -1 && textSms.length() > 7) { // Check if the message is correct and not empty
  102.         textSms.toUpperCase(); // Convert message to uppercase
  103.  
  104.         if (textSms.indexOf("SOLDIER: CONNECTED") != -1) {
  105.             light.turnOn(); // Turn relay on
  106.             soldier_RelayModule_Signal_PIN_D5_rawData = true;
  107.         } else if (textSms.indexOf("SOLDIER OFF") != -1) {
  108.             light.turnOff(); // Turn relay off
  109.             soldier_RelayModule_Signal_PIN_D5_rawData = false;
  110.         }
  111.  
  112.         GSM.delAllSms(); // Delete all SMS
  113.     }
  114. }
  115.  
  116. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement