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

Thread Starter

Sunandhan S

Joined Oct 9, 2020
7
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:

C++:
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 !
 

djsfantasi

Joined Apr 11, 2010
9,163
It’s strange that this worked on a breadboard, but failed on your PCB. Can you post clear pics of the breadboard and both sides of the PCB? It’s strange that it seems to work fir a while before failing.

Obviously, your SD card adapter is being hosed by the servo...

Your code is hard to understand. It obviously is not your complete program. Variable definitions are missing and there is no setup code.

I suspect that there is a mixup of the pins used by the servo and the micro SD card adapter. Or, the PCB board is affected by noise generated by the servo.

How is all this powered? Do you have filter capacitors on the Nano power supply? Are you using a single power supply for both the servo and everything else? Try powering the servo from 4 AA batteries with the battery ground connected to the Nano ground as well. Include a filter capacitor on the battery supply as well. This will eliminate motor noise as a fault.
 

BobaMosfet

Joined Jul 1, 2009
2,113
@Sunandhan S
As previously requested, we need schematic. It is possible your PCB does not faithfully represent what you did on the breadboard. Easy mistake to make, can be difficult to find.

We also need information about the servo motor and so forth, so we can understands its parameters.
 

Thread Starter

Sunandhan S

Joined Oct 9, 2020
7
@Sunandhan S
As previously requested, we need schematic. It is possible your PCB does not faithfully represent what you did on the breadboard. Easy mistake to make, can be difficult to find.

We also need information about the servo motor and so forth, so we can understands its parameters.
NOW IT IS NOW WORKING PERFECTLY !!
 
Top