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,
- 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.
- 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?