arduino datalogger using ethernet shield

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Octaviuso8

Thread Starter
Joined
Jan 22, 2016
Messages
9
i am trying to store data in text format in a sd card from my dht11 sensor using a ethernet shield.
i wrote the code on the ide given below:
#include <DHT.h>
#include <SD.h>

//Constants
#define DHTPIN A0 // what pin we're connected to
#define DHTTYPE DHT11 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino



// variables
float hum ;
float temp ;
int sensor ;
const int chipSelect =4;
int analogPin =0;
void setup() {
// put your setup code here, to run once:
// Open serial communications and wait for port to open:
Serial.begin(9600);
dht.begin();
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.");
//Defines Temperature as an INPUT on PIN Number 0
pinMode(0, INPUT);
}

void loop() {
// put your main code here, to run repeatedly:

// make a string for assembling the data to log:
String dataString = "";
for (analogPin = 0; analogPin < 2; analogPin++){


if(analogPin==0){
//reads Humidity
hum = dht.readHumidity();

sensor = hum ;
}


else
{
//reads temperature
temp = dht.readTemperature();

sensor = temp ;
}

delay(2000);

//stores our values
dataString += String(sensor);
if (analogPin < 1) {
dataString += ",";
}

// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("data.txt", FILE_WRITE);

// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}

}
}
after uploading the code when i run it the serial monitor shows
Initializing SD card...Card failed, or not present
error opening datalog.txt
error opening datalog.txt
error opening datalog.txt
error opening datalog.txt
error opening datalog.txt
error opening datalog.txt
error opening datalog.txt
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top