Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <RTClib.h>
- #include <dht.h>
- #include <OneWire.h>
- #include <DallasTemperature.h>
- //Programa : Sensor de umidade e temperatura DHT11/Cartão SD/Dois sensores de temperatura DS18B20
- //Autor : Gustavo Okano Alves Pinto
- #define ONE_WIRE_BUS 10
- #define dht_dpin A1 //Pino DATA do Sensor ligado na porta Analogica A1
- RTC_DS1307 RTC;
- dht DHT; //Inicializa o sensor
- OneWire oneWire(ONE_WIRE_BUS);
- DallasTemperature sensors(&oneWire);
- DeviceAddress vermelho_1_Thermometer = { 0x28, 0xFF, 0xB8, 0x67, 0x56, 0x14, 0x03, 0xB0 };
- DeviceAddress azul_1_Thermometer = { 0x28, 0xFF, 0x5B, 0x45, 0x64, 0x14, 0x04, 0x41 };
- float tempC; // modifiquei aqui
- float tempA; // modifiquei aqui
- float tempV; // modifiquei aqui
- void setup(void)
- {
- Serial.begin(9600);
- Wire.begin();//Inicializacao do protocolo wire
- RTC.begin();//Inicializacao do modulo RTC
- delay (1000);
- //Verifica se o modulo esta funcionando ou nao
- if (!RTC.isrunning()) {
- Serial.println("RTC is NOT running!");
- //Ajusta a data/hora do Clock com a data/hora em que o codigo foi compilado, basta descomentar a linha
- RTC.adjust(DateTime(2015,6,5,17,27,10));
- }
- sensors.begin();
- sensors.setResolution(vermelho_1_Thermometer, 10);
- sensors.setResolution(azul_1_Thermometer, 10);
- }
- void printTemperature(DeviceAddress deviceAddress)
- {
- // float tempC = sensors.getTempC(deviceAddress); // modifiquei aqui
- tempC = sensors.getTempC(deviceAddress); // modifiquei aqui
- if (tempC == -127.00)
- {
- Serial.print("Erro ao ler temperatura !");
- }
- else
- {
- Serial.print("C: ");
- Serial.print(tempC);
- Serial.print(" F: ");
- Serial.print(DallasTemperature::toFahrenheit(tempC));
- }
- }
- void loop(void)
- {
- {
- DateTime now = RTC.now();//Recuperando a data e hora atual
- Serial.print(now.day(), DEC);//Imprimindo o dia
- Serial.print('/');
- Serial.print(now.month(), DEC);//Recuperando o mes
- Serial.print('/');
- Serial.print(now.year(), DEC);//Recuperando o ano
- Serial.print(' ');
- Serial.print(now.hour(), DEC);//Recuperando a hora
- Serial.print(':');
- Serial.print(now.minute(), DEC);//Reci[erando os minutos
- Serial.print(':');
- Serial.print(now.second(), DEC);//Recuperando os segundos
- Serial.println();
- DHT.read11(dht_dpin); //Lê as informações do sensor
- Serial.print("SENSOR DHT11:\n\r");
- Serial.print("Umidade = ");
- Serial.print(DHT.humidity);
- Serial.print(" % ");
- Serial.print("Temperatura = ");
- Serial.print(DHT.temperature);
- Serial.println(" Celsius ");
- {
- delay(3000);
- Serial.print("SENSOR DS18B20:\n\r");
- sensors.requestTemperatures();
- Serial.print("Temperatura Sensor 1: ");
- printTemperature(vermelho_1_Thermometer);
- tempV = tempC; // modifiquei aqui
- Serial.print("\n\r");
- Serial.print("Temperatura Sensor 2: ");
- printTemperature(azul_1_Thermometer);
- tempA = tempC; // modifiquei aqui
- Serial.print("\n\r");
- delay(1000);//Aguarda 1 seg antes de acessar as informações do sensor
- }
- //Não diminuir o valor abaixo. O ideal é a leitura a cada 2 segundos
- delay(4000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement