Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <OneWire.h>
- #include <DallasTemperature.h>
- #include <max6675.h>
- // Definições: GPIOs do Arduino max6675
- #define GPIO_SO 8
- #define GPIO_CS 9
- #define GPIO_CLK 10
- // Porta do pino de sinal do DS18B20
- #define ONE_WIRE_BUS 3
- MAX6675 termopar(GPIO_CLK, GPIO_CS, GPIO_SO);
- OneWire oneWire(ONE_WIRE_BUS);
- float tempMin = 999;
- float tempMax = 0;
- DallasTemperature sensors(&oneWire);
- DeviceAddress sensor1;
- //--------------------------------------------------------------------------
- void setup(void)
- {
- Serial.begin(115200);
- sensors.begin();
- // Localiza e mostra enderecos dos sensores
- Serial.println("Localizando sensores DS18B20...");
- Serial.print("Foram encontrados ");
- Serial.print(sensors.getDeviceCount(), DEC);
- Serial.println(" sensores.");
- if (!sensors.getAddress(sensor1, 0))
- Serial.println("Sensores nao encontrados !");
- // Mostra o endereco do sensor encontrado no barramento
- Serial.print("Endereco sensor: ");
- mostra_endereco_sensor(sensor1);
- Serial.println();
- Serial.println();
- }
- //--------------------------------------------------------------------------
- void mostra_endereco_sensor(DeviceAddress deviceAddress)
- {
- for (uint8_t i = 0; i < 8; i++)
- {
- // Adiciona zeros se necessário
- if (deviceAddress[i] < 16) Serial.print("0");
- Serial.print(deviceAddress[i], HEX);
- }
- }
- //--------------------------------------------------------------------------
- void loop()
- {
- // rotina max6675
- Serial.print("Temperatura max6675: ");
- Serial.print(termopar.readCelsius());
- Serial.println("C");
- delay(1000);
- // rotina DS18B20
- sensors.requestTemperatures();
- float tempC = sensors.getTempC(sensor1);
- // Atualiza temperaturas minima e maxima
- if (tempC < tempMin)
- {
- tempMin = tempC;
- }
- if (tempC > tempMax)
- {
- tempMax = tempC;
- }
- // Mostra dados no serial monitor
- Serial.print("Temp 18b20 C: ");
- Serial.print(tempC);
- Serial.print(" Min 18b20: ");
- Serial.print(tempMin);
- Serial.print(" Max 18b20: ");
- Serial.println(tempMax);
- Serial.print("Temp. 18b20: ");
- Serial.print("C 18b20");
- Serial.println(tempC);
- Serial.print("L: 18b20");
- Serial.print(tempMin, 1);
- Serial.print("H: 18b20");
- Serial.println(tempMax, 1);
- delay(3000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement