Silícios LabPCBWay
Published © GPL3+

Real-Time SD Card Failure Detection System

In this project, you'll learn how to create a system that must be able to detect a malfunction in an SD card and to inform on an LCD.

BeginnerProtip30 minutes1,108
Real-Time SD Card Failure Detection System

Things used in this project

Hardware components

PCBWay Custom PCB
PCBWay Custom PCB
×1
UTSOURCE Arduino UNO R3
×1
10kR Rotary Potentiometer - UTSOURCE
×2
Wire Jumpers - UTSOURCE
×1
UTSOURCE Display LCD 16x2
×1
UTSOURCE 10kR Resistor
×1
SD Card Module - UTSOURCE
×1
Switch Button - UTSOURCE
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematic of the Circuit

Code

Code to Detect failed or card disconnected

Arduino
#include <SD.h>
#include <SPI.h>
#include <LiquidCrystal.h>

File myFile;

const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

#define AnalogPin A0

int pinoSS = 10; // Pin 53 para Mega / Pin 10 para UNO

int DigitalValue = 0;

byte samples = 0;

bool SDCardTest = 0, ControlState = 0, LCDControl = 0;

void setup()
{ 
    Serial.begin(9600); // Define BaundRate
    lcd.begin(16, 2);
    pinMode(pinoSS, OUTPUT); // Declara pinoSS como saída

      delay(500);
    
    lcd.clear();    
  
    do
    {
      if (SD.begin()) 
      { // Inicializa o SD Card
        lcd.setCursor(6,0);
        lcd.print("Card");
        lcd.setCursor(3,1);
        lcd.print("Connected!");
        delay(2000);
        SDCardTest = 1;
      } 
       
        else 
      
      {
        lcd.clear();
        Serial.println("imprimindo segunda mensagem de erro.");
        lcd.setCursor(1,0);
        lcd.print("Failed or Card");
        lcd.setCursor(2,1);
        lcd.print("disconnected");
        SDCardTest = 0;
      }
      
    }while(SDCardTest == 0);
    
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Press the button");
      lcd.setCursor(1,1);
      lcd.print("To store data");
     
}
 
void loop()
{
          
          bool Button = digitalRead(8);

           if(LCDControl == 0)
           {
            lcd.setCursor(0,0);
            lcd.print("Press the button");
            lcd.setCursor(1,1);
            lcd.print("To store data");
            LCDControl = 1;
           }
          
          if(Button == 0 && ControlState == 1)
          {
            ControlState = 0;  
          }    
      
          if(Button == 1 && ControlState == 0)
          {
            myFile = SD.open("silicioslab.txt", FILE_WRITE); // Create/Open File the txt
            delay(500);
            
            lcd.clear();
            
            lcd.setCursor(4,0);
            lcd.print("Storing");
            lcd.setCursor(4,1);
            lcd.print("data...");
            
            do
            {              
              DigitalValue = analogRead(AnalogPin);
              myFile.println(DigitalValue);
              delay(400);
              samples++;
            }while(samples < 10);

            samples = 0;
              
            lcd.clear();
            
            lcd.setCursor(4,0);
            lcd.print("Finished");
            lcd.setCursor(2,1);
            lcd.print("Successfully");            
            delay(2000);
            
            LCDControl = 0;
            myFile.close(); //Close file
            ControlState = 0;
          }

          do
          {
            
            if (SD.begin()) 
            {
                SDCardTest = 1;          
            } 
             
              else
            
            {
              lcd.clear();
              lcd.setCursor(1,0);
              lcd.print("Failed or Card");
              lcd.setCursor(2,1);
              lcd.print("disconnected");
              SDCardTest = 0; 
              LCDControl = 0;   
              Serial.println("Verificando problema...");     
            }
            
          }while(SDCardTest == 0);
}

Credits

Silícios Lab

Silícios Lab

72 projects • 173 followers
Hello, I love program microcontrollers and works with electronic projects.
PCBWay

PCBWay

90 projects • 146 followers
We are a PCB and assembly manufacturer, As low as $5/10pcs and 24 hours delivery time. We are committed to helping creators build project.

Comments