Advertisement
RuiViana

Untitled

Jun 4th, 2015
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #include <Wire.h>
  2.  
  3. #include <OneWire.h>
  4. #include <DallasTemperature.h>
  5.  
  6. #define ONE_WIRE_BUS 10
  7.  
  8. OneWire oneWire(ONE_WIRE_BUS);
  9. DallasTemperature sensors(&oneWire);
  10. // Coloque aqui os Nos. de serie dos sensores
  11. DeviceAddress Sensor_1 = { 0x28, 0xFF, 0x38, 0x50, 0x73, 0x04, 0x00, 0x1A };
  12.  
  13. float tempC;
  14. float tempV;
  15. //--------------------------------------- setup ------------------------------------
  16. void setup(void)
  17. {
  18. // Serial.begin(9600);
  19. Wire.begin(); //Inicializacao do protocolo wire
  20.  
  21. delay (1000);
  22.  
  23. sensors.begin();
  24. sensors.setResolution(Sensor_1, 10);
  25. }
  26. //--------------------------------------- Calc temperature ------------------------------------
  27. void printTemperature(DeviceAddress deviceAddress)
  28. {
  29. tempC = sensors.getTempC(deviceAddress);
  30. if (tempC == -127.00)
  31. {
  32. // Serial.print("Erro ao ler temperatura !");
  33. }
  34. else
  35. {
  36. // Serial.print("C: ");
  37. // Serial.print(tempC);
  38. }
  39. }
  40. //--------------------------------------- loop ------------------------------------
  41. void loop(void)
  42. {
  43. // Serial.print("SENSOR DS18B20:\n\r");
  44. sensors.requestTemperatures();
  45. // Serial.print("Temperatura Sensor 1: ");
  46. printTemperature(Sensor_1);
  47. tempV = tempC;
  48. delay(1000); // Aguarda 1 seg antes de acessar as informa��es do sensor
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement