I am new user of arduino and I am using arduino with atmega 328, readings from LM35 and DS1307 will be outputed to a 16x2 LCD and at the same time to log the data( datetime+temp reading), the problem that I encountered is that I am unable to the ( datetime+temp reading) to the LCD display, as part of the troubleshooting to check if LCD is working...I disable the all the sketch that have something to do with the sd card logging by putting //...... then the LCD works perfectly without the SD logging.
The LCD connection: The RTC connection:
- LCD RS pin to digital pin 12 *RTC clock to analog pin 5
- LCD Enable pin to digital pin 11 *RTC clock to analog pin 4
- LCD D4 pin to digital pin 5
- LCD D5 pin to digital pin 4
- LCD D6 pin to digital pin 3
- LCD D7 pin to digital pin 2
The SD connection: The LM 35 connection:
*SD CLK to digital pin 13 *LM35 to analog pin 0
*SD DO to digital pin 12
*SD DI to digitalpin 11
*SD CS to digitalpin 10
this is my sketch:
#include <LiquidCrystal.h>
#include <SD.h>
#include <Wire.h>
#include <DS1307.h>
const int chipSelect = 4;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int pin = 0; // analog pin
int tempc = 0; // temperature variable
char dateTime[20];
int RTCValues[7];
void setup()
{
Serial.begin(9600);
DS1307.begin();
lcd.begin(16, 2);
Serial.print("Initializing SD card...");
pinMode(10, OUTPUT);
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
return;
}
Serial.println("card initialized.");
File dataFile = SD.open("datalog.csv", FILE_WRITE);
dataFile.print("DATE");
dataFile.print(",");
dataFile.print("TEMP");
dataFile.println(",");
}
void loop()
{
tempc = ( 5.0 * analogRead(pin) * 100.0) / 1024.0;
DS1307.getDate(RTCValues);
lcd.setCursor(0, 0);
sprintf(dateTime, "20%02d-%02d-%02d ", RTCValues[0],
RTCValues[1], RTCValues[2]);
lcd.print(dateTime);
lcd.setCursor(0, 1);
sprintf(dateTime, "%02d:%02d:%02d", RTCValues[4], RTCValues[5],
RTCValues[6]);
lcd.print(dateTime);
lcd.setCursor(11, 1);
lcd.print(tempc);
lcd.setCursor(13, 1);
lcd.print((char)223);
lcd.setCursor(14, 1);
lcd.print("C");
String dataString = "";
File dataFile = SD.open("datalog.csv", FILE_WRITE);
sprintf(dateTime, "20%02d-%02d-%02d %02d:%02d:%02d", RTCValues[0],
RTCValues[1], RTCValues[2], RTCValues[4], RTCValues[5],
RTCValues[6]);
dataString += String(dateTime);
dataFile.print(dataString);
dataFile.print(",");
dataFile.println(tempc);
dataFile.close();
Serial.print(dataString);
Serial.print("------>");
Serial.println(tempc,DEC);
delay(5000);
}
tularan5_1_sd_card.pde (1.72 KB)