Advertisement
RuiViana

1Wire_C_ROM_LCD

Oct 25th, 2015
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1.  
  2. #include <OneWire.h>
  3. #include <DallasTemperature.h>
  4. #include <LiquidCrystal.h>
  5. // Inicializa o LCD
  6. LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
  7.  
  8. #define ONE_WIRE_BUS_A 8
  9.  
  10. OneWire oneWire_1(ONE_WIRE_BUS_A);
  11. DallasTemperature sensors_A(&oneWire_1);
  12.  
  13. // Coloque aqui os Nos. de serie dos sensores
  14. // DeviceAddress Sensor_1 = { 0x28, 0xE9, 0x9A, 0xEF, 0x06, 0x00, 0x00, 0xA9 }; // Meu
  15. // 28 FF 0F C8 71 14 04 F0
  16. DeviceAddress Sensor_1 = { 0x28, 0xFF, 0x0F, 0xC8, 0x71, 0x14, 0x04, 0xF0 }; // AFM
  17. float tempA;
  18.  
  19. //--------------------------------------- setup ------------------------------------
  20. void setup(void)
  21. {
  22. lcd.begin(16, 4); // Diz para o Arduino que o display é 16x2.
  23. Serial.begin(9600);
  24. delay (100);
  25. sensors_A.begin();
  26. sensors_A.setResolution(Sensor_1, 10);
  27. }
  28. //--------------------------------------- Calc temperature ------------------------------------
  29. void printTemperature(float temp)
  30. {
  31. if (temp == -127.00)
  32. {
  33. Serial.print("Erro ao ler temperatura !");
  34. }
  35. else
  36. {
  37. Serial.print("C: ");
  38. Serial.print(temp);
  39. }
  40. }
  41. //--------------------------------------- loop ------------------------------------
  42. void loop(void)
  43. {
  44. Serial.print("SENSOR DS18B20:");
  45. sensors_A.requestTemperatures();
  46. Serial.print("Sensor 1: ");
  47. tempA = sensors_A.getTempC(Sensor_1);
  48. printTemperature(tempA);
  49. Serial.print("\n\r");
  50.  
  51. lcd.setCursor(0,0);
  52. lcd.print(" ");
  53. lcd.setCursor(0,0);
  54. lcd.print(tempA);
  55. delay(1000); // Aguarda 1 seg antes de acessar as informações do sensor
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement