I'm using Arduino Uno as my microcontroller, but I got a strange behavior. I need to run several function at the same time. One to get GPS and temperature value then send every value to user's phone number when a request received by SIM800L GSM module, and another to display those value on I2C LCD. Everything works fine when my USB port connected to my computer. But when I tried to unplug the USB and using external power source from Li-Po battery I can't get a response from SIM800L module whenever I send a request message.
When I tried to create a separate program (just received a request message and then sent a response by SIM800L) it works fine even though using external power supply (Li-Po battery) without USB port plugged in. Another strange behavior is when I was using both of Li-Po battery and USB port connected then unplugged the USB port it works fine again. But when I unplugged my battery and then plugged it again without USB port connected, SIM800L couldn't send a response. What is wrong ?
This is my full code:
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
#include "DHT.h"
//sms
char ReceivedSms;
short DHT_OK=-1, GPS_OK=-1;
String DataSms;
int _timeout;
String _buffer;
String number = "+62811XXXXXX";
//dht
#define DHTPIN 5
#define DHTTYPE DHT11
LiquidCrystal_I2C lcd(0x27,20,4);
SoftwareSerial sim800l(2,3);
DHT dht(DHTPIN, DHTTYPE);
// The TinyGPS++ object
TinyGPSPlus gps;
void setup()
{
Serial.begin(9600);
sim800l.begin(9600);
dht.begin();
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
_buffer.reserve(50);
ReceiveMode();
}
void loop()
{
displayInfo();
}
void displayInfo()
{
String RSMS;
while(sim800l.available() > 0) {
ReceivedSms = sim800l.read();
RSMS.concat(ReceivedSms);
GPS_OK = RSMS.indexOf("All");
}
if (gps.location.isValid())
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Latitude : ");
lcd.println(gps.location.lat(), 6);
lcd.setCursor(0,1);
lcd.print("Longitude : ");
lcd.println(gps.location.lng(), 6);
delay(5000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Suhu : ");
lcd.println(dht.readTemperature());
lcd.setCursor(0,1);
lcd.print("Kelembaban : ");
lcd.println(dht.readHumidity());
delay(2000);
if(GPS_OK!=-1)
{
String link = "http://www.google.com/maps/place/" + String(gps.location.lat(),6) + "," + String(gps.location.lng(),6);
DataSms = "ALL\nSuhu = "+String(dht.readTemperature(),1)+" C"+" \nKelembaban ="+String(dht.readHumidity(),1)+" %"+" \nMaps = "+link;
SendMessage();
ReceiveMode();
GPS_OK = -1;
}
}
else
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("GPS not found");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Suhu :");
lcd.println(dht.readTemperature());
lcd.setCursor(0,1);
lcd.print("Kelembaban:");
lcd.println(dht.readHumidity());
delay(2000);
if(GPS_OK!=-1)
{
DataSms = "ALL\nSuhu = "+String(dht.readTemperature(),1)+" C"+" \nKelembaban ="+String(dht.readHumidity(),1)+" %"+" \nMaps = Lokasi Tidak Ditemukan";
SendMessage();
ReceiveMode();
GPS_OK = -1;
}
}
}
String _readSerial() {
_timeout = 0;
while (!sim800l.available() && _timeout < 12000 )
{
delay(13);
_timeout++;
}
if (sim800l.available()) {
return sim800l.readString();
}
}
void ReceiveMode() {
sim800l.println("AT");
delay(100);
sim800l.println("AT+CMGF=1");
delay(100);
sim800l.println("AT+CNMI=2,2,0,0,0");
delay(100);
}
void SendMessage()
{
//Serial.println ("Sending Message");
sim800l.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000);
//Serial.println ("Set SMS Number");
sim800l.println("AT+CMGS=\"" + number + "\"\r"); //Mobile phone number to send message
delay(1000);
String SMS = "Hello from 800L...";
sim800l.println(DataSms);
delay(100);
sim800l.println((char)26);// ASCII code of CTRL+Z
delay(1000);
_buffer = _readSerial();
}
Just for your information I'm using Li-Po battery 7.4V 2200mAh
gps.encode(...)
- and anyway, where is your GPS connected? I see no SoftwareSerial for it (which by the way can only listen on ONE interface at a time).