RX pin is connected to Arduino pin 3
TX pin is connected to Arduino pin 2
GPS module
Rx is connected to Arduino TX
TX is connected to Arduino RX
and this is the code;
#include <TinyGPS++.h>
TinyGPSPlus gps;
double latitude, longitude;
#include <SoftwareSerial.h>
SoftwareSerial SIM800L(2, 3);
String response;
int lastStringLength = response.length();
String link;
void setup() {
Serial.begin(9600);
Serial.println("GPS Mulai");
SIM800L.begin(9600);
SIM800L.println("AT+CMGF=1");
Serial.println("SIM800L started at 9600");
delay(1000);
Serial.println("Setup Complete! SIM800L is Ready!");
SIM800L.println("AT+CNMI=2,2,0,0,0");
}
void loop() {
if (SIM800L.available()>0){
response = SIM800L.readStringUntil('\n');
}
if(lastStringLength != response.length()){
GPS();
//Perintah ON
if(response.indexOf("ON") == 4){
SIM800L.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
SIM800L.println("AT+CMGS=\"xxxxxxxxx\"\r"); // mobile number
delay(1000);
SIM800L.println(link);// The SMS text you want to send
delay(100);
SIM800L.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
}
}
void GPS(){
if(Serial.available()) {
gps.encode(Serial.read());
}
if(gps.location.isUpdated()) {
latitude = gps.location.lat();
longitude = gps.location.lng();
link = "www.google.com/maps/place/" + String(latitude, 6) + "," + String(longitude, 6) ;
Serial.println(link);
}
}
the code works perfectly on the Arduino. But i'd like to use a STANDALONE Atmega328p microcontroller. can anyone please help me to makes changes to the code to function with the atmega controller only.
What changes? A standalone MCU is no different. At least, mine isn't. What clock crystal are you using?
Also, you have posted code without using code tags. The code tags make the code look
like this
when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons. The "Code: [Select]" feature allows someone to select the entire sketch so it can be easily copied and pasted into the IDE for testing.
If you have already posted without using code tags, open your message and select "modify" from the pull down menu labelled, "More", at the lower right corner of the message. Highlight your code by selecting it (it turns blue), and then click on the "</>" icon at the upper left hand corner. Click on the "Save" button. Code tags can also be inserted manually in the forum text using the code and /code metatags.
The current code works well with the UART pins (pins 0 and 1). But i would like to change the GPS on the Arduino with any other two pins, so it wont be using the UART pins (the RX and TX pins).
this is the code with the Software Serial for the Gps connected to pins 4 and 5 on the Arduino. but nothing shows on serial monitor. if i remove the software serial commands, and connect GPS rx and tx to the arduino pins 0 and 1 it works.
#include <TinyGPS++.h>
TinyGPSPlus gps;
double latitude, longitude;
static const uint32_t GPSBaud = 9600;
#include <SoftwareSerial.h>
SoftwareSerial SIM800L(2, 3);
SoftwareSerial ss(4,5);
String response;
int lastStringLength = response.length();
String link;
void setup() {
Serial.begin(9600);
ss.begin(GPSBaud);
Serial.begin(9600);
Serial.println("GPS Mulai");
SIM800L.begin(9600);
SIM800L.println("AT+CMGF=1");
Serial.println("SIM800L started at 9600");
delay(1000);
Serial.println("Setup Complete! SIM800L is Ready!");
SIM800L.println("AT+CNMI=2,2,0,0,0");
}
void loop() {
if (SIM800L.available()>0){
response = SIM800L.readStringUntil('\n');
}
if(lastStringLength != response.length()){
GPS();
//Perintah ON
if(response.indexOf("ON") == 4){
SIM800L.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
SIM800L.println("AT+CMGS=\"0670322888\"\r"); // Replace x with mobile number
delay(1000);
SIM800L.println(link);// The SMS text you want to send
delay(100);
SIM800L.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
}
}
void GPS(){
while(ss.available()>0) {
gps.encode(ss.read());
}
if(gps.location.isUpdated()) {
latitude = gps.location.lat();
longitude = gps.location.lng();
link = "www.google.com/maps/place/" + String(latitude, 6) + "," + String(longitude, 6) ;
Serial.println(link);
}
Two instances of SoftwareSerial is the problem because they share the same buffer. I have yet to see a successful project that uses two instances although in theory you can use the listen() function to activate each interface when it is required