• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Water flow sensor yf
#1
Witam 
Mam pytanie czy jest jakaś możliwość podłączenia 4 czujników przepływu (water flow sensor yf-s401) do arduino nano nie używając multipleksera ?
Sensor ten opiera się na czujniku Halla i do transmisji sygnału wykorzystuje przerwania. Problem w tym że arduino które posiadam mają tylko dwa piny obsługujące przerwania pin 2 i 3 .
Czy jest może możliwość obsługi tych czujników przez arduino nano i funkcję pinchange ?.
Będę bardzo wdzięczny za pomoc bo już od tygodnia nad tym myślę... Sad


byte sensorInterrupt_1 = 0;  // 0 = digital pin 2
byte sensorPin_1       = 2;

float calibrationFactor_1 = 5.5;
volatile byte pulseCount_1;
byte pulseCount1;//protected transfer
float flowRate_1;
unsigned int flowMilliLitres_1;
unsigned long totalMilliLitres_1;

unsigned long totalLitres_1;


//For FlowSensor_2   Ble
byte sensorInterrupt_2 = 1;  // 1 = digital pin 3
byte sensorPin_2       = 3;
//float calibrationFactor_2 = 5.44;
float calibrationFactor_2 = 6.44;
volatile byte pulseCount_2;
byte pulseCount2;//protected transfer
float flowRate_2;
unsigned int flowMilliLitres_2;
unsigned long totalMilliLitres_2;
unsigned long totalLitres_2;




//sensor reading and print timing
unsigned long readInterval = 1000;
unsigned long lastRead;


void setup() {

  Serial.begin(115200);

  //Setup_FlowSensor_1
  pinMode(sensorPin_1, INPUT);
  digitalWrite(sensorPin_1, HIGH);
  pulseCount_1        = 0;
  flowRate_1          = 0.0;
  flowMilliLitres_1   = 0;
  totalMilliLitres_1  = 0;
  totalLitres_1 = 0;
  attachInterrupt(sensorInterrupt_1, pulseCounter_1, FALLING);


  //Setup_FlowSensor_2
  pinMode(sensorPin_2, INPUT);
  digitalWrite(sensorPin_2, HIGH);
  pulseCount_2        = 0;
  flowRate_2          = 0.0;
  flowMilliLitres_2   = 0;
  totalMilliLitres_2  = 0;
  totalLitres_2 = 0;
  attachInterrupt(sensorInterrupt_2, pulseCounter_2, FALLING);


 
}

void flowSensors() {

  if ((millis() - lastRead) > readInterval)   // process counters once per second
  {
    lastRead += readInterval;
    noInterrupts();
    pulseCount1 = pulseCount_1;
    pulseCount_1 = 0;
    pulseCount2 = pulseCount_2;
    pulseCount_2 = 0;
   
    interrupts();

    flowRate_1 = (pulseCount1) / calibrationFactor_1;
    flowRate_2 = (pulseCount2) / calibrationFactor_2;
   

    flowMilliLitres_1 = (flowRate_1 / 60) * 1000;
    totalMilliLitres_1 += flowMilliLitres_1;
    totalLitres_1 = (totalMilliLitres_1 / 1000);

    flowMilliLitres_2 = (flowRate_2 / 60) * 1000;
    totalMilliLitres_2 += flowMilliLitres_2;
    totalLitres_2 = (totalMilliLitres_2 / 1000);


    Serial.print("FlowRate_1= ");
    Serial.print(flowRate_1);
    Serial.print("   Total_1= ");
    Serial.println(totalLitres_1);
    Serial.println("  ");
    //pulseCount_1 = 0;

    Serial.print("FlowRate_2= ");
    Serial.print(flowRate_2);
    Serial.print("   Total_2= ");
    Serial.println(totalLitres_2);
    Serial.println("  ");
    //pulseCount_2 = 0;

  }
}

void pulseCounter_1() {
  pulseCount_1++;
}

void pulseCounter_2() {
  pulseCount_2++;
}


void loop() {

  flowSensors();

}
 
Odpowiedź
  


Wiadomości w tym wątku
Water flow sensor yf - przez KarmelYeti - 02-12-2022, 15:44
RE: Water flow sensor yf - przez kaczakat - 02-12-2022, 16:03
RE: Water flow sensor yf - przez KarmelYeti - 02-12-2022, 22:36
RE: Water flow sensor yf - przez kaczakat - 02-12-2022, 23:29
RE: Water flow sensor yf - przez KarmelYeti - 12-12-2022, 13:24

Skocz do:


Przeglądający: 1 gości