Untitled
unknown
c_cpp
10 months ago
1.3 kB
17
Indexable
#include <HardwareSerial.h>
// Initialize HardwareSerial for Serial2 (RX2, TX2)
HardwareSerial sim800(2); // Use Serial2
void setup() {
Serial.begin(115200); // Serial monitor communication
sim800.begin(9600, SERIAL_8N1, 16, 17); // RX2 (GPIO16), TX2 (GPIO17)
delay(2000); // Wait for the SIM800L to initialize
Serial.println("Testing SIM800L...");
// Send AT command to SIM800L and check if it responds
sim800.println("AT");
delay(1000); // Wait for response
// Check if SIM800L sends a response
while (sim800.available()) {
char c = sim800.read();
Serial.write(c); // Print response to Serial Monitor
}
// Check if SIM800L is registered to the network
sim800.println("AT+CREG?");
delay(1000); // Wait for response
while (sim800.available()) {
char c = sim800.read();
Serial.write(c); // Print network registration status to Serial Monitor
}
// Send a test SMS
sim800.println("AT+CMGF=1"); // Set SMS text mode
delay(1000);
sim800.println("AT+CMGS=\"+880 1977351352\""); // Replace with your phone number
delay(1000);
sim800.print("Hello, this is a test message from SIM800L!"); // Message content
delay(1000);
sim800.write(26); // Send Ctrl+Z to send SMS
Serial.println("Message Sent !");
}
void loop() {
// Nothing to do in loop
}
Editor is loading...
Leave a Comment