Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Programa : Leitor temperatura sensores DS18B20
- // Alterações : Arduino e Cia
- // Este programa usa o endereço físico de cada sensor para mostrar as
- // informações de temperatura no Serial Monitor
- //Carrega a biblioteca LiquidCrystal
- #include <LiquidCrystal_I2C.h>
- //Define os pinos que serão utilizados para ligação ao display
- LiquidCrystal_I2C lcd(0x3F,16,2);
- volatile int flow_frequency; // Measures flow meter pulses
- unsigned int l_hour; // Calculated litres/hour
- unsigned char flowmeter = 2; // Flow Meter Pin number
- unsigned long currentTime;
- unsigned long cloopTime;
- void flow () // Interruot function
- {
- flow_frequency++;
- }
- void setup(void)
- {
- // start serial port
- Serial.begin(9600);
- lcd.init();
- lcd.backlight();
- lcd.begin(16, 2);
- pinMode(flowmeter, INPUT);
- Serial.begin(9600);
- attachInterrupt(0, flow, RISING); // Setup Interrupt
- // see http://arduino.cc/en/Reference/attachInterrupt
- sei(); // Enable interrupts
- currentTime = millis();
- cloopTime = currentTime;
- }
- float corrigeVazao(int lHour){
- float vazaoCorrigida = 0;
- vazaoCorrigida = 0.5216 * lHour + 6.3494;
- return vazaoCorrigida;
- }
- void loop(void)
- {
- currentTime = millis();
- // Every second, calculate and print litres/hour
- if(currentTime >= (cloopTime + 1000))
- {
- cloopTime = currentTime; // Updates cloopTime
- // Pulse frequency (Hz) = 7.5Q, Q is flow rate in L/min. (Results in +/- 3% range)
- l_hour = (flow_frequency * 60 / 7.5); // (Pulse frequency x 60 min) / 7.5Q = flow rate in L/hour
- flow_frequency = 0; // Reset Counter
- l_hour = corrigeVazao(l_hour);
- Serial.print(l_hour, DEC); // Print litres/hour
- Serial.println(" L/hour");
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print(l_hour, DEC);
- lcd.print(" L/hour");
- }
- delay(3000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement