Advertisement
RuiViana

Sensores.ino

Apr 7th, 2021
919
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.29 KB | None | 0 0
  1.  
  2. #include <OneWire.h>
  3. #include <DallasTemperature.h>
  4.  
  5. #include <max6675.h>
  6.  
  7. // Definições: GPIOs do Arduino max6675
  8. #define GPIO_SO       8
  9. #define GPIO_CS       9
  10. #define GPIO_CLK      10
  11. // Porta do pino de sinal do DS18B20
  12. #define ONE_WIRE_BUS 3
  13.  
  14. MAX6675 termopar(GPIO_CLK, GPIO_CS, GPIO_SO);
  15.  
  16. OneWire oneWire(ONE_WIRE_BUS);
  17.  
  18. float tempMin = 999;
  19. float tempMax = 0;
  20.  
  21. DallasTemperature sensors(&oneWire);
  22. DeviceAddress sensor1;
  23. //--------------------------------------------------------------------------
  24. void setup(void)
  25. {
  26.   Serial.begin(115200);
  27.   sensors.begin();
  28.   // Localiza e mostra enderecos dos sensores
  29.   Serial.println("Localizando sensores DS18B20...");
  30.   Serial.print("Foram encontrados ");
  31.   Serial.print(sensors.getDeviceCount(), DEC);
  32.   Serial.println(" sensores.");
  33.   if (!sensors.getAddress(sensor1, 0))
  34.     Serial.println("Sensores nao encontrados !");
  35.   // Mostra o endereco do sensor encontrado no barramento
  36.   Serial.print("Endereco sensor: ");
  37.   mostra_endereco_sensor(sensor1);
  38.   Serial.println();
  39.   Serial.println();
  40. }
  41. //--------------------------------------------------------------------------
  42. void mostra_endereco_sensor(DeviceAddress deviceAddress)
  43. {
  44.   for (uint8_t i = 0; i < 8; i++)
  45.   {
  46.     // Adiciona zeros se necessário
  47.     if (deviceAddress[i] < 16) Serial.print("0");
  48.     Serial.print(deviceAddress[i], HEX);
  49.   }
  50. }
  51. //--------------------------------------------------------------------------
  52. void loop()
  53. {
  54.   // rotina max6675
  55.   Serial.print("Temperatura max6675:  ");
  56.   Serial.print(termopar.readCelsius());
  57.   Serial.println("C");
  58.   delay(1000);
  59.  
  60.   // rotina DS18B20
  61.   sensors.requestTemperatures();
  62.   float tempC = sensors.getTempC(sensor1);
  63.   // Atualiza temperaturas minima e maxima
  64.   if (tempC < tempMin)
  65.   {
  66.     tempMin = tempC;
  67.   }
  68.   if (tempC > tempMax)
  69.   {
  70.     tempMax = tempC;
  71.   }
  72.   // Mostra dados no serial monitor
  73.   Serial.print("Temp 18b20 C: ");
  74.   Serial.print(tempC);
  75.   Serial.print(" Min 18b20: ");
  76.   Serial.print(tempMin);
  77.   Serial.print(" Max 18b20: ");
  78.   Serial.println(tempMax);
  79.  
  80.   Serial.print("Temp. 18b20:       ");
  81.   Serial.print("C 18b20");
  82.   Serial.println(tempC);
  83.   Serial.print("L: 18b20");
  84.   Serial.print(tempMin, 1);
  85.   Serial.print("H: 18b20");
  86.   Serial.println(tempMax, 1);
  87.   delay(3000);
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement