Advertisement
peterzig

arduino 16x2 temperatura

Oct 11th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. //YWROBOT
  2. //Compatible with the Arduino IDE 1.0
  3. //Library version:1.1
  4. #include <Wire.h>
  5. #include <LiquidCrystal_I2C.h>
  6. //Include libraries
  7. #include <OneWire.h>
  8. #include <DallasTemperature.h>
  9.  
  10. // Data wire is plugged into pin 2 on the Arduino
  11. #define ONE_WIRE_BUS 2
  12. // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
  13. OneWire oneWire(ONE_WIRE_BUS);
  14. // Pass our oneWire reference to Dallas Temperature.
  15. DallasTemperature sensors(&oneWire);
  16.  
  17. LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display
  18.  
  19. void setup()
  20. {
  21.  
  22.   Serial.begin(9600); //Begin serial communication
  23.   Serial.println("Arduino Digital Temperature // Serial Monitor Version"); //Print a message
  24.   sensors.begin();  
  25.   lcd.init();                      // initialize the lcd
  26.   lcd.init();
  27.   // Print a message to the LCD.
  28.   lcd.backlight();
  29.   lcd.setCursor(0,0);
  30.   lcd.print("Temperatura: ");
  31.   lcd.setCursor(0,1);
  32. }
  33.  
  34.  
  35. void loop()
  36. {
  37.   lcd.setCursor(0,1);
  38.   lcd.println(sensors.getTempCByIndex(0));
  39.   lcd.setCursor(5,1);
  40.   lcd.print("\337C");
  41.   lcd.setCursor(0,1);
  42.   sensors.requestTemperatures();  
  43.   Serial.print("Temperature is: ");
  44.   Serial.println(sensors.getTempCByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
  45.   //Update value every 1 sec.
  46.   delay(2000);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement