how to write code controll 2water pump with 3level electrode

when water low p1p2 on untill water full
when water half p1 or p2 on untill water full
when water half again p1 or p2 on untill water full

thank you very much

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.

We need so see how much code you have written, we will not write all your code.
We will help you with your code development.
OPs pic


Thanks for the diagram.
You will need some back EMF diodes on the relay coils, and possibly some snubbers on the 220Vac contacts of the pump relays because you will be switching an inductive load.

Tom.... :slight_smile:

sorry for wrong topic menu my english skill is bad

#define pump1 12
#define pump2 13
#define sensorlow 0
#define sensorme 1
#define sensorhigh 2
#define ledsensorlow 9
#define ledsensorme 10
#define ledsensorhigh 11
void setup() {
pinMode (pump1, OUTPUT);
pinMode (pump2, OUTPUT);
pinMode (sensorlow, INPUT);
pinMode (sensorme, INPUT);
pinMode (sensorhigh, INPUT);
pinMode (ledsensorlow, OUTPUT);
pinMode (ledsensorme, OUTPUT);
pinMode (ledsensorhigh, OUTPUT);
}
void loop() {
int valuehigh=digitalRead(sensorhigh);
int valuelow=digitalRead(sensorlow);
int valueme=digitalRead(sensorme);
digitalWrite(ledsensorhigh,valuehigh );
digitalWrite(ledsensorme,valueme );
digitalWrite(ledsensorlow,valuelow );
if (valuehigh==1)
{
digitalWrite(pump1 , LOW);
digitalWrite(pump2 , LOW);
}
if (valuelow==0)
{
digitalWrite(pump1 , HIGH);
digitalWrite(pump2 , HIGH);
}
if (valueme==0)
{
digitalWrite(pump1 , HIGH);
digitalWrite(pump2 , LOW);
}
delay(1);
}

i can't toggles pump1 pump2 with code

Hi,

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.

Thanks.. Tom... :slight_smile:

see if this makes sense

#define pump1  12
#define pump2  13
#define sensorlow  0
#define sensorme  1
#define sensorhigh  2
#define ledsensorlow  9
#define ledsensorme  10
#define ledsensorhigh  11
void setup() {
  pinMode (pump1, OUTPUT);
  pinMode (pump2, OUTPUT);
  pinMode (sensorlow, INPUT);
  pinMode (sensorme, INPUT);
  pinMode (sensorhigh, INPUT);
  pinMode (ledsensorlow, OUTPUT);
  pinMode (ledsensorme, OUTPUT);
  pinMode (ledsensorhigh, OUTPUT);
}
void loop() {
  int valuehigh = digitalRead(sensorhigh);
  int valuelow = digitalRead(sensorlow);
  int valueme = digitalRead(sensorme);
  digitalWrite(ledsensorhigh, valuehigh );
  digitalWrite(ledsensorme, valueme );
  digitalWrite(ledsensorlow, valuelow );
  static byte doOnce;//static tell compiler to remember whats stored
  static byte onePump;
  static byte toggle;
  
  if  (valuehigh == 1)
  {
    digitalWrite(pump1 , LOW);
    digitalWrite(pump2 , LOW);
    onePump = 0;
    doOnce = 0;
  }
  if  (valuelow == 0)
  {
    digitalWrite(pump1 , HIGH);
    digitalWrite(pump2 , HIGH);
  }
  if  (valueme == 0)
  {
   onePump = 1;//flag saying you need one pump 
 }

  if (onePump == 1) {//start one pump run until high level
    if (doOnce == 0){//only do this once
    toggle = ! toggle;// if last was 1 now its 0 if it was 0 now its 1
    doOnce = 1;//block the doOnce until high level
    }
    if (toggle == 1) {//which pump decided by toggle 1 or 0
      digitalWrite(pump1 , HIGH);
    }
    if (toggle == 0) {
      digitalWrite(pump2 , HIGH);
    }
  }
  delay(1);
}

Your circuit is putting 12 volts on the Arduino input pins, that will burn them out. Maximum is 5.5 volts.

in your if() tree, you are currently testing all three inputs at the same time, causing conflicts in the decision of which outputs to operate.

One simple appproach is if() followed by else / else if(), which will only activate outputs when one of the three conditions is true.

Later, You may want to add some hysteresis, so the pumps don't chatter on & off with ripples in the water level as they cross each switch position.

Hi,
I think I have all your components in the schematic.
Try not to use D0 and D1, these are the programming pins for the 328.
I have reconfigured your potential divider resistors at the three switching input PNPs.
12V will now apply 4.8V to the D2, D3 and D4 pins.

Tom... :slight_smile:

thank all guy to tell problem

fix water ripple with C10uf at D1&D2 C1uf at D0

thank u very much gpop1 for code but want one pump on untill water full not toggles untill full

thank u very much TomGeorge for fix voltage in put and good digital pic

thank gpop1 your code is work when test with r10k pulldown at d1 d2

Thank all guy it work!!

#define pump1  12
#define pump2  13
#define sensorlow  0
#define sensorme  1
#define sensorhigh  2
#define ledsensorlow  9
#define ledsensorme  10
#define ledsensorhigh  11
void setup() {
  pinMode (pump1, OUTPUT);
  pinMode (pump2, OUTPUT);
  pinMode (sensorlow, INPUT);
  pinMode (sensorme, INPUT);
  pinMode (sensorhigh, INPUT);
  pinMode (ledsensorlow, OUTPUT);
  pinMode (ledsensorme, OUTPUT);
  pinMode (ledsensorhigh, OUTPUT);
}
void loop() {
  int valuehigh = digitalRead(sensorhigh);
  int valuelow = digitalRead(sensorlow);
  int valueme = digitalRead(sensorme);
  digitalWrite(ledsensorhigh, valuehigh );
  digitalWrite(ledsensorme, valueme );
  digitalWrite(ledsensorlow, valuelow );
  static byte doOnce;//static tell compiler to remember whats stored
  static byte onePump;
  static byte toggle;
  
  if  (valuehigh == 1)
  {
    digitalWrite(pump1 , LOW);
    digitalWrite(pump2 , LOW);
    onePump = 0;
    doOnce = 0;
  }
  else if  (valuelow == 0)
  {
    digitalWrite(pump1 , HIGH);
    digitalWrite(pump2 , HIGH);
  }
  else if  (valueme == 0)
  {
   onePump = 1;//flag saying you need one pump 
 }

  if (onePump == 1) {//start one pump run until high level
    if (doOnce == 0){//only do this once
    toggle = ! toggle;// if last was 1 now its 0 if it was 0 now its 1
    doOnce = 1;//block the doOnce until high level
    }
    if (toggle == 1) {//which pump decided by toggle 1 or 0
      digitalWrite(pump1 , HIGH);
    }
   else if (toggle == 0) {
      digitalWrite(pump2 , HIGH);
    }
  }
  delay(1);
}