pleasedontcode

ESP32 SMS rev_01

Nov 24th, 2025
817
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: ESP32 SMS
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2025-11-25 03:29:32
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Enable remote communication by sending SMS using */
  21.     /* the SIM800L module, ensuring proper pin */
  22.     /* configurations and serial communication setup with */
  23.     /* the ESP32 DevKit V1. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26.  
  27. /* START CODE */
  28.  
  29. // Full and Final code implementing SMS send functionality for ESP32 with SIM800L as per System Requirement 1
  30.  
  31. #include <SoftwareSerial.h> // https://github.com/plerup/espsoftwareserial
  32. #include <Sim800L.h>          // https://github.com/vittorioexp/Sim800L-Arduino-Library-revised
  33. #include <ESP32Servo.h>       // https://github.com/madhephaestus/ESP32Servo
  34.  
  35. // Define pins for SoftwareSerial and SIM800L
  36. const uint8_t RX_PIN = 13;     // RX pin for SoftwareSerial
  37. const uint8_t TX_PIN = 4;      // TX pin for SoftwareSerial
  38. const uint8_t RST_PIN = 14;    // Reset pin for SIM800L
  39. const uint8_t RING_PIN = 16;   // Ring Detection pin (if needed)
  40. // Instantiate SoftwareSerial for SIM800L communication
  41. SoftwareSerial sim800Serial(RX_PIN, TX_PIN);
  42. // Instantiate SIM800L object
  43. Sim800L sim800(sim800Serial);
  44.  
  45. // Function prototypes
  46. void sendSms(const char* number, const char* text);
  47. // Variable to track system state
  48. bool smsSent = false;
  49.  
  50. void setup() {
  51.   // Initialize serial for debugging
  52.   Serial.begin(115200);
  53.   // Initialize SIM800L serial communication
  54.   sim800Serial.begin(9600); // Baud rate for SIM800L
  55.   // Initialize SIM800L with reset pin
  56.   pinMode(RST_PIN, OUTPUT);
  57.   digitalWrite(RST_PIN, HIGH); // Keep SIM800L out of reset
  58.   delay(1000); // Wait for stabilization
  59.   // Optional: Reset SIM800L
  60.   digitalWrite(RST_PIN, LOW);
  61.   delay(1000);
  62.   digitalWrite(RST_PIN, HIGH);
  63.   delay(2000); // Wait for module to initialize
  64.  
  65.   Serial.println("Initializing SIM800L...");
  66.   // Basic check
  67.   if (sim800.getProductInfo() != "") {
  68.     Serial.println("SIM800L Initialized.");
  69.   } else {
  70.     Serial.println("Failed to initialize SIM800L.");
  71.   }
  72.   // Send initial SMS to a number
  73.   sendSms("+1234567890", "Hello from ESP32! This is a system-generated message.");
  74.   // Mark that SMS has been sent
  75.   smsSent = true;
  76. }
  77.  
  78. void loop() {
  79.   // Keep the loop alive or implement additional communication if needed
  80.   // For demonstration, do nothing
  81.   if (smsSent) {
  82.     // Do something or repeat
  83.   }
  84. }
  85.  
  86. // Function to send SMS
  87. void sendSms(const char* number, const char* text) {
  88.   Serial.print("Sending SMS to: ");
  89.   Serial.println(number);
  90.   bool success = sim800.sendSms(number, text);
  91.   if (success) {
  92.     Serial.println("SMS sent successfully.");
  93.   } else {
  94.     Serial.println("Failed to send SMS.");
  95.   }
  96. }
  97.  
  98. /* END CODE */
  99.  
Advertisement
Add Comment
Please, Sign In to add comment