You are right..
seems no problem with the wiring, like i said it work when its conecthed to the computer. think the problem is with my code..
i have a sd-adapter, Mq135 sensor and the humidity/temperatur sensor, connected to my arduino Uno
my code is, and hope its readable:
#include <SD.h>
#include <SPI.h>
#include "DHT.h"
#define DHTPIN 7
#define DHTTYPE DHT11
#define anInput A0 //analog feed from MQ135
#define co2Zero 44 //calibrated CO2 0 level
long seconds=00;
long minutes=00;
long hours=00;
int CS_pin = 10;
DHT dht(DHTPIN, DHTTYPE);
File sd_file;
void setup() {
Serial.begin(9600);
pinMode(CS_pin, OUTPUT);
dht.begin();
// SD Card Initialization
if (SD.begin()) {
Serial.println("SD card is initialized. Ready to go");
}
else {
Serial.println("Failed");
return;
}
sd_file = SD.open("data.txt", FILE_WRITE);
if (sd_file) {
Serial.print("Time");
Serial.print(",");
Serial.print("Humidity");
Serial.print(",");
Serial.print("Temperature");
Serial.print(",");
Serial.print("CO2-index");
Serial.print(",");
Serial.println("Heat_index");
sd_file.print("Time");
sd_file.print(",");
sd_file.print("Humidity");
sd_file.print(",");
sd_file.print("Temperature");
sd_file.print(",");
sd_file.print("CO2-index");
sd_file.print(",");
sd_file.println("Heat_index");
}
sd_file.close(); //closing the file
}
void loop() {
sd_file = SD.open("data.txt", FILE_WRITE);
if (sd_file) {
senddata();
}
// if the file didn't open, print an error:
else {
Serial.println("error opening file");
}
delay(1000);
}
void senddata() {
for(long seconds = 00; seconds < 60; seconds=seconds+10) {
float temp = dht.readTemperature(); //Reading the temperature as Celsius and storing in temp
float hum = dht.readHumidity(); //Reading the humidity and storing in hum
float heat_index = dht.computeHeatIndex(temp, hum);
int co2now[10]; //int array for co2 readings
int co2raw = 0; //int for raw value of co2
int co2comp = 0; //int for compensated co2
int co2ppm = 0; //int for calculated ppm
int zzz = 0; //int for averaging
int grafX = 0; //int for x value of graph
for (int x = 0;x<10;x++){ //samplpe co2 10x over 2 seconds
co2now[x]=analogRead(A0);
delay(1000);
}
for (int x = 0;x<10;x++){ //add samples together
zzz=zzz + co2now[x];
}
co2raw = zzz/10; //divide samples by 10
co2comp = co2raw - co2Zero; //get compensated value
co2ppm = map(co2comp,0,1023,400,5000); //map value for atmospheric levels
sd_file.print(hours);
sd_file.print(":");
sd_file.print(minutes);
sd_file.print(":");
sd_file.print(seconds);
sd_file.print(",");
sd_file.print(hum);
sd_file.print(",");
sd_file.print(temp);
sd_file.print(",");
sd_file.print(co2ppm, DEC);
sd_file.print(",");
sd_file.println(heat_index);
Serial.print(hours);
Serial.print(":");
Serial.print(minutes);
Serial.print(":");
Serial.print(seconds);
Serial.print(", ");
Serial.print(hum);
Serial.print(", ");
Serial.print(temp);
Serial.print(", ");
Serial.print(co2ppm, DEC);
Serial.print(", ");
Serial.println(heat_index);
if(seconds>=50) {
minutes= minutes + 1;
}
if (minutes>59) {
hours = hours + 1;
minutes = 0;
}
sd_file.flush(); //saving the file
delay(9000);
}
sd_file.close(); //closing the file
}