Advertisement
Guest User

FALTA RTC

a guest
Jun 9th, 2015
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.55 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <SD.h>
  3. #include <Wire.h>
  4. #include <RTClib.h>
  5. #include <dht.h>
  6. #include <OneWire.h>
  7. #include <DallasTemperature.h>
  8.  
  9. #define ONE_WIRE_BUS 10
  10. #define dht_dpin A1 //Pino DATA do Sensor ligado na porta Analogica A1
  11.  
  12.  
  13. RTC_DS1307 RTC;
  14. dht DHT; //Inicializa o sensor
  15. const int chipSelect = 53;
  16. OneWire oneWire(ONE_WIRE_BUS);
  17. DallasTemperature sensors(&oneWire);
  18. DeviceAddress vermelho_1_Thermometer = { 0x28, 0xFF, 0xB8, 0x67, 0x56, 0x14, 0x03, 0xB0 };
  19. DeviceAddress azul_1_Thermometer = { 0x28, 0xFF, 0x5B, 0x45, 0x64, 0x14, 0x04, 0x41 };
  20.  
  21.  
  22. float tempC;                          // modifiquei aqui
  23. float tempA;                          // modifiquei aqui
  24. float tempV;                          // modifiquei aqui
  25.  
  26.  
  27. void setup(void)
  28. {
  29.   Serial.begin(9600);
  30.   Wire.begin();//Inicializacao do protocolo wire
  31.   RTC.begin();//Inicializacao do modulo RTC
  32.   DateTime now;
  33.   delay (1000);
  34.   //Verifica se o modulo esta funcionando ou nao
  35.   if (!RTC.isrunning()) {
  36.     Serial.println("RTC is NOT running!");
  37.     //Ajusta a data/hora do Clock com a data/hora em que o codigo foi compilado, basta descomentar a linha
  38.     //RTC.adjust(DateTime(2015,6,9,17,9,40));
  39.   }
  40.    
  41.     Serial.print("Initializing SD card...");
  42.  
  43.   // see if the card is present and can be initialized:
  44.   if (!SD.begin(chipSelect)) {
  45.     Serial.println("Card failed, or not present");
  46.     // don't do anything more:
  47.     return;
  48.   }
  49.  
  50.  
  51.   sensors.begin();
  52.   sensors.setResolution(vermelho_1_Thermometer, 10);
  53.   sensors.setResolution(azul_1_Thermometer, 10);
  54. }
  55.  
  56. void printTemperature(DeviceAddress deviceAddress)
  57. {
  58. //  float tempC = sensors.getTempC(deviceAddress);       // modifiquei aqui
  59.    tempC = sensors.getTempC(deviceAddress);              // modifiquei aqui
  60.   if (tempC == -127.00)
  61.   {
  62.     Serial.print("Erro ao ler temperatura !");
  63.   }
  64.   else
  65.   {
  66.     Serial.print(" C: ");
  67.     Serial.print(tempC);
  68.     Serial.print(" F: ");
  69.     Serial.print(DallasTemperature::toFahrenheit(tempC));
  70.   }
  71. }
  72.  
  73. void loop(void)
  74. {
  75.  
  76.    // make a string for assembling the data to log:
  77.   String dataString = "";
  78.  
  79.   // read one sensor and append to the string:
  80.   for (int analogPin = 0; analogPin < 3; analogPin++) {
  81.     int sensor = analogRead(analogPin);
  82.     dataString += String(sensor);
  83.     if (analogPin < 2) {
  84.       dataString += ",";
  85.     }
  86.   }
  87.  
  88.   // open the file. note that only one file can be open at a time,
  89.   // so you have to close this one before opening another.
  90.   File dataFile = SD.open("datalog.csv", FILE_WRITE);
  91.  
  92.   // if the file is available, write to it:
  93.   if (dataFile) {
  94.  
  95.     dataFile.println();
  96.    
  97.     dataFile.println("Temperature,Umidade");
  98.    
  99.     dataFile.println(DHT.temperature);
  100.    
  101.     dataFile.println(DHT.humidity);
  102.    
  103.     dataFile.println("TemperatureSensor1, TemperatureSensor2");
  104.  
  105.     dataFile.println(tempV);
  106.    
  107.     dataFile.println(tempA);
  108.    
  109.     dataFile.close();
  110.     // print to the serial port too:
  111.     Serial.println();
  112.   }
  113.   // if the file isn't open, pop up an error:
  114.   else {
  115.     Serial.println("error opening datalog.csv");
  116.   }
  117.  
  118.  
  119.  
  120.   {
  121.    DateTime now = RTC.now();//Recuperando a data e hora atual
  122.    Serial.print(now.day(), DEC);//Imprimindo o dia
  123.    Serial.print('/');
  124.    Serial.print(now.month(), DEC);//Recuperando o mes
  125.    Serial.print('/');
  126.    Serial.print(now.year(), DEC);//Recuperando o ano
  127.    Serial.print(' ');
  128.    Serial.print(now.hour(), DEC);//Recuperando a hora
  129.    Serial.print(':');
  130.    Serial.print(now.minute(), DEC);//Recuperando os minutos
  131.    Serial.print(':');
  132.    Serial.print(now.second(), DEC);//Recuperando os segundos
  133.    Serial.println();
  134.  
  135.  
  136.  
  137.   DHT.read11(dht_dpin); //Lê as informações do sensor
  138.   Serial.print("SENSOR DHT11:\n\r");
  139.   Serial.print("Umidade = ");
  140.   Serial.print(DHT.humidity);
  141.   Serial.print(" %  ");
  142.   Serial.print("Temperatura = ");
  143.   Serial.print(DHT.temperature);
  144.   Serial.println(" Celsius  ");
  145.  
  146.   {  
  147.   delay(3000);
  148.   Serial.print("SENSOR DS18B20:\n\r");
  149.   sensors.requestTemperatures();
  150.   Serial.print("Temperatura Sensor 1: ");
  151.   printTemperature(vermelho_1_Thermometer);
  152.   tempV = tempC;                                  // modifiquei aqui
  153.   Serial.print("\n\r");
  154.   Serial.print("Temperatura Sensor 2: ");
  155.   printTemperature(azul_1_Thermometer);
  156.   tempA = tempC;                                  // modifiquei aqui
  157.   Serial.print("\n\r");
  158.  
  159.   delay(1000);//Aguarda 1 seg antes de acessar as informações do sensor
  160. }
  161.  
  162.  
  163.   //Não diminuir o valor abaixo. O ideal é a leitura a cada 2 segundos
  164.   delay(4000);
  165.  }
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement