Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 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. //Carrega a biblioteca LiquidCrystal
  7. #include <LiquidCrystal_I2C.h>
  8.  
  9.  
  10.  
  11.  
  12. //Define os pinos que serão utilizados para ligação ao display
  13. LiquidCrystal_I2C lcd(0x3F,16,2);
  14.  
  15.  
  16. volatile int flow_frequency; // Measures flow meter pulses
  17. unsigned int l_hour; // Calculated litres/hour
  18. unsigned char flowmeter = 2; // Flow Meter Pin number
  19. unsigned long currentTime;
  20. unsigned long cloopTime;
  21.  
  22.  
  23.  
  24. void flow () // Interruot function
  25. {
  26. flow_frequency++;
  27. }
  28.  
  29. void setup(void)
  30. {
  31. // start serial port
  32. Serial.begin(9600);
  33. lcd.init();
  34. lcd.backlight();
  35. lcd.begin(16, 2);
  36.  
  37. pinMode(flowmeter, INPUT);
  38. Serial.begin(9600);
  39. attachInterrupt(0, flow, RISING); // Setup Interrupt
  40. // see http://arduino.cc/en/Reference/attachInterrupt
  41. sei(); // Enable interrupts
  42. currentTime = millis();
  43. cloopTime = currentTime;
  44. }
  45.  
  46. float corrigeVazao(int lHour){
  47. float vazaoCorrigida = 0;
  48. vazaoCorrigida = 0.5216 * lHour + 6.3494;
  49.  
  50. return vazaoCorrigida;
  51. }
  52.  
  53. void loop(void)
  54. {
  55.  
  56.  
  57. currentTime = millis();
  58. // Every second, calculate and print litres/hour
  59. if(currentTime >= (cloopTime + 1000))
  60. {
  61. cloopTime = currentTime; // Updates cloopTime
  62. // Pulse frequency (Hz) = 7.5Q, Q is flow rate in L/min. (Results in +/- 3% range)
  63. l_hour = (flow_frequency * 60 / 7.5); // (Pulse frequency x 60 min) / 7.5Q = flow rate in L/hour
  64. flow_frequency = 0; // Reset Counter
  65. l_hour = corrigeVazao(l_hour);
  66. Serial.print(l_hour, DEC); // Print litres/hour
  67. Serial.println(" L/hour");
  68. lcd.clear();
  69. lcd.setCursor(0,0);
  70. lcd.print(l_hour, DEC);
  71. lcd.print(" L/hour");
  72. }
  73.  
  74. delay(3000);
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement