Well, I am making a device, which has to receive SMS and print the text using am LCD display. Now I have code that can receive SMS and store it into a string variable using serial connection. Here is my code:
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; //LCD pins
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
String Arsp, Grsp;
SoftwareSerial gsm(6,7); // RX, TX
void setup() {
Serial.begin(9600);
Serial.println("Testing GSM SIM800L");
gsm.begin(9600);
gsm.println("AT"); //checking
delay(1000);
gsm.println("AT+CMGF=1"); //Set to Text mode
delay(1000);
gsm.println("AT+CNMI=1, 2, 0, 0, 0"); //Set to notification for new message, New message indication
lcd.begin(16, 2);
}
void loop() {
if(gsm.available()) {
//Check if GSM Send any data
Grsp = gsm.readString(); //Read data received from SIM800L GSM Module
lcd.clear(); //Clear LCD Screen
lcd.setCursor(0,0); //Set LCD cursor to First line, first row
for(int i = 0; i<=100; i++) {
//Print received string character by character
lcd.clear();
lcd.setCursor(0,0);
lcd.print(Grsp); //Print string which received from GSM (sms, sender, sms index, receive time, etc)
lcd.print(" ");
lcd.print(i); //Print the string index
delay(500);
}
}
}
When my Arduino Uno is connected to PC and the Arduino serial monitor is already open, it prints correctly this text received from GSM
" +CMT: "+995599093230","","18/01/05,16:29:57+16" 0.
In this case I sent a message with text "0". When I disconnect the USB and connect my Arduino Uno to 9V power supply and send the same message text it prints:
" +CMTI: "ME", "+995598403536", 40)
In this case 40 is the index of the message received. I want to get the whole string as in the first case when the USB was connected.
I using Arduino GND and 5V to power the SIM800L. What I am doing wrong? Is this due to incorrect serial connection or incorrect code error?