SMS with SIM808 - working code

I have tried multiple codes to get the UNO and the SIM808 to work and I still get no response from the AT Commands and still get Sim808 init error.

Does anyone have a working code and schematic on this? Seems everyone I find is old and does not work for some reason or other.

This is the one I am working with.

#include <DFRobot_SIM808.h>
#include <sim808.h>

#include <SoftwareSerial.h>



#define MESSAGE_LENGHT 160
#define MESSAGE "SMS 01"
#define MESSAGE2 "SMS02"

#define PIN_TX    10
#define PIN_RX    11
#define mySerial Serial //PIN_TX,PIN_RX
#define PHONE_NUMBER "X XXX XXX XXXX"
DFRobot_SIM808 sim808(&mySerial); //Connect PIN_TX,PIN_RX, GND

void setup()
{
mySerial.begin(9600);
Serial.begin(9600);

//---------------- Initialize sim808 module
while(!sim808.init()) {
delay(1000);
Serial.print("Sim808 init error\r\n");
}
delay(3000);
Serial.println("Sim808 init success");
}

void loop()
{

if (Serial.available())
switch(Serial.read())
{
case 's':
SendTextMessage();
break;
case 'n':
SendTextMessage2();
break;

case 'c':
DialVoiceCall();
break;

}
if (mySerial.available())
Serial.write(mySerial.read());
}

void SendTextMessage()
{

delay(3000);
Serial.println("Sending message ...");
sim808.sendSMS(PHONE_NUMBER,MESSAGE);
}

void SendTextMessage2()
{
delay(3000);
Serial.println("Sending message ...");
sim808.sendSMS(PHONE_NUMBER,MESSAGE2);
}

void DialVoiceCall()
{
delay(3000);
Serial.println("Start to call ...");
sim808.callUp(PHONE_NUMBER);

}

Welcome to the forum

Your topic was MOVED to its current forum category which is more appropriate than the original as it has nothing to do with Installation and Troubleshooting of the IDE

How is the SIM808 module powered and at what voltage ?

can you run a simple program to send AT commands to the SIM808 and check the response
for an example program see post sim808l-2-0-problem

The AT Commands come back with garbled text that makes no sense at all.

The SIM808 is powered with 9V battery.

SSRay

i8itscesSending message ...

AT+CMGF=1

O OOAT

ATK

AK

KAT

KKKT

T T T

could be problems with SoftwareSerial or power supply or noise
if you power the UNO and SIM808 from a USB is it OK?

I have used this to check AT commands on a SIM800

// SIM800l AltSoftSerial test 

#include <AltSoftSerial.h>
#include <SPI.h>
#include <Wire.h>

// Mega SIM800l  test
//SIM800L 5V  POWER to Mega 5V
//SIM800L GND POWER to Mega GND
//SIM800L TXD to Mega RX pin 48
//SIM800L RXD to Mega TX pin 46
//SIM800L VDD to Mega 5V

//SIM800L UART TTL GND and RST not connected

//SIM800L TXD to UNO RX pin 8
//SIM800L RXD to UNO TX pin 9

// taking the RST pin to GND for a couple of seconds which will reset the device

//  RS232 shield 
//   RS232 TXD to UNO pin 9
//  =[===RS232 RXD to UNO pin 8
AltSoftSerial simSerial;

void setup() {
  Serial.begin(115200);
  Serial.println("AltSoftSerial test");
  //Begin serial communication with Arduino and SIM800L
  simSerial.begin(9600);
  Serial.println("SIM module intialized");
}

void loop() {
  if (Serial.available()) {
    char command = Serial.read();
    //Serial.println(command);
    simSerial.print(command);
  }
  while (simSerial.available()) {
    char reponse = simSerial.read();
    Serial.print(reponse);
  }
}

connected to a UNO pins 8 and 9 it displays

AT
OK
AT+CGMI
SIMCOM_Ltd
OK
AT+CGMM
SIMCOM_SIM800L

looking at the sim808 Hardware design manual it states " User can power on the SIM808 by pulling down the PWRKEY for at least 1 second"
what SIM808 module is it?

Its the SIM808 EVB-V3. 2.4 Bluetooth, GPS and GSM.

This one is responding that the sim has initialized but I havent a clue where to put phone numbers in.. I am very new, and the code is still escaping me a bit.

#include <DFRobot_SIM808.h>
#include <sim808.h>

#include <SoftwareSerial.h>


#define MESSAGE_LENGTH 160

char message[MESSAGE_LENGTH];
int messageIndex = 0;
char MESSAGE[300];
char lat[12];
char lon[12];
char wspeed[12];

char phone[16];
char datetime[24];

#define PIN_TX    3
#define PIN_RX    2
SoftwareSerial mySerial(PIN_TX,PIN_RX);
DFRobot_SIM808 sim808(&mySerial);//Connect RX,TX,PWR,

void setup()
{
  mySerial.begin(9600);
  Serial.begin(9600);

  //******** Initialize sim808 module *************
  while(!sim808.init())
  {
      Serial.print("Sim808 init error\r\n");
      delay(1000);
  }
  delay(3000);

  if( sim808.attachGPS())
      Serial.println("Open the GPS power success");
  else 
      Serial.println("Open the GPS power failure");
      
  Serial.println("Init Success, please send SMS message to me!");
}

void loop()
{
  //*********** Detecting unread SMS ************************
   messageIndex = sim808.isSMSunread();

   //*********** At least, there is one UNREAD SMS ***********
   if (messageIndex > 0)
   { 
      Serial.print("messageIndex: ");
      Serial.println(messageIndex);
      
      sim808.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);
                 
      //***********In order not to full SIM Memory, is better to delete it**********
      sim808.deleteSMS(messageIndex);
      Serial.print("From number: ");
      Serial.println(phone);  
      Serial.print("Datetime: ");
      Serial.println(datetime);        
      Serial.print("Recieved Message: ");
      Serial.println(message); 

    while(!sim808.getGPS())
    {
      
    }

   
      Serial.print(sim808.GPSdata.year);
      Serial.print("/");
      Serial.print(sim808.GPSdata.month);
      Serial.print("/");
      Serial.print(sim808.GPSdata.day);
      Serial.print(" ");
      Serial.print(sim808.GPSdata.hour);
      Serial.print(":");
      Serial.print(sim808.GPSdata.minute);
      Serial.print(":");
      Serial.print(sim808.GPSdata.second);
      Serial.print(":");
      Serial.println(sim808.GPSdata.centisecond);
      Serial.print("latitude :");
      Serial.println(sim808.GPSdata.lat);
      Serial.print("longitude :");
      Serial.println(sim808.GPSdata.lon);
      Serial.print("speed_kph :");
      Serial.println(sim808.GPSdata.speed_kph);
      Serial.print("heading :");
      Serial.println(sim808.GPSdata.heading);
      Serial.println();
  
      float la = sim808.GPSdata.lat;
      float lo = sim808.GPSdata.lon;
      float ws = sim808.GPSdata.speed_kph;
  
      dtostrf(la, 0, 2, lat); //put float value of la into char array of lat. 6 = number of digits before decimal sign. 2 = number of digits after the decimal sign.
      dtostrf(lo, 0, 2, lon); //put float value of lo into char array of lon
      dtostrf(ws, 0, 2, wspeed);  //put float value of ws into char array of wspeed
    
      //sprintf(MESSAGE, "Latitude : %s\nLongitude : %s\nWind Speed : %s kph\nMy Module Is Working. Try With This Link.\nhttp://www.latlong.net/Show-Latitude-Longitude.html\nhttp://maps.google.com/maps?q=%s,%s\n", lat, lon, wspeed, lat, lon);
      sprintf(MESSAGE, "Latitude : %s\nLongitude : %s\nWind Speed : %s kph\nMy Module Is Working.\nhttp://maps.google.com/maps?q=%s,%s\n", lat, lon, wspeed, lat, lon);
      
       Serial.println("Sim808 init success");
       Serial.println("Start to send message ...");
       Serial.println(MESSAGE);
       Serial.println(phone);
       sim808.sendSMS(phone,MESSAGE);
      //************* Turn off the GPS power ************
      //sim808.detachGPS();
      
   }
}

the SIM808 appears to use 3.3V logic so don't connect directly to a UNO which uses 5V logic
have you seen https:/basics-project-053d-sim808-gsm-gprs-gps-bluetooth-evolution-board-evb-v32-at-acoptexcom
it shows a potential divider on the UNO Tx to SIM808 Rx line

you need to read the library documentation
I tend to use AT commands directly, e.g.send a SMS text
AT+CMGS=”+TTTTT” where TTTTT is the destination number
e.g. AT+CMGS="+447967123456" you must use International Dialling code format

My goal is to make my own alarm system for my shop that will text me, l am very new to this. That last link you sent looks promising, I will follow the instructions and see if that works.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.