Dear Group members,
I am newer of grove product use.
I am using Grove humidity and temperature sensor (Arduio Uno).
I facing small problem, is that: i an view the data with time stamp but the data not writing to SD card.
I tried with Sample SD card write code it is working fine.
Any one can correct my code to store the data in Sd card as well.
TIA
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.CSV”;
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,10);//Feb 10,2015
clock.fillByHMS(15,28,30);//15:28 30”
clock.fillDayOfWeek(TUE);//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(" ");
}