Advertisement
AlexShu

Fridge Sensor

Aug 4th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.13 KB | None | 0 0
  1.  
  2. #include <Wire.h>  // Comes with Arduino IDE
  3.  
  4. #include <LiquidCrystal_I2C.h>
  5.  
  6. #include <OneWire.h>
  7. #include <DallasTemperature.h>
  8.  
  9. // Data wire is plugged into port 2 on the Arduino
  10. #define ONE_WIRE_BUS 2
  11.  
  12. // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
  13. OneWire oneWire(ONE_WIRE_BUS);
  14.  
  15. // Pass our oneWire reference to Dallas Temperature.
  16. DallasTemperature sensors(&oneWire);
  17. LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
  18.  
  19.  
  20.  
  21. void setup()
  22. {
  23.   Serial.begin(9600);  
  24.   sensors.begin();
  25.   lcd.begin(16,2);        
  26.   lcd.backlight();
  27.  
  28.  
  29.  
  30. }
  31.  
  32. void loop()
  33. {
  34.   sensors.requestTemperatures(); // Send the command to get temperatures
  35.  
  36.  
  37.   lcd.setCursor(0,0); //Start at character 4 on line 0
  38.   lcd.print("In: ");
  39.   lcd.print(sensors.getTempCByIndex(0),1);
  40.   lcd.write(223);
  41.   lcd.print("/ ");
  42.   lcd.print(sensors.getTempCByIndex(1),1);
  43.   lcd.write(223);
  44.  
  45.   lcd.setCursor(0,1); //Start at character 4 on line 0
  46.   lcd.print("Out: ");
  47.   lcd.print(sensors.getTempCByIndex(2),1);
  48.   lcd.write(223);
  49. delay(300);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement