Hi folks.
I hope I get the format correct, 1st time using the forum and I'm following the guide as best as possible.
I've a college project where I'm trying to control the speed of an inlet pump by the flow rate of the outlet pump. Outlet pump is controlled with a pot. each 24v pump is controlled via Mosfet PWM drivers capable of 30v. Outlet pump is 750L/hr and inlet pump is 1100L/hr. Flow meters are 0 - 60L/min calibration factor 7.8, pulse per litre 468. The issue I have is the inlet pump speed won't vary regardless of what speed the outlet pump is running at. In the code you'll notice some of the mapping figures are different than expected, I've been changing things looking for answers.
Thanks in advance,
Jay
```cpp
#include <LiquidCrystal.h>
//// Pin definitions ////
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
//Inputs
int outletFlowMeter = 2; //This is an interupt input pin on the Arduino
volatile float outflowRate; //This is the value we intend to calculate.
volatile long outletFlowcount; //This integer needs to be set as volatile to ensure it updates correctly during the interrupt process.
int inletFlowMeter = 3; //This is an interupt input pin on the Arduino
volatile float inflowRate;
volatile long inletFlowcount;
unsigned long lastTime; // Using internal timing for flow calculations
const float calibrationFactor = 7.8; // Calibration factor for the flow meters
const float pulsesPerLiter = 468.0; // Number of pulses per liter
int outPumpLevelControl = 7; //Outlet low level and Inlet high level limit switches wired in series.
int inPumpLevelControl = 4; //Inlet low level and Outlet high level limit switches wired in series.
int outletPot = A1; //Speed control for outlet pump.
int temperatureSensor = A2; //Inlet water temp.
//Outputs
int outletPump = 5; //PWM pump speed control
int inletPump = 6; //PWM pump speed control
void setup()
{
Serial.begin(9600); //Start serial monitor
lcd.begin(16, 4); //Start LCD display
pinMode(outletFlowMeter, INPUT);
pinMode(inletFlowMeter, INPUT);
pinMode(outPumpLevelControl, INPUT_PULLUP); //PULLUP to activate internal resistor
pinMode(inPumpLevelControl, INPUT_PULLUP); //PULLUP to activate internal resistor
pinMode(outletPot, INPUT);
pinMode(temperatureSensor, INPUT);
pinMode(inletPump, OUTPUT);
pinMode(outletPump, OUTPUT);
attachInterrupt(digitalPinToInterrupt(outletFlowMeter), outletFlowPulseIncrement, FALLING); // Interrupt for counting pulses, falling edge
attachInterrupt(digitalPinToInterrupt(inletFlowMeter), inletFlowPulseIncrement, FALLING); // Interrupt for counting pulses, falling edge
//////System Check//////
// Purge pumps//
analogWrite(outletPump, 10);
analogWrite(inletPump, 10);
lcd.clear();
lcd.setCursor(1, 1);
lcd.print("Out Pump Purge");
lcd.setCursor(1, 2);
lcd.print("In Pump Purge");
delay(5000);
analogWrite(outletPump, 0);
analogWrite(inletPump, 0);
lcd.clear();
lcd.setCursor(1, 1);
lcd.print("System Ready");
delay(5000);
lcd.clear();
}
void loop()
{
////// Outlet Pump //////
int pot = analogRead(outletPot); //read potentiometer (0-1023)
int outSpeed = map(pot, 0, 1023, 0, 127.5); // convert to 0-255
int outpercentage = map(outSpeed, 0, 127.5, 0, 100); // PWM vaue mapped to %
digitalRead(outPumpLevelControl);
if(outPumpLevelControl, HIGH)
{
analogRead(outletPot);
analogWrite(outletPump, outSpeed);
}
lcd.setCursor(0,0);
lcd.print("Out Speed ");
lcd.print(outpercentage);
lcd.print("%");
lcd.setCursor(0,1);
lcd.print("Out ");
lcd.print(outflowRate);
lcd.print(" L/min");
////// Outlet Pump Alarm//////
if(outPumpLevelControl, LOW)
{
analogWrite(outletPump, 0);
lcd.clear();
lcd.setCursor(0,1);
lcd.scrollDisplayLeft();
lcd.print("Outlet Pump Alarm - Check Water Levels");
}
//////Flow calculations//////
outletFlowcount = 0;
inletFlowcount = 0;
interrupts();
delay(2000);
outflowRate = 2.1368 * outletFlowcount / 1000 * 30; //2.1368 is amount of flow in ml/pulse//
inflowRate = 2.1368 * inletFlowcount / 1000 * 30;
noInterrupts();
Serial.print("Outlet Flow ");
Serial.print(outflowRate);
Serial.println(" L/min");
Serial.print("Inlet Flow ");
Serial.print(inflowRate);
Serial.println(" L/min");
//////Inlet Pump//////
int inpercentage = map(inflowRate, 0, 13.5, 0, 100); // 13.5 L/min is maximum output of Inlet Pump
int inSpeed = map(outletFlowcount, 0, 4212, 0, 255); // 4212 is the amount of pulses for 9L/min,,,,,,maximum flow of outlet pump
digitalRead(inPumpLevelControl);
if(inPumpLevelControl, HIGH)
{
analogRead(inSpeed);
analogWrite(inletPump, inSpeed);
}
lcd.setCursor(0,2);
lcd.print("In Speed ");
lcd.print(inpercentage);
lcd.print("%");
lcd.setCursor(0,3);
lcd.print("In ");
lcd.print(inflowRate);
lcd.print(" L/min");
// Inlet Pump Alarms
if(inPumpLevelControl, LOW)
{
analogWrite(inletPump, 0);
lcd.clear();
lcd.setCursor(0,3);
lcd.scrollDisplayLeft();
lcd.print("Inlet Pump Alarm - Check Water Levels");
}
}
//////Functions//////
void outletFlowPulseIncrement()
{
outletFlowcount++;
}
void inletFlowPulseIncrement()
{
inletFlowcount++;
}