Stap 3: Code
/* ** MOSI - pin 11 ** MISO - pin 12 ** CLK - pin 13 ** CS - pin 4 */#include #include #define PhotoresistorPin 2 #define TempPin 3 const int chipSelect = 4;String FileName = "DataLog.txt";long int LastLog;void setup() { Serial.begin(9600); pinMode(TempPin, INPUT); pinMode(PhotoresistorPin, INPUT); pinMode(13, OUTPUT); 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"); //turns on the onboard led to signal that something is wrong digitalWrite(13,HIGH); // don't do anything more: return; } Serial.print("Card initialized.");}void loop() { //delays 10 minutes while (LastLog + 600000 > millis()) { delay(1000); } int PhotoResistance = GetPhotoresistence(); float Temparature = GetTemperature(); LogData(PhotoResistance, Temparature); }void LogData(int Resistance, int Temparature) { //the file you edit File dataFile; dataFile = SD.open(FileName, FILE_WRITE); dataFile.print("Minutes Running:"); dataFile.print(millis() / 60000); dataFile.print(" Photoresistor: "); dataFile.print(Resistance); dataFile.print(" Temparature: "); dataFile.print(Temparature); dataFile.println("C"); dataFile.close(); LastLog = millis(); }float GetTemperature() { float Temperature = analogRead(TempPin); Temperature = Temperature * 0.48828125; delay(1000); return Temperature; }int GetPhotoresistence() { int Photoresistence = analogRead(PhotoresistorPin); return Photoresistence; }