why Micro SD card can't log the data when we connect servo motor ?

Hi guys, recently Iam making a project which includes Arduino Nano, MPU6050, BMP280, micro SD card module and a servo motor. Brief explanation of my project is basically I am trying to collect data from the MPU6050 and BMP280 and log that data with the help of a micro SD card module and the job of the servo motor is just to rotate its shaft from 0 degrees to 90 degrees after some time we powered up the board and for that I am using simple timer code using Millis(). Everything works perfectly, micro SD card log data correctly and servo moved at the correct time and i got really a great data and I tested this in breadboard but my project needs to be on PCB board.

Connections:

Micro SD card module:
MOSI - pin D11
MISO - pin D12
CLK - pin D13
CS - pin D4

MPU6050:
SCL - pin A5
SDA - pin A4

BMP280:
SCL - pin A5
SDA - pin A4

SERVO:
SIGNAL PIN - D6

and every VCC and GND i connected to the arduino’s 5v (except bmp280 because it is connected to 3.3v) and GND.

So, I transferred everything to my PCB board and I soldered it, but when I tested it on PCB board, in the start everything works good and micro SD card module started to log data perfectly, but when the servo rotated after some time we powered up the board, suddenly micro SD card stops to log the data and Serial monitor printed:

X axis = -2 | Y axis = 0 | Temperature = 30.27 *C | Pressure = 101103.99 Pa | Approx altitude = -14.53 m |
X axis = -6 | Y axis = 0 | Temperature = 30.27 *C | Pressure = 101103.99 Pa | Approx altitude = -14.53 m |
X axis = -2 | Y axis = 0 | Temperature = 30.27 *C | Pressure = 101103.99 Pa | Approx altitude = -14.53 m |
X axis = -3 | Y axis = 0 | Temperature = 30.27 *C | Pressure = 101104.10 Pa | Approx altitude = -14.54 m |
X axis = -2 | Y axis = 0 | Temperature = 30.27 *C | Pressure = 101104.10 Pa | Approx altitude = -14.54 m |
X axis = -1 | Y axis = 0 | Temperature = 30.27 *C | Pressure = 101104.10 Pa | Approx altitude = -14.54 m |
X axis = -1 | Y axis = 0 | Temperature = 30.27 *C | Pressure = 101104.58 Pa | Approx altitude = -14.58 m |
X axis = -3 | Y axis = 0 | Temperature = 30.27 *C | Pressure = 101104.58 Pa | Approx altitude = -14.58 m |
X axis = -2 | Y axis = 0 | Temperature = 30.27 *C | Pressure = 101104.58 Pa | Approx altitude = -14.58 m |
X axis = -2 | Y axis = 0 | Temperature = 30.27 *C | Pressure = 101104.91 Pa | Approx altitude = -14.61 m |
error opening X.txt
error opening Y.txt
error opening T.txt
error opening P.txt
error opening A.txt
X axis = 8 | Y axis = 0 | Temperature = 30.27 *C | Pressure = 101104.91 Pa | Approx altitude = -14.61 m |
error opening X.txt
error opening Y.txt
error opening T.txt
error opening P.txt
error opening A.txt
X axis = 21 | Y axis = 0 | Temperature = 30.27 *C | Pressure = 101105.78 Pa | Approx altitude = -14.68 m |
error opening X.txt
error opening Y.txt
error opening T.txt
error opening P.txt
error opening A.txt

Here you can see that initially everything worked perfectly, but after the servo moved the serial monitor started to print error opening…

But after some time whenever i attach the pins of servo to the arduino board the micro SD card can’t log the data

X axis = 0 | Y axis = 0 | Temperature = 30.40 *C | Pressure = 101098.16 Pa | Approx altitude = -14.05 m |
error opening X.txt
error opening Y.txt
error opening T.txt
error opening P.txt
error opening A.txt
X axis = 0 | Y axis = 0 | Temperature = 30.40 *C | Pressure = 101098.60 Pa | Approx altitude = -14.08 m |
error opening X.txt
error opening Y.txt
error opening T.txt
error opening P.txt
error opening A.txt
X axis = 0 | Y axis = 0 | Temperature = 30.40 *C | Pressure = 101098.60 Pa | Approx altitude = -14.08 m |
error opening X.txt
error opening Y.txt
error opening T.txt
error opening P.txt
error opening A.txt
X axis = 0 | Y axis = 0 | Temperature = 30.40 *C | Pressure = 101098.60 Pa | Approx altitude = -14.08 m |
error opening X.txt
error opening Y.txt
error opening T.txt
error opening P.txt
error opening A.txt

Before, whenever the servo moves, then only the micro SD card module can’t log the data, but now whenever I attach the servo with Arduino nano itself micro SD card module can’t log the data.

I have checked the solder lines many times and i think and there is no problem with that and there also no problem with the code. Whenever I attach the servo the module can’t log the data and when I remove the servo motor everything works perfectly, but for my project servo is really very important.

I don’t know what is exactly wrong here So can you guys pls say what i have to do now to solve this problem, pls pls

And I will also upload the code, but not fully because it is little big and confidential So I will just upload what are the important things in the code which are related with this problem:

void timer() {
  
  v = digitalRead(but);
  
  if (v == 0) {
    
    for (int b = 0; b < 6; b++) {
      
      int buz;
      
      buz = buz + 1000;
      
      tone(buzz, buz);
       delay(100);
        noTone(buzz);
         delay(100);
         
    }
    
    Serial.println(F("timer STARTS !!"));
     Serial.println(F("DURATION IS 60s"));
     
    for (int x = 0; x < 60; x++) {
      
      Serial.println(y);
      
      v = digitalRead(but);
      
      if (v == 0) {
        
        Serial.println(F("timer IS PAUSED !!"));
        
        tone(buzz, 100);
         delay(1000);
          noTone(buzz);
          
        while (w) {

         delay(1);

         del = del + 1UL;
         
         v = digitalRead(but);
         
          if ( v == 0) {
            
           w = 0;

           Serial.println(F("timer is RESUMEED !!"));

            for (int b = 0; b < 6; b++) {
              
              int buz = 0;
              
              buz = buz + 250;

              tone(buzz, buz);
               delay(100);
                noTone(buzz);
                 delay(100);

              
              
            }
          }

         delay(1000);

         del = del + 1000UL;

         
         
      }

      
    }

    w = 1;
      
      if (y <= 60 && y > 45) {
        
        digitalWrite(led2, HIGH);
         delay(500);
          digitalWrite(led2, LOW);
           delay(500);
        
      }
      
      else if (y <= 55 && y > 30) {
        
        digitalWrite(led1, HIGH);
         delay(500);
          digitalWrite(led1, LOW);
           delay(500);
           
      }
      
      else if (y <= 30 && y > 10) {
        
        digitalWrite(led1, HIGH);
         digitalWrite(led2, HIGH);
          delay(500);
          
        digitalWrite(led1, LOW);
         digitalWrite(led2, LOW);
          delay(500);
        
      }
      
      else if (y <= 10 && y > 1 ) {
        
        digitalWrite(buzz, HIGH);
         delay(500);
          digitalWrite(buzz, LOW);
           delay(500);
           
      }
      
      else if (y = 1) {
        
        tone(buzz, 600);
         delay(1000);
          noTone(buzz);
           delay(500);
        
      }
      
      y = y - 1;
      
    }
  }
  
  Serial.println(F("DHRAVAM GO FOR LAUNCH !!!"));
  
}


void data() {
  
  File XFile = SD.open("X.txt", FILE_WRITE);
  
   if (XFile) {
    
    XFile.println(totalX);
     XFile.close();
    
 }
 
  else {
    
   Serial.println(F("error opening X.txt"));
   
  }

   File YFile = SD.open("Y.txt", FILE_WRITE);
   
   if (YFile) {
    
    YFile.println(totalY);
     YFile.close();
    
 }
 
  else {
    
   Serial.println(F("error opening Y.txt"));
   
  }

   File TFile = SD.open("T.txt", FILE_WRITE);
   
   if (TFile) {
    
    TFile.println(bmp.readTemperature());
     TFile.close();
    
 }
 
  else {
    
   Serial.println(F("error opening T.txt"));
   
  }

   File PFile = SD.open("P.txt", FILE_WRITE);
   
   if (PFile) {
    
    PFile.println(bmp.readPressure());
     PFile.close();
    
 }
 
  else {
    
   Serial.println(F("error opening P.txt"));
   
  }

   File AFile = SD.open("A.txt", FILE_WRITE);
   
   if (AFile) {
    
    AFile.println(bmp.readAltitude(1009.3));
     AFile.close();
    
 }
 
  else {
    
   Serial.println(F("error opening A.txt"));
   
  }
}

void servo() {

  adel = del + 96000UL + 1000UL;
  
  t = millis();
  
  if ( t > adel ) {
    
    s.write(180);
    
  }
}

PLS PLS HELP ME TO SOLVE THIS PROBLEM !

How was the Nano powered when it failed? Battery?
When testing on the breadboard did you have a laptop connected (USB power)?
I would suspect your power supply dips when the servo kicks in.

Karma for using code tags.
G

Zardof:
How was the Nano powered when it failed? Battery?
When testing on the breadboard did you have a laptop connected (USB power)?
I would suspect your power supply dips when the servo kicks in.

Karma for using code tags.
G

Ya for now i am using my laptop has a main power source for my nano through a USB cable but my arduino nano's 5v output is not working so for that I am using 9v baterry(connecting the vcc and gnd of the mpu6050, micro sd card module and servo to the anode and cathode terminal of the battery and I am also connected the cathode of the battery to the gnd of nano) and sorry I forgot to inform this earlier

PP3-sized 9V battery can’t power motors or servos, they are low current batteries.

You should be using separate power for a servo anyway, not trying to share with the logic
chips.

Even small servo’s take lots of current, you should budget 1A per servo for small ones,
proportionately more with larger ones and high-torque ones. 95% of problems people
have with servos is underestimating the power draw.

MarkT:
PP3-sized 9V battery can't power motors or servos, they are low current batteries.

You should be using separate power for a servo anyway, not trying to share with the logic
chips.

Even small servo's take lots of current, you should budget 1A per servo for small ones,
proportionately more with larger ones and high-torque ones. 95% of problems people
have with servos is underestimating the power draw.

thanks for saying and i will try it out