problem in communication between lcd and sd card from dht sensor

Hi,
iam using the arduino uno in my project.The project is to display the temperature and humidity in lcd and ethernet and stored in the sd card in every 1 minute ,using the dht 22 sensor.But the lcd display is not working simultaneously with the sd .Hereby i am attaching the code.pls hlp me to trobleshoot the problem.

sketch_jun03aterror.ino (4.06 KB)

const int chipSelect = 4;
LiquidCrystal lcd(3, 4, 5, 6, 7, 8);

Pin 4 conflict.

Please post your code inside the code tags available at the top left of the tool bar </>
It makes it much easier to look at your code.

This is my code:

#include <SPI.h>
#include <SD.h>
#include <Ethernet.h>
#include "DHT.h"
#include <LiquidCrystal.h>
#define DHTPIN 2
#define DHTTYPE DHT22
const int chipSelect = 4;
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(3, 9, 5, 6, 7, 8);
byte mac[] = {0x90, 0xA2, 0xDA, 0x00, 0x23, 0x36};
IPAddress ip(192, 168, 1, 49);
EthernetServer server(80);
File myFile;
File webFile;
int Timer = 0;
//long lst = 0;
void setup()
{

Serial.begin(9600);
Serial.print("Initializing SD card...");

pinMode(4, OUTPUT);

if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");

return;
}
Serial.println("card initialized.");

Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
lcd.begin(16, 2);
lcd.clear();
dht.begin();
}

void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (Timer == 0)
{

lcd.clear();
lcd.setCursor(0, 0);

lcd.print("Temp: ");
lcd.print(t);
lcd.print("C");

lcd.setCursor(0, 1);
lcd.print("Humidity: ");
lcd.print(h);
lcd.print("%");
delay(200);

}

else
{
File myFile;
myFile = SD.open("test.txt", FILE_WRITE);
if (myFile) {
myFile.println(".......");
myFile.println("humidity(%)");
myFile.println(h, 2);
myFile.println("Temperature(*C)");
myFile.println(t, 2);

myFile.close();
Serial.println("done.");
} else {

Serial.println("error opening test.txt");
}
delay (60000);

myFile = SD.open("test.txt");
if (myFile) {
Serial.println("test.txt:");

while (myFile.available()) {
Serial.write(myFile.read());
}
}
EthernetClient client = server.available(); // try to get client
if (client) { // got client?
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) { // client data available to read
char c = client.read(); // read 1 byte (character) from client
// last line of client request is blank and ends with \n
// respond to client only after last line received
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
//client.println("Refresh: 60"); // refresh the page automatically every 60 sec
client.println();
client.println("");
client.println("");
client.println("
");
// send web page
webFile = SD.open("test.txt"); // open web page file
if (webFile) {
while (webFile.available()) {
client.write(webFile.read()); // send web page to client
}
webFile.close();
}
break;
//client.println("Refresh: 5");
}
// every line of text received from the client ends with \r\n
if (c == '\n') {
// last character on line of received text
// starting new line with next character read
currentLineIsBlank = true;
}
else if (c != '\r') {
// a text character was received from client
currentLineIsBlank = false;
}
} // end if (client.available())
} // end while (client.connected())
delay(1); // give the web browser time to receive the data
client.stop();// close the connection
}
}
Timer = Timer + 1;
if (Timer == 2)
{
Timer = 0;
}
}

Hai ,

Then i changed the pin4 to 9 in lcd ,lcd and sd is working but the ethernet is not working(pin 9 is w5100 's reset pin). Pls give me an alternative solution to working the whole components properly.

Anyone pls hlp me.i was struck in this project for 3 weeks.

Change pin 9 on the lcd to an unused pin. I'd stay away from 1,2,and 13 because of the Serial and the led on 13. If you don't have a digital pin available, analog pins, may be configured, and used, in exactly the same manner as digital pins.

umm check the ip address, it doesent look right

I'd stay away from 1,2,and 13 because of the Serial and the led on 13.

I think you mean 0,1 for serial.
There is no problem using 13 - it is connected to the input of an op-amp/comparator to drive the LED, which presents the same miniscule load to a signal as any other IO pin - just 1uA.

hi,
i change the pin configuration.Now the program is working ,but after 10 minutes it showing error in opening text,if i reset the arduino board its working.W hat change in code i have do to work this program for 24 hours.hereby also attaching my new code.somebody pls hlp me.

code:

#include <SPI.h>
#include "DHT.h"
#include <LiquidCrystal.h>
#include <SD.h>
#include <Ethernet.h>
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
const int chipSelect = 4;
LiquidCrystal lcd(3,A0,5,6,7,8);
byte mac[] = {0x90, 0xA2, 0xDA, 0x00, 0x23, 0x36};
IPAddress ip(192, 168, 1, 49);
EthernetServer server(80);
File myFile;
File webFile;
void setup()
{
Serial.begin(9600);
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(4, 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.");

Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
lcd.begin(16, 2);
lcd.clear();
dht.begin();
pinMode(2,INPUT);
pinMode(A0,OUTPUT);
digitalWrite(A0, LOW);
}
void loop()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
int i=0;

if (isnan(h) || isnan(t))
{
Serial.println("Failed to read from DHT sensor!");
return;
}

lcd.setCursor(0,0);
lcd.print("Humidity: ");
lcd.print(h);
lcd.print("%");
lcd.setCursor(0,1);
lcd.print("Temp(*c):");
lcd.print(t);
delay(2000);

Serial.print("Humidity(%): ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temp(*c): ");
Serial.print(t);
Serial.println();
File myFile;
myFile = SD.open("test.txt", FILE_WRITE);
if (myFile) {
myFile.println(".......");
myFile.println("humidity(%)");
myFile.println(h, 2);
myFile.println("Temperature(*C)");
myFile.println(t, 2);
myFile.println();
// close the file:
myFile.close();
// Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
delay (60000);
// re-open the file for reading:
myFile = SD.open("test.txt");
if (myFile) {
Serial.println("test.txt:");
// lcd.println("test.txt:");
// read from the file until there's nothing else in it:
while (myFile.available()) {
Serial.write(myFile.read());
}
}
EthernetClient client = server.available(); // try to get client
if (client) { // got client?
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) { // client data available to read
char c = client.read(); // read 1 byte (character) from client
// last line of client request is blank and ends with \n
// respond to client only after last line received
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
// client.println("Refresh: 5"); // refresh the page automatically every 60 sec
client.println();
client.println("");
client.println("");
client.println("
");
// send web page
webFile = SD.open("test.txt"); // open web page file
if (webFile) {
while (webFile.available()) {
client.write(webFile.read()); // send web page to client
}
webFile.close();
}
break;
//client.println("Refresh: 5");
}
// every line of text received from the client ends with \r\n
if (c == '\n') {
// last character on line of received text
// starting new line with next character read
currentLineIsBlank = true;
}
else if (c != '\r') {
// a text character was received from client
currentLineIsBlank = false;
}
} // end if (client.available())
} // end while (client.connected())
delay(1); // give the web browser time to receive the data
client.stop();// close the connection
}
}

// re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");
   // lcd.println("test.txt:");
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
  }
    // close the file:
    myFile.close();

Try closing the file in this section of code.

Hey
i tried to close myfile in the reopening section ,but it still not working after 12 minutes.i tried for the combination of sd&ethernet,sd and lcd,in these combination also its showing error after 12 minutes. I think Float is converted to string the problem can be solved.IN this pgm how to convert the float to string.Can anyone pls suggest methods to slove these problem.

I think Float is converted to string the problem can be solved.IN this pgm how to convert the float to string.Can anyone pls suggest methods to slove these problem.

I do not believe that this is related to your problem. The two float variables h and t are stored in the SD card as character strings by the myFile.print() statements

myFile.println("humidity(%)");
    myFile.println(h, 2);
    myFile.println("Temperature(*C)");
    myFile.println(t, 2);

This problem sounds like some kind of memory problem. There is really no need for the two File objects.

File myFile;
File webFile;

I would try remove the declaration of webFile, as it is re-opening "test.txt." You can send the same data with myFile.

// send web page
          myFile = SD.open("test.txt");        // open web page file
          if (myFile) {
            while (myFile.available()) {
              client.write(myFile.read()); // send web page to client
            }
            myFile.close();
          }

EDIT 9:30 6/9/15 You have declared File myFile twice. Once globally, and once in the loop. I would only use one of these.

HI,
I used software reset option now its working.Is there any method to dividing time for lcd,sd,ethernet.In my pgm while writing in sd ,lcd is not taking any value.but i want to take lcd the continous values from sensor.is there any timer option?