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
- #include <OneWire.h>
- #include <DallasTemperature.h>
- //Carrega a biblioteca LiquidCrystal
- #include <LiquidCrystal_I2C.h>
- // Conectar o pino central dos sensores ao pino 10 do Arduino
- #define ONE_WIRE_BUS 10
- // Setup a oneWire instance to communicate with any OneWire devices
- OneWire oneWire(ONE_WIRE_BUS);
- 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;
- float tempMin = 999;
- float tempMax = 0;
- // Pass our oneWire reference to Dallas Temperature.
- DallasTemperature sensors(&oneWire);
- DeviceAddress S1 = { 0x28, 0xEE, 0x05, 0xC5, 0x21, 0x16, 0x02, 0x8B };
- DeviceAddress S2 = { 0x28, 0xEE, 0xE7, 0x34, 0x24, 0x16, 0x02, 0x19 };
- DeviceAddress S3 = { 0x28, 0xEE, 0xC3, 0x39, 0x27, 0x16, 0x01, 0x65 };
- DeviceAddress S4 = { 0x28, 0xEE, 0x97, 0xA1, 0x27, 0x16, 0x01, 0x12 };
- //Define os pinos que serão utilizados para ligação ao display
- LiquidCrystal_I2C lcd(0x3F,16,2);
- void flow () // Interruot function
- {
- flow_frequency++;
- }
- void setup(void)
- {
- // start serial port
- Serial.begin(9600);
- // Start up the library
- sensors.begin();
- // set the resolution to 10 bit (good enough?)
- sensors.setResolution(S1, 10);
- sensors.setResolution(S2, 10);
- sensors.setResolution(S3, 10);
- sensors.setResolution(S4, 10);
- 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;
- }
- void printTemperature(DeviceAddress deviceAddress)
- {
- float tempC = sensors.getTempC(deviceAddress);
- 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));
- }
- }
- float corrigeTemp(int sensor, float tempValor){
- float tempCorrigida = 0;
- if(sensor == 1){
- tempCorrigida = 1.0065*tempValor + 0.9512;
- }
- if(sensor == 2){
- tempCorrigida = 1.0011*tempValor + 1.0846;
- }
- if(sensor == 3){
- tempCorrigida = 1.0032*tempValor + 1.1469;
- }
- if(sensor == 4){
- tempCorrigida = 1.007*tempValor + 0.8989;
- }
- return tempCorrigida;
- }
- void loop(void)
- {
- sensors.requestTemperatures();
- float tempC = sensors.getTempC(S1);
- tempC = corrigeTemp(1, tempC);
- // Atualiza temperaturas minima e maxima
- if (tempC < tempMin)
- {
- tempMin = tempC;
- }
- if (tempC > tempMax)
- {
- tempMax = tempC;
- }
- //////////////
- //Limpa a tela
- tempC = sensors.getTempC(S1);
- tempC = corrigeTemp(1, tempC);
- float tempC2 = sensors.getTempC(S2);
- tempC2 = corrigeTemp(2, tempC2);
- float tempC3 = sensors.getTempC(S3);
- tempC3 = corrigeTemp(3, tempC3);
- float tempC4 = sensors.getTempC(S4);
- tempC4 = corrigeTemp(4, tempC4);
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print("T1:");
- lcd.print(tempC);
- lcd.print("T2:");
- lcd.print(tempC2);
- lcd.setCursor(0,1);
- lcd.print("T3:");
- lcd.print(tempC3);
- lcd.print("T4:");
- lcd.print(tempC4);
- delay(5000);
- 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 = 0.5216*l_hour+6.3494;
- 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(5000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement