Problem with my SD Card

Hello, I seem to have a problem with my data logger as it only seems to have a limit of 500 kilobytes in the file despite having 32 gigabytes of storage, It clears the lines before and continues to record at a certain amount of lines. For example after line 1000 it continues to record but deletes anything before that. Here is the code I used. I am also using SanDisk Micro SD Card FAT32 formatted.

//Tech Trends Shameer
//Temperature Data Log into SD Card

#include <SPI.h>        // Include SPI library (needed for the SD card)
#include <SD.h>         // Include SD library
#include <DHT.h>        // Include DHT sensor library
 
File dataFile;
 
#define DHTPIN 4            // DHT11 data pin is connected to Arduino pin 4
#define DHTTYPE DHT11       // DHT11 sensor is used
#define sensorPower 7
#define sensorPin A0
DHT dht(DHTPIN, DHTTYPE);   // Initialize DHT library
 
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial)
    ; // wait for serial port to connect. Needed for native USB port only
  Serial.print("Initializing SD card...");
  if (!SD.begin()) 
  {
    Serial.println("initialization failed!");
    while (1);
  }
  Serial.println("initialization done.");
  delay(2000);
  dht.begin();
}
 
uint16_t line = 1;
 
void loop() {
  int moisture = analogRead (A0);
  delay(1000);
  // Read humidity
  byte RH = dht.readHumidity();
  //Read temperature in degree Celsius
  byte Temp = dht.readTemperature();
  
  dataFile = SD.open("DHT11Log.txt", FILE_WRITE);
  
  // if the file opened okay, write to it:
  if (dataFile) 
  {
    Serial.print(line);
    Serial.print(":    Aragon Alfonso Calunsag Nillas Ngamoy Al-ag Anino R.");
    Serial.print(":    STEM-B");
    Serial.print(":    Soil Moisture Index: ");
  	Serial.println(moisture);
    Serial.print(":    Temperature = ");
    Serial.print(Temp);
    Serial.print("°C,    Humidity = ");
    Serial.print(RH);
    Serial.println("%");
    // Write data to SD card file (DHT11Log.txt)
    dataFile.print(line++);
    dataFile.print(":    Aragon Alfonso Calunsag Nillas Ngamoy Al-ag Anino R.");
    dataFile.print(":    STEM-B :>");
    dataFile.print(":    Soil Moisture Index: ");
  	dataFile.println(moisture);
    dataFile.print(":    Temperature = ");
    dataFile.print(Temp);
    dataFile.print("°C,    Humidity = ");
    dataFile.print(RH);
    dataFile.println("%");
    dataFile.close();
    int readSensor (A0); {
	digitalWrite(sensorPower, HIGH);	// Turn the sensor ON
	delay(1000);							// Allow power to settle
	int val = analogRead(A0);	// Read the analog value form sensor
	digitalWrite(sensorPower, LOW);		// Turn the sensor OFF
	return val;							// Return analog moisture value
}
  }
  // if the file didn't open, print an error:
  else
    Serial.println("error opening DHT11Log.txt");
}

Help would be appreciated :smile:

Is that your problem?

(How is this "URGENT"?)

Also, you may find a use for the F() macro in your code.

Post code that will compile. There are at least two fatal errors in the two lines above. I count three.

extremely sorry for the confusion but it compiles normally when i run it

Those errors are a serious problem, regardless. In the Arduino IDE, under File>Preferences turn on "verbose" output for compilation to see the error messages.

Go through the program line by line, and make sure that you understand what each line does, and why.

Alright thank you kind stranger

Compile error here;

In function 'void loop()':
Code:74:10: error: return-statement with a value, in function returning 'void' [-fpermissive]
   return val;             // Return analog moisture value
          ^~~
exit status 1
return-statement with a value, in function returning 'void' [-fpermissive]

Hint: this bit of code was once a separate function definition, but because of a missing brace, and a misplaced ";" it has become part of loop().

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.