Professional Documents
Culture Documents
Data Logger For Arduino PDF
Data Logger For Arduino PDF
//PhotoResistor Pin
int lightPin = 1; //the analog pin the photoresistor is connected to the photoresistor is not calibrated to any units so this is simply a raw sensor value (relative light)
Arduino Page 1
RTC_DS1307 RTC; // define the Real Time Clock object
//========================================================
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16,2);
Serial.begin(9600); //Start the serial connection with the copmuter
//to view the result open the serial monitor
//last button beneath the file bar (looks like a box with an antena
pinMode(lcdRed, INPUT); //sets the led pin to input
pinMode(lcdBlue, INPUT); //sets the led pin to input
Wire.begin();
RTC.begin();
//----------------------------------------
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
//-------------------------------
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(SS, OUTPUT);
//=========================================================
void loop() {
float temperature = getVoltage(temperaturePin); //getting the voltage reading from the temperature sensor
temperature = ((temperature - .5) * 100)*1.8+32; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((volatge - 500mV) times 100)
// Serial.println(temperature); //printing the result
// delay(500); //waiting a second
Arduino Page 2
// delay(500); //waiting a second
//------------------------
int lightLevel = analogRead(lightPin); //Read the
lightLevel = map(lightLevel, 0, 900, 0, 150); //adjust the value 0 to 900 to span 0 to 255
lightLevel = constrain(lightLevel, 0, 150); //make sure the value is betwween 0 and 255
//////
int tempLevel = analogRead(temperaturePin)*100; //Read the
tempLevel = map(tempLevel, 66, 82, 0, 150); //adjust the value 0 to 900 to span 0 to 255
tempLevel = constrain(tempLevel, 0, 150); //make sure the value is betwween 0 and 255
analogWrite(lcdBlue, lightLevel); //write the value
analogWrite(lcdRed, tempLevel); //write the value
//-----------------------------------------------------------
//-------------------------------------------------------
//logfile.println("");
//----------------
/*
// read sensors and append to the string:
for (int analogPin = 0; analogPin < 2; analogPin++) {
int sensor = analogRead(analogPin);
dataString += String(sensor);
if (analogPin < 1) {
dataString += ",";
}
}
*/
// dataFile.println(dataString);
logfile.println(dataString);
// Serial.println(dataString);
// dataFile.flush();
logfile.flush();
//-----------------------------------------------------------
// set the cursor to (0,0):
lcd.setCursor(0, 0);
// print from 0 to 9:
// for (int thisChar = 0; thisChar < 10; thisChar++) {
lcd.print(temperature);
// lcd.print(myString);
lcd.setCursor(0, 1);
lcd.print(lightLevel);
lcd.setCursor(8, 0);
lcd.print("Temp"); //display temp on the lcd
lcd.setCursor(8, 1);
Arduino Page 3
lcd.setCursor(8, 1);
lcd.print("Light"); //display light on the lcd
delay(500);
//---------------------lcd backlight
// lightLevel = constrain(lightLevel, 0, 255);//make sure the
//value is betwween
//0 and 255
//------------------------------------------------------------
//==========================================================
float getVoltage(int pin){
return (analogRead(pin) * .004882814); //converting from a 0 to 1023 digital range
// to 0 to 5 volts (each 1 reading equals ~ 5 millivolts
}
Arduino Page 4