Arduino Processing Control Entrances

Hello, Im using arduino and processing to send data to a mysql database (using xampp).
Its a program to contral entrances, Im using rfid tags and the mrfc522 sensor to read it, arduino reads it and then via processing its sent to the mysql database.
All is working fine but the program just stops working from time to time, especially if you dont use it for some minutes. The program ussualy gets solved bu resending the processing code but sometimes I also need to resend arduino… Any ideas on how to solve it?

Thanks in advance

My processing code

// Example by Tom Igoe
import de.bezier.data.sql.;
import processing.serial.
;
import processing.sound.*;
SoundFile song;

String numero=" ";
Serial myPort; // The serial port
MySQL dbconnection;
void setup() {
// List all the available serial ports:
printArray(Serial.list());
// Open the port you are using at the rate you want:
myPort = new Serial(this, “COM6”, 9600);
song = new SoundFile(this, “song.mp3”);
}

void draw() {
while (myPort.available() > 0) {
String inBuffer = myPort.readString();
if (inBuffer != null) {
println(inBuffer);
numero = inBuffer;
println(numero);

    String user     = "root";
    String pass     = "";
    String database = "entradas";
    // connect to database of server "localhost"
    dbconnection = new MySQL( this, "localhost", database, user, pass );

    if ( dbconnection.connect() ) {
    
    // now send data to database
    dbconnection.execute( "INSERT INTO entrou (numero) VALUES ('"+numero+"');" );
    println();
    println("Introduzido com sucesso!");
    song.play();
    
}

}
}
}

Randomly coming problems often depend on the powering being insufficient. A wiring diagram, links, regarding powering could be useful for helpers.

Sorry about late reply but had to go to work.
I dont have the wiring here but its just the mrfc522 simpliest wiring diagram that even appears in the Arduino examples.
I thought it was about that and I changed all cables, I even changed Arduino and happens the same every time.

I also thought about being a computer problem, I tried to use it in every USB port and nothing changes, tho sometimes I have to disconnect and then connect again the cable for it to works, but looks strange, if the problem was that I would have to disconnect and connect every time, right?

Thanks for the reply

Okey. I don’t know the details of all the parts You are using. However I know that way too often insufficient powering is the reason for unexpected problems.
I admit I guess but making sure the powering is good would give You, me and other helpers a good base to work from.
Can You use pen and paper and make a wiring diagram of all power lines including supplies and consumers?

image

My wiring os just like this one

That’s a Fritzing, not useful to answer the previous question. The UNO has no power supply.

Considder adding an array to log time from event to response from sql.

If the communication is lost and has to reset… that could cause an unexpected delay.

The power supply is the computer via USB port…

That seems like a good idea, Ill try it out and let you know, if I manage to make ir work

That must be safe.

Wasnt working so I used ethernet shield and works like a charm