797
edits
mNo edit summary |
mNo edit summary |
||
Line 29: | Line 29: | ||
''Code'' | ''Code'' | ||
#include <SPI.h> //including SDcard | #include <SPI.h> //including SDcard | ||
#include <SD.h> | #include <SD.h> | ||
#include <math.h> //including for temperature calculation | #include <math.h> //including for temperature calculation | ||
File myFile; //directing data to file | |||
void setup() { | void setup() { | ||
Serial.begin(9600); //starting comunication with arduino | Serial.begin(9600); //starting comunication with arduino | ||
while (!Serial) { | while (!Serial) { | ||
; | ; | ||
} | } | ||
Serial.print("Initializing SD card..."); //initializing the SD card | Serial.print("Initializing SD card..."); //initializing the SD card | ||
if (!SD.begin(10)) { | if (!SD.begin(10)) { | ||
Serial.println("initialization failed!"); // signal if connection failed | Serial.println("initialization failed!"); // signal if connection failed | ||
while (1); | while (1); | ||
} | } | ||
Serial.println("initialization done."); // signal if connection succeded | Serial.println("initialization done."); // signal if connection succeded | ||
myFile = SD.open("test.txt", FILE_WRITE); //naming file | myFile = SD.open("test.txt", FILE_WRITE); //naming file | ||
if (myFile) { | if (myFile) { | ||
Serial.print("Writing to test.txt..."); | Serial.print("Writing to test.txt..."); | ||
myFile.println ("Spaziergang"); //naming the section of the file, date, place, number of walk | myFile.println ("Spaziergang"); //naming the section of the file, date, place, number of walk | ||
myFile.close(); | myFile.close(); | ||
Serial.println("done."); | Serial.println("done."); | ||
} | } | ||
else { | else { | ||
// if the file didn't open, print an error: | // if the file didn't open, print an error: | ||
Serial.println("error opening test.txt"); //signal if opening failed | Serial.println("error opening test.txt"); //signal if opening failed | ||
} | } | ||
} | } | ||
void loop() { | void loop() { | ||
//if the communication started successfully- | //if the communication started successfully- | ||
myFile = SD.open("test.txt", FILE_WRITE); | myFile = SD.open("test.txt", FILE_WRITE); | ||
if (myFile) { | if (myFile) { | ||
//collect incoming data from sensors | //collect incoming data from sensors | ||
//light | //light | ||
Serial.print("Writing to test.txt..."); | Serial.print("Writing to test.txt..."); | ||
int light = analogRead(A0); | int light = analogRead(A0); | ||
myFile.print( "Licht: "); | |||
myFile.println(light); | myFile.println(light); | ||
//temperature | //temperature | ||
myFile.print ("Temperatur: "); | myFile.print ("Temperatur: "); | ||
double temp=analogRead(A1); | double temp=analogRead(A1); | ||
Line 81: | Line 81: | ||
myFile.print( "Pulse: "); | myFile.print( "Pulse: "); | ||
myFile.println(pulse); | myFile.println(pulse); | ||
delay(60000); //collect data every minute | delay(60000); //collect data every minute | ||
// close the file: | // close the file: | ||
myFile.close(); | myFile.close(); |
edits