// ----------------------------------------------------------------- #include #include #include #include // Data wire is plugged into pin 7 on the Arduino #define ONE_WIRE_BUS 7 // Setup a oneWire instance to communicate with any OneWire devices // (not just Maxim/Dallas temperature ICs) OneWire oneWire(ONE_WIRE_BUS); // Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire); float temperature = 0.0; // ----------------------------------------------------------------- #include // Connections: // rs (LCD pin 4) to Arduino pin 12 // rw (LCD pin 5) to Arduino pin 11 // enable (LCD pin 6) to Arduino pin 10 // LCD pin 15 to Arduino pin 13 // LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2 LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2); int backLight = 13; // pin 13 will control the backlight // ----------------------------------------------------------------- //SD card const int sdPin = 9; File logFile; // ----------------------------------------------------------------- void setup(void) { // start serial port Serial.begin(9600); Serial.println("Dallas Temperature IC Control"); // Start up the library sensors.begin(); pinMode(backLight, OUTPUT); digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off. lcd.begin(16,2); // columns, rows. use 16,2 for a 16x2 LCD, etc. lcd.clear(); // start with a blank screen lcd.setCursor(0,0); // set cursor to column 0, row 0 (the first row) lcd.print("Dallas Temperature IC Control"); // change this text to whatever you like. keep it clean. lcd.setCursor(0,1); // set cursor to column 0, row 1 lcd.print("DS18B20"); delay(1000); if(!SD.begin(sdPin)) { Serial.println("Failed to initialize SD card"); // lcd.setCursor(0,0); // lcd.println("Init SD failed "); } else { Serial.println("SD initialized."); // lcd.setCursor(0,0); // lcd.println("Init SD success "); } delay(1000); } void loop(void) { // call sensors.requestTemperatures() to issue a global temperature // request to all devices on the bus Serial.print(" Requesting temperatures..."); sensors.requestTemperatures(); // Send the command to get temperatures Serial.println("DONE"); temperature = sensors.getTempCByIndex(0); Serial.print("Temperature for Device 1 is: "); Serial.println(temperature); // Why "byIndex"? // You can have more than one IC on the same bus. // 0 refers to the first IC on the wire lcd.setCursor(0,0); lcd.print(temperature); lcd.print("*C "); lcd.setCursor(0,1); lcd.print(millis()/1000); lcd.print(" sec "); logFile = SD.open("cookLog.txt", FILE_WRITE); logFile.print(millis()); logFile.print("\t"); logFile.println(temperature); logFile.close(); }