nrf24l01 and gsm sim800l not working on arduino nano

Hello! Good day, I would like to ask some help for my program code regarding the problem of nrf24l01 and sim800l. Hoping you could help me finish my degree this year coz this is for my year-end project code :’( :’( . Been troubleshooting and searching the code for about a month already and don’t have enough sleep for this. I have the code below

#include <Sleep_n0m1.h>
#include <Time.h>
#include <TinyGPS++.h> // Include TinyGPS++ library
#include <SoftwareSerial.h> // Include software serial library
#include <Sim800l.h>
#define SIM800_Send 2
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(7, 8 );
TinyGPSPlus gps;
#define S_RX 3 // Define software serial RX pin
#define S_TX 4 // Define software serial TX pin
SoftwareSerial mySerial(10,11);
SoftwareSerial SoftSerial(S_RX, S_TX); // Configure SoftSerial library

char incomingByte;
String inputString;
long previousMillis = 0;
long interval = 1000;
int green= 9;
int red= 13;
int buzzer=12;
int i = 0;
int x = 0;
const byte rxAddr[6] = “00001”;
String content = “”;
char text;

void setup() {
Serial.begin(9600);
SoftSerial.begin(9600);
while (!Serial);
Serial.begin(9600);
pinMode(A0,OUTPUT); //tap indicator
pinMode(A2,INPUT);
pinMode(green,OUTPUT);
pinMode(red,OUTPUT);
pinMode(buzzer, OUTPUT);
digitalWrite(buzzer,HIGH);
pinMode(SIM800_Send,INPUT);
radio.begin();
mySerial.begin(9600);
while(!mySerial.available()){
mySerial.println(“AT”);
delay(1000);
Serial.println(“Connecting…”);
}
Serial.println(“Connected!”);
mySerial.println(“AT+CMGF=1”); //Set SMS to Text Mode
delay(1000);
mySerial.println(“AT+CNMI=1,2,0,0,0”); //Procedure to handle newly arrived messages(command name in text: new message indications to TE)
delay(1000);
mySerial.println(“AT+CMGL=“REC UNREAD””);
delay(500);
}

void loop() {
nrf();
tracking();
battery();
}

void tracking(){
if(i == 0){
digitalWrite(buzzer,HIGH);
mySerial.begin(9600);
while(mySerial.available()){ //if there was a text received
delay(100);
// Serial Buffer
while(mySerial.available()){
incomingByte = mySerial.read(); // the GSM reads the character
inputString += incomingByte; //if the incoming string was a new line
}
delay(10);
Serial.println(inputString);
inputString.toUpperCase(); // Uppercase the Received Message
if (inputString.indexOf(“OFF”) > -1){
delay(100);
mySerial.end();
delay(1000);
SoftSerial.begin(9600);
delay(1000);
i = 1;
x = 1;
delay(1000);
}
delay(50);
//Delete Messages & Save Memory
if (inputString.indexOf(“OK”) == -1){
mySerial.println(“AT+CMGDA=“DEL ALL””);
delay(1000);}
inputString = “”;
}
}
if(i == 1){
// the buzzer would make a noise if the device receives an off message
if(x==1)
{
digitalWrite(buzzer,LOW);
//delay(120000);
digitalWrite(buzzer,HIGH);
x=0;
}
// finding the coordinates
while(SoftSerial.available()>0) { //if the GPS module was available
if(gps.encode(SoftSerial.read())) { //if the GPS has coordinates
if(gps.location.isValid()) { // checking if it is valid
// printing at the Serial monitor the latitude and the longitude
Serial.print("Latitude = “);
Serial.println(gps.location.lat(), 6);
Serial.print(“Longitude = “);
Serial.println(gps.location.lng(), 6);
digitalWrite(buzzer, LOW);
// sending the latitude and the longitude to the server
delay(1000);
mySerial.write(“AT+CMGF=1\r\n”); // Set the module into text mode
mySerial.write(“AT+CMGS=”+639324497090”\r\n”); // send the text
mySerial.print(gps.location.lat(), 6);
mySerial.print(” ");
mySerial.print(gps.location.lng(), 6);
mySerial.write((char)26); // write all the characters*/
}
}
}
delay(100);
}

}

void nrf(){
radio.openReadingPipe(0, rxAddr);
radio.startListening();
if(radio.available()){
//radio.powerUp();
radio.read(&text, sizeof(text));
//Serial.println(text);
if(text == ‘2’){
content = “F7DB9173”;
Serial.println(content);
for(x=0; x<=1; x++)
{
digitalWrite(green,LOW);
digitalWrite(red,LOW);
digitalWrite(A0,HIGH);
delay(3000);
}
digitalWrite(A0,LOW);
}
else if(text == ‘1’){
content = “E5C1A179”;
Serial.println(content);
digitalWrite(A0,LOW);
delay(100);
}
}

}

void battery(){
int sensorValue = analogRead(A2);
float voltage = sensorValue * (5.0 / 1023.0);
voltage = (voltage/2.5)*5;
//Serial.println(voltage);
unsigned long currentMillis = millis();
if (currentMillis - previousMillis > interval)
{
previousMillis = currentMillis;
if (voltage <= 2.5)
{
Serial.println(“Low Battery”);
digitalWrite(red,HIGH);
digitalWrite(green,LOW);
}
else{
digitalWrite(green,HIGH);
digitalWrite(red,LOW);
//text=“HIGH BATTERY”;
}
}
delay(100);

}

When the radio.begin() initializes, the code for sim800l in the setup

( while(!mySerial.available()){
mySerial.println(“AT”);
delay(1000);
Serial.println(“Connecting…”);
}
Serial.println(“Connected!”);
mySerial.println(“AT+CMGF=1”); //Set SMS to Text Mode
delay(1000);
mySerial.println(“AT+CNMI=1,2,0,0,0”); //Procedure to handle newly arrived messages(command name in text: new message indications to TE)
delay(1000);
mySerial.println(“AT+CMGL=“REC UNREAD””);
delay(500); )

keeps on responding as CONNECTING but when I remove the radio.begin(), it works perfectly fine. Is there a way that you could help me? What I need is the nrf24l01 and sim800l are just to wait for the incoming data. What I did was, when coding separately for nrf and sim800l, they work fine but when they are merged together, it no longer work. Hoping you could help me with my year-end project. I am using only one arduino nano for both of them. Please do respect.

Please correct your post above and add code tags around your code:

[code]

[color=blue]// your code is here[/color]

[/code]

.

It should look like this:

// your code is here

(Also press ctrl-T (PC) or cmd-T (Mac) in the IDE before copying to indent your code properly)

———————

You are using two SoftwareSerial, that's looking for trouble.... from the documentation

The library has the following known limitations:
If using multiple software serial ports, only one can receive data at a time.
Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).
Not all pins on the Leonardo and Micro support change interrupts, so only the following can be used for RX: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
On Arduino or Genuino 101 the current maximum RX speed is 57600bps
On Arduino or Genuino 101 RX doesn't work on Pin 13
If your project requires simultaneous data flows, see Paul Stoffregen's AltSoftSerial library. AltSoftSerial overcomes a number of other issues with the core SoftwareSerial, but has it's own limitations. Refer to the AltSoftSerial site for more information.

———————

Best would be to upgrade to an Arduino with more Hardware Serial Ports and/or built in GSM capability

I actually don't have issue with the two SoftSerial coz the GPS SoftSerial is not active unless it is triggered by the GSM message (OFF). My trouble is just in between the GSM Sim800l and NRF24l01. :frowning: :frowning:

2k16cmp:
I actually don’t have issue with the two SoftSerial coz the GPS SoftSerial is not active unless it is triggered by the GSM message (OFF). My trouble is just in between the GSM Sim800l and NRF24l01. :frowning: :frowning:

You mean the GPS is not powered? since you begin() the SoftwareSerial(), if your GPS is “talking” to your arduino (likely sending sentences every second?) then your SoftwareSerial will be active in the background

The GPS is also powered Sir, the GPS is just on standy. I really don't have issue with the two Software Serial coz I have already tested it and it's perfectly working fine. My only concern is when the NRF module initializes the GSM cannot establish connection and keeps on responding on the Serial as CONNECTING :frowning: :frowning:

Also, when the GSM will receive a message "OFF" it will end its Software Serial then begin the Software Serial for the GPS. I have made a good logic conditioning between the two that's why the two Software Serial is working fine.

havent read the code because no code tag... fix it please

how are things powered?

It’s working already, I just figured out something about the ICSP pins are just the same with the designated digital pins of the arduino and I found out that I am using some of the digital pins designated for the SPI as the Software Serial. So what I did was change the Software Serial pins and modify the library I am using for the Software Serial pin.