I am running two motor pumps with an Arduino board, one problem that I have right now is that they don't run at the desired time. The first pump and second pump run simultaneously when I plugged in the power source. However, after 10-15 seconds, they started to run as desired. I am really confused, I checked my circuit and it doesn't seem like it's wrong, and also since they run as desired after 10-15 seconds, I think the problem is with my code. Below is what I have:
int InPin = 7; // In Pump - NPN base connected to digital pin 7
int DrainPin = 8; // Drain pump - NPN base connected to digital pin 8
int blinkPin = 13; //
int InTime = 5000; // 5 seconds (change accordingly)
int DwellTime = 5000; // 5 seconds
int DrainTime = 5000; // 5 seconds
int WaitTime = 5000; // 5 seconds
void setup()
{ // put your setup code here, to run once:
pinMode(InPin, OUTPUT); // set the pin 7 as output
pinMode(DrainPin, OUTPUT); // set the pin 8 as output
pinMode(blinkPin, OUTPUT); //
}
void loop()
{ // Pump water
digitalWrite(InPin, LOW); // In NPN LOW, MOSFET HIGH, turns pump on
digitalWrite(blinkPin, HIGH); // blinkPin ON means pumping into patient
delay(InTime); // Pump water for 25 secs
// Dwelling
digitalWrite(InPin, HIGH); // In NPN HIGH, MOSFET LOW, turns pump off
digitalWrite(blinkPin, LOW); // blinkPin off means pump is turned off
delay(DwellTime); // dwell water for 10 secs
// Draining starts
digitalWrite(DrainPin, LOW); // Drain NPN LOW, MOSFET HIGH, turns pump on
delay(DrainTime); //
// Pause before starting another cycle
digitalWrite(DrainPin, HIGH); // Drain NPN HIGH, MOSFET LOW, turns pump off
delay(WaitTime);
// After this the In pump will be turned on again, and the cycle will be repeated for 30 times
}
Please let me know if there's something that you think I should fix! Thanks!!
=========
I removed "{" and "}" accidentally when I transferred the code just now. The code compiles, it just doesn't work the way I want it to work.
First, you are missing a "}" at the end of setup().
Try this:
{ // put your setup code here, to run once:
digitalWrite(InPin,HIGH);
digitalWrite(DrainPin,HIGH);
pinMode(InPin, OUTPUT); // set the pin 7 as output
pinMode(DrainPin, OUTPUT); // set the pin 8 as output
pinMode(blinkPin, OUTPUT); //
}
Time stamps must be. Intervals don't have to be. They can be int or even byte and be perfectly safe, as long as you don't overflow them when you assign a value to them.
digitalWrite(InPin, LOW); // In NPN LOW, MOSFET HIGH, turns pump on
I'm always impressed by people who use "in" in the name of an output pin.
digitalWrite(blinkPin, HIGH); // blinkPin ON means pumping into patient
And what does HIGH mean?
// After this the In pump will be turned on again, and the cycle will be repeated for 30 times
No, the cycle will be repeated until the Arduino wears out.
You should set the state of the output pins in setup(), since the default value of LOW means that the pump(s) is/are running, and that isn't what you want.
No, the cycle will be repeated until the Arduino wears out.
This is in the comment section, I removed the for loop because the pumps are not working the way I want them to work now.
You should set the state of the output pins in setup(), since the default value of LOW means that the pump(s) is/are running, and that isn't what you want.
Thanks! This helped solve the problem!
spycatcher2k, thanks for your comment as well! I missed that just now!
aarg, thanks for the input, I'll keep that in mind when I work on my circuit!
polarpan:
I am running two motor pumps with an Arduino board, one problem that I have right now is that they don't run at the desired time. The first pump and second pump run simultaneously when I plugged in the power source. However, after 10-15 seconds, they started to run as desired.
This is because outputs are LOW by default, and in your sketch LOW turns the pump on.
Turn the pumps off in your setup.
void setup()
{ // put your setup code here, to run once:
pinMode(InPin, OUTPUT); // set the pin 7 as output
pinMode(DrainPin, OUTPUT); // set the pin 8 as output
digitalWrite(InPin, HIGH); // turn pump off at startup
digitalWrite(DrainPin, HIGH); // turn pump off at startup
pinMode(blinkPin, OUTPUT); //
}