Sd module

Helllo

I have a problem with the SD module: I need to register on the sd card data every 5 seconds. In void setup, initialization of the card I put a light that illuminates when the module does not work.

after which the void loop, I’m going to write my data.

The problem I found is that if done the setup, and the card was read successfully, trying to remove it during the loop does not turn on the LED (also even in the serial monitor is written error opening data.txt).
Can you give me an explanation? I need you to come on the LED otherwise do something so that it can intervene.
Thanks in advance

#include <DHT.h>
#include <SD.h>

float t1;
float h1;
float t2;
float h2;

DHT dht1(A0,DHT22);
DHT dht2(A1,DHT22);

File myFile;



void setup()
{  
 pinMode(2,OUTPUT);
 dht1.begin();
 dht2.begin();


 Serial.print("Inizializzazione Card: ");
 if (!SD.begin(10))    
 {
   Serial.println("FALLITA!");
   digitalWrite(2,HIGH);
 } else{
 Serial.println("ESEGUITO!");
 }

}

void loop()
{

t1 = dht1.readTemperature();
h1 = dht1.readHumidity();
t2 = dht2.readTemperature();
h2 = dht2.readHumidity();

   
    myFile = SD.open("Dati.csv", FILE_WRITE);
   if (myFile) {
     myFile.print((float)h1);
     myFile.print(";");
     myFile.print((float)t1);
     myFile.print(";");
     myFile.print((float)h2);
     myFile.print(";");
     myFile.print((float)t2);
     myFile.print(";");
     
     myFile.close();
   } else {
     Serial.println("error opening dati.txt");
        digitalWrite(2,HIGH);  
   }

 
 delay (5000);
 

 }
     myFile.print((float)h1);

Why are you casting a float to a float?

If writing HIGH to the pin that the LED is connected to does not make the LED come on, then the LED is not wired correctly.

Which SD module are you using?