Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. General Discussion
  3. Ardunio SD Card data Store

Ardunio SD Card data Store

Scheduled Pinned Locked Moved General Discussion
3 Posts 2 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sudasan
    wrote on last edited by
    #1

    HI,
    I am beginner of ardunio, I have written the ardunio code to store the temp and humidity data with time stamp information .
    while collecting the data, it shows correctly (temp and humidity with time stamp) but not stored in the SD card.
    any one help me in this ? (i like to know where i am doing mistake ?) . My code:
    #include <SD.h>
    #include "DHT.h"
    #include <Wire.h>
    #include "RTClib.h"
    #include "DS1307.h"
    #define DHTPIN A0
    #define DHTTYPE DHT22
    DHT dht(DHTPIN, DHTTYPE);
    DS1307 clock; // declare object for DS3234 class

    const int chipSelect = 10;

    void setup()
    {
    // Open serial communications and wait for port to open:
    Serial.begin(9600);
    while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
    }

    Serial.print("Initializing SD card...");
    // make sure that the default chip select pin is set to
    // output, even if you don't use it:
    pinMode(10, OUTPUT);

    // see if the card is present and can be initialized:
    if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
    }
    Serial.println("card initialized.");

    // create a new file
    char filename[] = "LOGGER00.txt";a
    for (uint8_t i = 0; i < 100; i++) {
    filename[6] = i/10 + '0';
    filename[7] = i%10 + '0';
    if (! SD.exists(filename)) {
    // only open a new file if it doesn't exist
    break; // leave the loop!
    }

    }
    Serial.print("Logging to: ");
    Serial.println(filename);
    // Enter the time and date when flashing the program
    clock.begin();
    clock.fillByYMD(2015,2,15);//Feb 10,2015
    clock.fillByHMS(18,05,30);//15:28 30"
    clock.fillDayOfWeek(SUN);//Tuesday
    clock.setTime();//write time to the RTC chip
    }

    void loop()
    {
    // Reading temperature or humidity takes about 250 milliseconds!
    // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
    float h = dht.readHumidity();
    float t = dht.readTemperature();

    //Time stamp for your program
    printTime();
    // check if returns are valid, if they are NaN (not a number) then something went wrong!

    if (isnan(t) || isnan(h))
    {
    Serial.println("Failed to read from DHT");
    }
    else
    {
    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(t);
    Serial.println(" *C");
    }

    }
    void printTime()
    {
    clock.getTime();
    Serial.print(clock.hour, DEC);
    Serial.print(":");
    Serial.print(clock.minute, DEC);
    Serial.print(":");
    Serial.print(clock.second, DEC);
    Serial.print(" ");
    Serial.print(clock.month, DEC);
    Serial.print("/");
    Serial.print(clock.dayOfMonth, DEC);
    Serial.print("/");
    Serial.print(clock.year+2000, DEC);
    Serial.print(" ");
    Serial.print(clock.dayOfMonth);
    Serial.print("*");
    switch (clock.dayOfWeek)// Friendly printout the weekday
    {
    case MON:
    Serial.print("MON");
    break;
    case TUE:
    Serial.print("TUE");
    break;
    case WED:
    Serial.print("WED");
    break;
    case THU:
    Serial.print("THU");
    break;
    case FRI:
    Serial.print("FRI");
    break;
    case SAT:
    Serial.print("SAT");
    break;
    case SUN:
    Serial.print("SUN");
    break;
    }
    Serial.println(" ");
    }

    1 Reply Last reply
    0
    • RJ_MakeR Offline
      RJ_MakeR Offline
      RJ_Make
      Hero Member
      wrote on last edited by
      #2

      can you indent your code with 4 spaces? It's too difficult to read un-formatted.

      RJ_Make

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sudasan
        wrote on last edited by
        #3

        #include <SD.h>
        #include "DHT.h"
        #include <Wire.h>
        #include "RTClib.h"
        #include "DS1307.h"
        #define DHTPIN A0
        #define DHTTYPE DHT22
        DHT dht(DHTPIN, DHTTYPE);
        DS1307 clock; // declare object for DS3234 class

        const int chipSelect = 10;

        void setup()
        {
        // Open serial communications and wait for port to open:
        Serial.begin(9600);
        while (!Serial) {
        ; // wait for serial port to connect. Needed for Leonardo only
        }

        Serial.print("Initializing SD card...");
        // make sure that the default chip select pin is set to
        // output, even if you don't use it:
        pinMode(10, OUTPUT);

        // see if the card is present and can be initialized:
        if (!SD.begin(chipSelect)) {
        Serial.println("Card failed, or not present");
        // don't do anything more:
        return;
        }
        Serial.println("card initialized.");

        // create a new file
        char filename[] = "LOGGER00.txt";
        for (uint8_t i = 0; i < 100; i++) {
        filename[6] = i/10 + '0';
        filename[7] = i%10 + '0';
        if (! SD.exists(filename)) {
        // only open a new file if it doesn't exist
        break; // leave the loop!
        }

        }
        Serial.print("Logging to: ");
        Serial.println(filename);
        // Enter the time and date when flashing the program
        clock.begin();
        clock.fillByYMD(2015,2,15);//Feb 15,2015
        clock.fillByHMS(22,55,30);//19:05 30"
        clock.fillDayOfWeek(SUN);//Sunday
        clock.setTime();//write time to the RTC chip
        }

        void loop()
        {
        // Reading temperature or humidity takes about 250 milliseconds!
        // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
        float h = dht.readHumidity();
        float t = dht.readTemperature();
        delay(60000); // wait one second (1000) before do it again (60 sec =1 min) 60 *1000
        //Time stamp for your program
        printTime();
        // check if returns are valid, if they are NaN (not a number) then something went wrong!

        if (isnan(t) || isnan(h))
        {
        Serial.println("Failed to read from DHT");
        }
        else
        {
        Serial.print("Humidity: ");
        Serial.print(h);
        Serial.print(" %\t");
        Serial.print("Temperature: ");
        Serial.print(t);
        Serial.println(" *C");
        }

        }
        void printTime()
        {
        clock.getTime();
        Serial.print(clock.hour, DEC);
        Serial.print(":");
        Serial.print(clock.minute, DEC);
        Serial.print(":");
        Serial.print(clock.second, DEC);
        Serial.print(" ");
        Serial.print(clock.month, DEC);
        Serial.print("/");
        Serial.print(clock.dayOfMonth, DEC);
        Serial.print("/");
        Serial.print(clock.year+2000, DEC);
        Serial.print(" ");
        Serial.print(clock.dayOfMonth);
        Serial.print("*");
        switch (clock.dayOfWeek)// Friendly printout the weekday
        {
        case MON:
        Serial.print("MON");
        break;
        case TUE:
        Serial.print("TUE");
        break;
        case WED:
        Serial.print("WED");
        break;
        case THU:
        Serial.print("THU");
        break;
        case FRI:
        Serial.print("FRI");
        break;
        case SAT:
        Serial.print("SAT");
        break;
        case SUN:
        Serial.print("SUN");
        break;
        }
        Serial.println(" ");
        }

        • list item
        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        49

        Online

        11.7k

        Users

        11.2k

        Topics

        113.1k

        Posts


        Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • MySensors
        • OpenHardware.io
        • Categories
        • Recent
        • Tags
        • Popular