How do I run three loops at same time to scan RFID and GPS data and send sms

I have build a real time vehicle tracking system in which I want to scan continuously gps location using sim900 shield module which send data to mysql database where I will fetch for futher operation and also i am using 2 witch when i press it send sms to pre define numbers. if any person scan his RFID card at RC522 Module I need to pause gps tracking and http connection of data sending and give highest priority to rfid scanner but when card is not present it start gps coordinate and send over the server if I place a card to scan it will not scan the card till http connection shut that may lead error to scan card and send to card detail to server.

How do I solve this issue with arduino Mega 2560 + RC522 +GSM sim 900module and gps neo 6m.
I want to give highest priority to rfid scanner as well data logging in background when card is not present but if card reaches the sensor immideatley hold the http and gps operation while card process is going on.

Please help I am new in arduino.

Here is my code in below

testing_project.ino (16.6 KB)

What are you requesting Project Guidance in the section for IDE Installation & Troubleshooting?

Being a single thread processor, it can only do one thing at a time. If the interruption or processing time is too long for anyone of the three elements, then it may require being placed on its own processor. Based on the above description, use a Arduino Nano or Mini to service the RFID scanner, then flag the MEGA there is data available. There may be a delay in processing the data, but the data from the RFID scanner would not be missed. Since you have already selected the MEGA, it has three hardware serial ports, are either Serial1 or Serial 2 available?

i am already using three serial communication serial2 for gps and serial for rfid hardware serial for GSM
Project have three feature first scan the rfid card and send to web server for identification ,second get gps coordinate continuous for real time tracking of his vehicle and send lat lng to same web server.
and third one is when i press button it will send sms notification

user can scan his card any time while vehicle running or stop thats mean I want rfid scanner active all time and once the card scanned that detail send to web server database through http get request connection but problem occurs of gps scanner because its continuously running and data sending to t web server mode Now when user scan his card it will not scanned till gps and http complete his loop once they complete the card get scanned its very long process to hold the card at reader.and also same procedure is repeating for switch button.

What I want, RFID scanning and gps location sender functions run in parallel way as rfid reader alway active even gps sending data in background mode live service. I have two priority for this project sending gps coordinate continuously as well as scan rfid any moment that card is placed.

all problem occur due to http connection once gps is in the function of htttp it take time and not scan RFID.

Can I run both rfid scan and gps and switch acquisition process simultaneously rather htttp connection work in background.

There is no "work in the background" as there is no background on a single thread processor.

Since all Serial is occupied, use I2C to connect multiple processors with each single thread processor doing one task and feed them back to the master/host.

so what should i do for this in your opinion please help i am new in arduino

Can't look at your code now; Useful links - check here for reference posts / tutorials - Programming Questions - Arduino Forum has a few useful links under 'general design's. I think that number 2..5 can be if help.

all problem occur due to http connection

You will have to make that function "non-blocking".

Lines like this

    delay(2000);

are a serious problem. Can you guess what the processor does during delay()?

non blocking function like i need to put some delay on looping function

?

umerAbbasi11:
non blocking function like i need to put some delay on looping function

No, you need to get rid of delays. Adding to the above list of stuff to read: Using millis() for timing. A beginners guide

The demo Several Things at a Time illustrates the use of millis() to manage timing without blocking. It may help with understanding the technique.

Note also how each function runs very briefly and returns to loop() so the next one can be called. Long running processes are achieved a tiny piece at a time. And there may be dozens of calls to some functions before it is actually time for anything to happen.

And have a look at the examples in Serial Input Basics - simple reliable non-blocking ways to receive data.

...R

Robin sir ! if you dont mind could you modify my code for me because i am confused where i start to do that task ..... my code file is in above section.

umerAbbasi11:
Robin sir ! if you dont mind could you modify my code for me because i am confused where i start to do that task ..... my code file is in above section.

I will try to look at it later tonight or in the morning and if it only needs a small change I will try to help. However you have 16k of code so I suspect it is not simple.

How did it get as big as 16k before you discovered there was a problem?

...R

sir really thankful to you i put my all effort but every time problem was same after 4 days my fyp submission date is over thats why i am humbly requesting you...

my fyp submission date is over

Too late, then. Start large school assignments earlier.

umerAbbasi11:
my fyp submission date is over thats why i am humbly requesting you...

I have not had time to look at your program yet but you may rest assured that I have no intention of giving you a solution that you can hand is as your FYP project and pretend you did it all yourself. That is cheating.

...R

HI Robin Sir DId you check my code

umerAbbasi11:
HI Robin Sir DId you check my code

Not yet. Hopefully later today.

I have had a look at it now. Sorry, as I suspected there is no obvious simple fix. I can't even quickly figure out what it tries to do.

By the way, if you have a GPS I don't see why you also need an RTC. The GPS will give a very accurate time signal - maybe even better than the RTC.

...R

By the way I am not a "Sir" - just an ordinary person like you.

did you figure out where i made mistake

umerAbbasi11:
did you figure out where i made mistake

No. It would take me too long just to figure out what the program is supposed to do.

As the program is so long I presume you have an earlier working version. Go back to that and work forwards again. That's what I do with my own programs when I get stuck.

...R