Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.38 KB | None | 0 0
  1. // Programa : Leitor temperatura sensores DS18B20
  2. // Alterações : Arduino e Cia
  3. // Este programa usa o endereço físico de cada sensor para mostrar as
  4. // informações de temperatura no Serial Monitor
  5.  
  6. #include <OneWire.h>
  7. #include <DallasTemperature.h>
  8.  
  9. //Carrega a biblioteca LiquidCrystal
  10. #include <LiquidCrystal_I2C.h>
  11.  
  12.  
  13.  
  14.  
  15. // Conectar o pino central dos sensores ao pino 10 do Arduino
  16. #define ONE_WIRE_BUS 10
  17.  
  18. // Setup a oneWire instance to communicate with any OneWire devices
  19. OneWire oneWire(ONE_WIRE_BUS);
  20.  
  21.  
  22. volatile int flow_frequency; // Measures flow meter pulses
  23. unsigned int l_hour; // Calculated litres/hour
  24. unsigned char flowmeter = 2; // Flow Meter Pin number
  25. unsigned long currentTime;
  26. unsigned long cloopTime;
  27.  
  28. float tempMin = 999;
  29. float tempMax = 0;
  30.  
  31. // Pass our oneWire reference to Dallas Temperature.
  32. DallasTemperature sensors(&oneWire);
  33. DeviceAddress S1 = { 0x28, 0xEE, 0x05, 0xC5, 0x21, 0x16, 0x02, 0x8B };
  34. DeviceAddress S2 = { 0x28, 0xEE, 0xE7, 0x34, 0x24, 0x16, 0x02, 0x19 };
  35. DeviceAddress S3 = { 0x28, 0xEE, 0xC3, 0x39, 0x27, 0x16, 0x01, 0x65 };
  36. DeviceAddress S4 = { 0x28, 0xEE, 0x97, 0xA1, 0x27, 0x16, 0x01, 0x12 };
  37.  
  38. //Define os pinos que serão utilizados para ligação ao display
  39. LiquidCrystal_I2C lcd(0x3F,16,2);
  40.  
  41. void flow () // Interruot function
  42. {
  43. flow_frequency++;
  44. }
  45.  
  46. void setup(void)
  47. {
  48. // start serial port
  49. Serial.begin(9600);
  50. // Start up the library
  51. sensors.begin();
  52. // set the resolution to 10 bit (good enough?)
  53. sensors.setResolution(S1, 10);
  54. sensors.setResolution(S2, 10);
  55. sensors.setResolution(S3, 10);
  56. sensors.setResolution(S4, 10);
  57. lcd.init();
  58. lcd.backlight();
  59. lcd.begin(16, 2);
  60.  
  61. pinMode(flowmeter, INPUT);
  62. Serial.begin(9600);
  63. attachInterrupt(0, flow, RISING); // Setup Interrupt
  64. // see http://arduino.cc/en/Reference/attachInterrupt
  65. sei(); // Enable interrupts
  66. currentTime = millis();
  67. cloopTime = currentTime;
  68. }
  69.  
  70. void printTemperature(DeviceAddress deviceAddress)
  71. {
  72. float tempC = sensors.getTempC(deviceAddress);
  73. if (tempC == -127.00)
  74. {
  75. Serial.print("Erro ao ler temperatura !");
  76. }
  77. else
  78. {
  79. Serial.print("C: ");
  80. Serial.print(tempC);
  81. Serial.print(" F: ");
  82. Serial.print(DallasTemperature::toFahrenheit(tempC));
  83. }
  84. }
  85.  
  86. float corrigeTemp(int sensor, float tempValor){
  87. float tempCorrigida = 0;
  88. if(sensor == 1){
  89. tempCorrigida = 1.0065*tempValor + 0.9512;
  90. }
  91.  
  92. if(sensor == 2){
  93. tempCorrigida = 1.0011*tempValor + 1.0846;
  94. }
  95.  
  96. if(sensor == 3){
  97. tempCorrigida = 1.0032*tempValor + 1.1469;
  98. }
  99.  
  100. if(sensor == 4){
  101. tempCorrigida = 1.007*tempValor + 0.8989;
  102. }
  103.  
  104. return tempCorrigida;
  105. }
  106.  
  107. void loop(void)
  108. {
  109.  
  110.  
  111. sensors.requestTemperatures();
  112. float tempC = sensors.getTempC(S1);
  113.  
  114. tempC = corrigeTemp(1, tempC);
  115.  
  116. // Atualiza temperaturas minima e maxima
  117. if (tempC < tempMin)
  118. {
  119. tempMin = tempC;
  120. }
  121. if (tempC > tempMax)
  122. {
  123. tempMax = tempC;
  124. }
  125.  
  126. //////////////
  127. //Limpa a tela
  128.  
  129. tempC = sensors.getTempC(S1);
  130. tempC = corrigeTemp(1, tempC);
  131.  
  132. float tempC2 = sensors.getTempC(S2);
  133. tempC2 = corrigeTemp(2, tempC2);
  134.  
  135. float tempC3 = sensors.getTempC(S3);
  136. tempC3 = corrigeTemp(3, tempC3);
  137.  
  138. float tempC4 = sensors.getTempC(S4);
  139. tempC4 = corrigeTemp(4, tempC4);
  140.  
  141. lcd.clear();
  142. lcd.setCursor(0,0);
  143. lcd.print("T1:");
  144. lcd.print(tempC);
  145. lcd.print("T2:");
  146. lcd.print(tempC2);
  147. lcd.setCursor(0,1);
  148. lcd.print("T3:");
  149. lcd.print(tempC3);
  150. lcd.print("T4:");
  151. lcd.print(tempC4);
  152. delay(5000);
  153. currentTime = millis();
  154. // Every second, calculate and print litres/hour
  155. if(currentTime >= (cloopTime + 1000))
  156. {
  157. cloopTime = currentTime; // Updates cloopTime
  158. // Pulse frequency (Hz) = 7.5Q, Q is flow rate in L/min. (Results in +/- 3% range)
  159. l_hour = (flow_frequency * 60 / 7.5); // (Pulse frequency x 60 min) / 7.5Q = flow rate in L/hour
  160. flow_frequency = 0; // Reset Counter
  161. l_hour = 0.5216*l_hour+6.3494;
  162. Serial.print(l_hour, DEC); // Print litres/hour
  163. Serial.println(" L/hour");
  164. lcd.clear();
  165. lcd.setCursor(0,0);
  166. lcd.print(l_hour, DEC);
  167. lcd.print(" L/hour");
  168. delay(5000);
  169. }
  170.  
  171.  
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement