Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SD.h>
- #include <SPI.h>
- //MOSI 11
- //MISO 12
- //SCK 13
- File dataFile;
- const int chipSelect = 10;
- const int sensorPin = A0;
- void setup() {
- Serial.begin(9600);
- while(!SD.begin(chipSelect)){
- Serial.print("Error initializing SD card, retrying");
- delay(250);
- for (int i=1;i<4;i++){
- Serial.print(".");
- delay(250);
- }
- Serial.println("");
- }
- Serial.println("SD card initialized");
- if (SD.exists("temp.csv")){
- SD.remove("temp.csv");
- Serial.println("temp.csv already exists, removing...");
- }
- dataFile = SD.open("temp.csv", FILE_WRITE);
- if (dataFile){
- Serial.println("Succesfully opened test.txt");
- dataFile.close();
- } else {
- Serial.println("Error opening test.txt");
- }
- }
- void loop() {
- // put your main code here, to run repeatedly:
- int sensorVal = analogRead(sensorPin);
- float voltage = (sensorVal/1024.0) * 5.0;
- float temperature = (voltage - 0.5) * 100;
- dataFile = SD.open("temp.csv", FILE_WRITE);
- dataFile.print(millis());
- dataFile.print(",");
- dataFile.println(temperature);
- dataFile.close();
- Serial.println(temperature);
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement