Przeszukaj forum
Pokazywanie wyników dla tagów 'Hallsensor'.
Znaleziono 1 wynik
-
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 arduino mega ? 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 te przerwania (pin 2 i 3) . Czy jest może możliwość obsługi tych czujników przez arduino nano i np.funkcję pinchange? jeżeli tak to byłbym wdzięczy za przykład z zainicjowaniem dodatkowych 2 czujników. Kod na którym obecnie się opieram to 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(); }
- 8 odpowiedzi
-
- flowmeter
- water flow
- (i 2 więcej)