Advertisement
microrobotics

800C GSM Module 3.3/5V - Compatible

Aug 28th, 2023
2,399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Interfacing the ESP32 with the SIM800C GSM module allows you to communicate over a cellular network. The SIM800C module can be used for sending SMS, making calls, or connecting to the internet. In this sample, I'll demonstrate a simple application that sends an SMS message.
  3.  
  4. Components:
  5. ESP32 development board
  6. SIM800C GSM module
  7. SIM card with active cellular service
  8. Connections:
  9. Connect the VCC of the SIM800C to a 4.2V power supply (or as recommended by the module you have). Make sure the power supply can provide around 2A current, especially during transmission.
  10. Connect GND of the SIM800C to the GND of the ESP32.
  11. Connect the TX pin of the SIM800C to the RX pin (e.g., GPIO 16) of the ESP32.
  12. Connect the RX pin of the SIM800C to the TX pin (e.g., GPIO 17) of the ESP32.
  13.  
  14. Software:
  15. Install the required library for handling AT commands:
  16. TinyGSM: https://github.com/vshymanskyy/TinyGSM
  17.  
  18. Make sure to:
  19.  
  20. Replace the phone_number with the recipient's phone number.
  21. Adjust the sms_text to your desired message.
  22. If your SIM card has a PIN, use modem.simUnlock("yourPIN"); to unlock it.
  23. This is a basic example. The SIM800C module supports a wide range of functionalities that can be leveraged using AT commands and the TinyGSM library. Make sure to refer to the documentation for more advanced use cases.
  24. */
  25.  
  26. #include <TinyGsmClient.h>
  27. #include <HardwareSerial.h>
  28.  
  29. #define MODEM_RX     16
  30. #define MODEM_TX     17
  31.  
  32. // Create an instance of the TinyGSM object
  33. TinyGsm modem(Serial2);
  34.  
  35. // Phone number and SMS text
  36. const char phone_number[] = "+1234567890";  // Replace with your phone number
  37. const char sms_text[] = "Hello from ESP32 and SIM800C!";
  38.  
  39. void setup() {
  40.   Serial.begin(115200);
  41.   delay(10);
  42.  
  43.   // Start communication with the GSM module
  44.   Serial2.begin(9600, SERIAL_8N1, MODEM_RX, MODEM_TX);
  45.   delay(3000);
  46.  
  47.   Serial.println("Initializing modem...");
  48.   modem.restart();
  49.  
  50.   String modemInfo = modem.getModemInfo();
  51.   Serial.println("Modem Info: " + modemInfo);
  52.  
  53.   // Unlock your SIM card with a PIN if needed
  54.   // modem.simUnlock("yourPIN");
  55.  
  56.   sendSMS();
  57. }
  58.  
  59. void sendSMS() {
  60.   Serial.println("Sending SMS...");
  61.  
  62.   // Send the SMS
  63.   bool res = modem.sendSMS(phone_number, sms_text);
  64.  
  65.   if (res) {
  66.     Serial.println("SMS sent successfully!");
  67.   } else {
  68.     Serial.println("Failed to send SMS.");
  69.   }
  70. }
  71.  
  72. void loop() {
  73.   // Nothing to do here
  74. }
  75.  
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement