Go Down

Topic: Alternate operation of two motors depending on state of pressure switch. (Read 1 time) previous topic - next topic

deshmane

Hello everyone,

I have a pump system, in which I want to run motor alternately depending on state of pressure switch and not with delay program.  I want logic as below,
1. When switch ON system and if pressure switch is at HIGH state, PUMP A should run and once pressure switch is LOW pump will stop.
2. When next time again pressure switch become HIGH, PUMP B should run as PUMP A was running earlier.
In such way I want to run pumps alternately.  I have made program for this as below, but its not working with hardware.  All other program and circuit is working good only alternate operation is not happening.


#define FlOAT_SWITCH_PIN 2
#define Pressure_SWITCH_PIN 12
//Motors pins:
#define PUMPA_PIN 7
#define PUMPB_PIN 8
# include <EEPROM.h>

void setup() {
pinMode(2, INPUT_PULLUP); 
pinMode(12, INPUT_PULLUP);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
Serial.begin(9600);}

void loop() {
  //when pressure switch(12) HIGH, first motor 8, should start,
  if (digitalRead(12)==HIGH && digitalRead(2)==HIGH && EEPROM.read(8, HIGH)
{digitalWrite(8,LOW);
 digitalWrite(7,HIGH);
 EEPROM.write(8,LOW);}
 //when next time pressure switch will become HIGH that time second motor 7, should start and in such way motors should run alternatly,
 else if (digitalRead(12)==HIGH && digitalRead(2)==HIGH && EEPROM.read(8, LOW)
{digitalWrite(8,HIGH);
 digitalWrite(7,LOW);
 EEPROM.write(8,HIGH);}
}

Please, can someone help me with this?

UKHeliBob

Quote
Please, can someone help me with this?
Not until you post your code properly.  Unless, of course, it really has smileys in it, which I doubt.

Please read this before posting a programming question and follow the instructions for posting code.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

johnwasser

You meant to post:
Code: [Select]
const int FLOAT_SWITCH_PIN = 2;
const int PRESSURE_SWITCH_PIN = 12;
//Motors pins:
const int PUMP_A_PIN = 7;
const int PUMP_B_PIN = 8;

#include <EEPROM.h>

void setup() {
  pinMode(FLOAT_SWITCH_PIN, INPUT_PULLUP);
  pinMode(PRESSURE_SWITCH_PIN, INPUT_PULLUP);
  pinMode(PUMP_B_PIN, OUTPUT);
  pinMode(PUMP_A_PIN, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  //when pressure switch(PRESSURE_SWITCH_PIN) HIGH, first motor 8, should start,
  if (digitalRead(PRESSURE_SWITCH_PIN) == HIGH &&
      digitalRead(FLOAT_SWITCH_PIN) == HIGH &&
      EEPROM.read(8) == HIGH) {
    digitalWrite(PUMP_B_PIN, LOW);
    digitalWrite(PUMP_A_PIN, HIGH);
    EEPROM.write(8, LOW);
  }
  //when next time pressure switch will become HIGH that time second motor 7, should start and in such way motors should run alternately,
  else if (digitalRead(PRESSURE_SWITCH_PIN) == HIGH &&
           digitalRead(FLOAT_SWITCH_PIN) == HIGH &&
           EEPROM.read(8) == LOW) {
    digitalWrite(PUMP_B_PIN, HIGH);
    digitalWrite(PUMP_A_PIN, LOW);
    EEPROM.write(8, HIGH);
  }
}


You said you want Pump A to always be first on power-up but you are using EEPROM to keep track of which pump was last used.  Did you mean to say you want them to alternate, even if power fails?
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

deshmane

Hi UKHeliBob and Johnwasser,

Sorrry for delay I was not able to find replies of post.

@ UKHeliBob: I am new to Arduino and have read the link sent by you, I got it.  Thanks.

I have attached my code and also posted below. 

Circuit Hardware: I have connected float switch and SPDT switch as pressure switch to INPUT of Arduino and two motor through 5V relay to OUTPUT of Arduino and all connections have made properly only not getting logic which I want.
 
Logic: I wants to run two motor(A & B) alternately according to status of pressure switch as shown in program [independent of motor ON time and main switch ON-OFF status(i e. ON-OFF main power supply or power failure and restore) it should sense only status of pressure switch and motors for alternate operation].  And for motors here logic is LOW, i.e. when said digitalWrite(8, LOw), motor at 8 will ON and for digitalWrite(8, HIGH), motor will OFF.

Current Working: I have made code for this using EEPROM concept to check and update status of motors as attached and also pasted below.  But with this motors are not running alternately, sometimes only one motor keeps running or both runs randomly.  And I think reason behind this is Arduino is not able to understand or sense pressure switch and motor status and give signal accordingly as my program is lacking somewhere.

@Johnswasser:  Yes I wants to run motor alternately even if power fails, that means if now motor A was running and power fails and whole system stopped then when power restored and float switch as well as pressure switch HIGH, motor B should start as motor A was running earlier.

What is mistake in this program?   And if anyone know getting this logic in someother way, post please.


CODE:
const int FLOAT_SWITCH_PIN = 2;
const int PRESSURE_SWITCH_PIN = 12;
//Motors pins:
const int PUMP_A_PIN = 7;
const int PUMP_B_PIN = 8;

#include <EEPROM.h>

void setup() {
  pinMode(FLOAT_SWITCH_PIN, INPUT_PULLUP);
  pinMode(PRESSURE_SWITCH_PIN, INPUT_PULLUP);
  pinMode(PUMP_B_PIN, OUTPUT);
  pinMode(PUMP_A_PIN, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  //when pressure switch(PRESSURE_SWITCH_PIN) HIGH, first motor 8, should start,
  if (digitalRead(PRESSURE_SWITCH_PIN) == HIGH &&
      digitalRead(FLOAT_SWITCH_PIN) == HIGH &&
      EEPROM.read(8) == HIGH) {
    digitalWrite(PUMP_B_PIN, LOW);
    digitalWrite(PUMP_A_PIN, HIGH);
    EEPROM.write(8, LOW);
  }
  //when next time pressure switch will become HIGH that time second motor 7, should start and in such way motors should run alternately,
  else if (digitalRead(PRESSURE_SWITCH_PIN) == HIGH &&
           digitalRead(FLOAT_SWITCH_PIN) == HIGH &&
           EEPROM.read(8) == LOW) {
    digitalWrite(PUMP_B_PIN, HIGH);
    digitalWrite(PUMP_A_PIN, LOW);
    EEPROM.write(8, HIGH);
  }
else{
    digitalWrite(PUMP_B_PIN, HIGH);
    digitalWrite(PUMP_A_PIN, HIGH);
  }
}

wildbill

How are your switches wired up? Are they normally closed? Your use of input pullup and testing whether switches are high implies it.

TomGeorge

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :)
Everything runs on smoke, let the smoke out, it stops running....

johnwasser

If you get your switches wired properly this version of the sketch is going to switch between the two motors hundreds of times per second as long as the two switches are open.  Probably not what you want to do.  You need to detect the moment when it goes from "don't run a pump" to "DO run a pump" and only then turn on a pump.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

deshmane

If you get your switches wired properly this version of the sketch is going to switch between the two motors hundreds of times per second as long as the two switches are open.  Probably not what you want to do.  You need to detect the moment when it goes from "don't run a pump" to "DO run a pump" and only then turn on a pump.
Is that mean when we switch pressure switch to HIGH or ON, motors becoming ON-OFF more number of times. As you said 'detect the moment when it goes from "don't run a pump" to "DO run a pump" and only then turn on a pump', How can I get this logic?

deshmane

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :)
I have posted circuit with Arduino Uno, see it and tell me what can I do for alternate operation.

Thanks :)

deshmane

How are your switches wired up? Are they normally closed? Your use of input pullup and testing whether switches are high implies it.
Switches are normally open, when SPDT switch(used as pressure switch) will HIGH then motor will run.


outsider

According to your drawing, the toggle (pressure) switch will be LOW when CLOSED, the float switch will be CLOSED and LOW when liquid is higher than float switch. Is that correct?

deshmane

According to your drawing, the toggle (pressure) switch will be LOW when CLOSED, the float switch will be CLOSED and LOW when liquid is higher than float switch. Is that correct?
When float switch closed(LOW), water level will be low  and so both motors will be OFF.   When float switch Open(HIGH), water level will be OK and so both motors will become ON alternately according to status to SPDT(pressure)switch.

For SPDT(single pole double throw), when switch at 1, no signal will go. When at 2, motor will go signal of ON.  If you see program as well as circuit I have attached above, you will get clearly what logic I want.

when SPDT at 2(mean SPDT or pressure switch at HIGH) motor A will start, when SPDT goes to state 1 motor will OFF.  Again next time when SPDT at 2 motor B should start instead of A.


bluejets

Built a control for 2 diesel pumps feeding a generator at the local hospital.... No micros... See if I can find it

deshmane

Built a control for 2 diesel pumps feeding a generator at the local hospital.... No micros... See if I can find it
Okay. I want alternate operation of two pumps with programming language, please see if you can find it.

outsider

If float switch is closed when level is below it should be drawn like this:

You need to create a boolean variable named "alt" and invert it's state (true or false) when the pump cuts off, next time a pump is to start, check the state of the boolean to see which one to start.
Code: [Select]
  // PSEUDO CODE

if(RUN_PUMP == HIGH)
  {
    if(alt == true)
      RUN_PUMP1;
  else
      RUN_PUMP2;
  }
else
  {
    STOP_PUMP1;
    STOP_PUMP2;
    alt = ! alt;  // invert alt
  }

Go Up