If it works when connected to the PC, there is clearly nothing wrong with the code, there is no need to modify it, and we don't need to see it, so don't bother posting it.
The power supply is another matter. You can be pretty sure there isn't enough of it, and what you need is something that supplies more - like a bigger battery. You need to be more forthcoming on what you are doing about that. Please don't tell us you are currently using a 9v PP3 battery........
I'm working on a little station of vegetation control, and I need to transport my Arduino out of the office, it means that I need to connect the Arduino with a battery or something similar, I know it's possible but my ask is the following one.
How I modify the code to read/ write sd data without pc connection?
The point is, I'm trying to saved all of tha data in Sd card, and all it works perfecte when the arduino is connect to computer...but it doesn't work when I disconnect the USB and reconnect the Arduino to a battery.
As you may have figured out from the previous very helpful quotes you probably just need more battery power so everything gets the power it needs. I have just started with Arduino and haven't tried to power one on batteries yet but would try a high output charger/battery like those used for tablets etc.