Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- The SIM808 is a GSM/GPRS/GPS module that can be used for cellular communication and GPS tracking. In this example, I'll provide you with an Arduino code to test the all-round functionality of the SIM808 module by sending various AT commands and receiving responses. The code will cover basic operations such as checking the module status, registering to the network, getting network information, sending an SMS, and getting GPS data. Note that this code assumes you are using an Arduino Uno or a similar board.
- First, connect the SIM808 module to the Arduino as follows:
- Vcc to 5V
- GND to GND
- RX (SIM808) to TX (Arduino)
- TX (SIM808) to RX (Arduino)
- Upload this code to your Arduino and open the Serial Monitor. The Arduino will send various AT commands to the SIM808 module and display the received responses in the Serial Monitor. This will help you test the all-round functionality of the SIM808 module.
- Make sure you have a proper power supply for the SIM808 module, as it may draw a high current during operation. Also, ensure you have a GSM SIM card inserted into the module and that it is registered with the network.
- When running the test, keep in mind that the GPS functionality may not work indoors or in an area with poor signal reception. Make sure the SIM808 has a clear view of the sky to receive GPS signals. Additionally, it may take a few minutes for the SIM808 module to get a GPS fix after it has been powered on.
- This example code should help you test the basic functionalities of the SIM808 module, including GSM communication and GPS tracking. You can modify the code or add more AT commands to test other functionalities provided by the SIM808 module. Please refer to the SIM808 AT Command Set documentation for more information on the available AT commands and their usage.
- */
- // SIM808 GSM/GPRS/GPS Module
- // Example code for Arduino
- #include <SoftwareSerial.h>
- const int simRxPin = 10; // Connect the RX pin of the SIM808 to Digital Pin 10
- const int simTxPin = 11; // Connect the TX pin of the SIM808 to Digital Pin 11
- SoftwareSerial simSerial(simRxPin, simTxPin); // Create a SoftwareSerial object for communication with the SIM808
- void setup() {
- Serial.begin(9600); // Initialize the serial communication for debugging
- simSerial.begin(9600); // Initialize the software serial communication with the SIM808
- delay(5000); // Wait for the SIM808 to power on and initialize
- Serial.println("SIM808 Test");
- }
- void loop() {
- // Test AT command
- sendATCommand("AT");
- // Check SIM card status
- sendATCommand("AT+CPIN?");
- // Query network registration status
- sendATCommand("AT+CREG?");
- // Get network information
- sendATCommand("AT+COPS?");
- // Send SMS
- sendATCommand("AT+CMGF=1"); // Set SMS mode to text
- sendATCommand("AT+CMGS=\"+1234567890\""); // Replace +1234567890 with the phone number to send the SMS to
- simSerial.print("Hello, World!"); // The SMS text
- simSerial.write(0x1A); // Send Ctrl+Z (0x1A) to indicate the end of the SMS text
- // Enable GPS
- sendATCommand("AT+CGPSPWR=1"); // Power on the GPS
- sendATCommand("AT+CGPSRST=0"); // Set GPS to standalone mode
- sendATCommand("AT+CGPSINF=0"); // Get GPS data
- delay(30000); // Wait for 30 seconds before running the test again
- }
- void sendATCommand(const char *command) {
- // Send an AT command to the SIM808
- simSerial.println(command);
- // Wait for a response from the SIM808
- while (!simSerial.available()) {
- delay(100);
- }
- // Read the response from the SIM808
- String response = simSerial.readStringUntil('\n');
- // Print the command and response to the Serial Monitor
- Serial.print("Command: ");
- Serial.println(command);
- Serial.print("Response: ");
- Serial.println(response);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement