How to if digitalRead(OUTPUT) then if digitalRead(INPUT)

Hello, i try to make two LDr sensing the if serial recived example A and B.

if serial A then
PIN11 HIGH
when PIN11 HIGH wait for INPUT sensing LOW at pin 2

if serial B then
PIN10 HIGH
when PIN10 HIGH wait for INPUT sensing LOW at pin 3

this code run in loop..i suggesfully with pin 10, but fail with pin 11.

Here my code:

void loop() 
{
  Serial.println(i++);
//-------------------------------------FAIL to work-------------------------------------------
//AUTO Sensing following selected autofilling - each sensor

if (digitalRead(11)==HIGH)      // digitalRead(11)==HIGH) 
{
  if (digitalRead(2)==LOW)      // wait for 2.8 litle sensor detected oil then
{
  digitalWrite(13, LOW);        // pump1 stop
  Serial.println("13 low");
  delay(100);                   // give some time space before next process
  digitalWrite(12, HIGH);       // Start pump2 to pump oil to gearbox container
  Serial.println("12 high");
} 
}
//-----------------------------------------SUCCESS-----------------------------------------
//AUTOFILLING 3.5LITLE PROCESS

if (digitalRead(10)==HIGH)      //  digitalRead(10)==HIGH)
{
  if (digitalRead(3)==LOW)      // wait for 3.5 litle sensor detected oil then
{
  digitalWrite(13, LOW);        // pump1 stop
  Serial.println("13 low");
  delay(100);                   // give some time space before next process
  digitalWrite(12, HIGH);       // Start pump2 to pump oil to gearbox cointainer
  Serial.println("12 high");
                  
       
} 
}


}

look like pin 11 not read, because if i change if (digitalRead(11)==LOW) the is work. Why this happen? I try to put LED it ligh on but it not read as HIGH

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

What's hooked up to pin 11? How is it hooked up? Post all of your code and perhaps try explaining it again; I'm having a difficult time trying to figure out what you're trying to do and what the problem actually is.

Here all complete code:
This will be serial on/off pin 13 and pin 11&10.
1.When i send 0 or 1 serial data, pin 13 will be HIGH and LOW
2.When i send 2 serial data, pin 13 will HIGH and pin 11.
-Pin 13 i hook with 1k resistor and bc548 transistor to control relay. For pin 11 i hook with Green LED and 220 ohm resistor.
-Pin 13 on the relay and pin 11 on the LED, i plan to used pin 11 as sensing if pin 11 High then it wait for LOW at Pin 2.
-After pin 2 connected with ground and sense as LOW, pin 12 will on and pin 13 off.
-Final process is if pin 4 sense Low the pin 12 off.

*I want to digitalRead pin 11 and 10 to separate the input program sequence for each serial data received.

//Setup atmega328-p serial communication and inout pin
void setup()
{
Serial.begin(9400);

//Setup input pin------------------------------------------------------------------------------------
pinMode(2, INPUT);  //Sensor 1 litle
pinMode(3, INPUT);  //Sensor 2 litle
pinMode(4, INPUT);  //Sensor OverFlow

//Setup output pin------------------------------------------------------------------------------------
pinMode(10, OUTPUT); //Sensing 2.8 Litle
pinMode(11, OUTPUT); //Sensing 3.5 Litle
pinMode(12, OUTPUT); //PUMP2
pinMode(13, OUTPUT); //PUMP1

//Set all output as low/off----------------------------------------------------------------------------
digitalWrite(10, LOW); 
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
}

//Initialise i as 0, so it start cointing from 0 to infinite
int i=0;

//Using loop function for all operation
void loop() 
{
  Serial.println(i++);
//-----------------------------------------------------------------------------------------------------
//AUTO Sensing following selected autofilling - each sensor

if (digitalRead(11)==HIGH) // && digitalRead(11)==HIGH)// wait for android send data to serial, and give HIGH status for pin 10
{
  if (digitalRead(2)==LOW)      // wait for 2.8 litle sensor detected oil then
{
  digitalWrite(13, LOW);        // pump1 stop
  Serial.println("13 low");
  delay(100);                   // give some time space before next process
  digitalWrite(12, HIGH);       // Start pump2 to pump oil to gearbox cointainer
  Serial.println("12 high");
} 
}
//------------------------------------------------------------------------------------------------------
//AUTOFILLING 3.5LITLE PROCESS

if (digitalRead(10)==HIGH) // && digitalRead(10)==HIGH)// wait for android send data to serial, and give HIGH status for pin 10
{
  if (digitalRead(3)==LOW)      // wait for 3.5 litle sensor detected oil then
{
  digitalWrite(13, LOW);        // pump1 stop
  Serial.println("13 low");
  delay(100);                   // give some time space before next process
  digitalWrite(12, HIGH);       // Start pump2 to pump oil to gearbox cointainer
  Serial.println("12 high");
                  
       
} 
}
//------------------------------------------------------------------------------------------------------
//Over flow sensor detection function
if (digitalRead(4)==LOW)
{
  digitalWrite(12, LOW);
  Serial.println("12 low");
  delay(100);
  digitalWrite(11, LOW);
  digitalWrite(10, LOW);
  Serial.println("11 and 10 low");
}
//------------------------------------------------------------------------------------------------------
//Serial speed
delay(200);

//Wait for serial android data recived------------------------------------------------------------------
if (Serial.available()) 
{
 int msg = Serial.read();

//Evan from android, sub p will wait in loop mode to operate as ordered

//START PUMP1
if (msg == '0') 
{
  digitalWrite(13, HIGH);                           //PUMP1 manual start
  Serial.println("Pump1 start");
}

//STOP PUMP1
if (msg == '1') 
{
  digitalWrite(13, LOW);                            //PUMP1 manual stop
  Serial.println("Pump1 stop");
}

//2.8 Litle filling
if (msg == '2') 
{
  digitalWrite(11, HIGH);                     //Sensing for 2.8 litle function ON
  digitalWrite(13, HIGH);                     //Pump 1 start to pump oil from main tank1 to Measure tank2
  Serial.println("Sensing auto filling 2.8");
}

//3.5 Litle filling
if (msg == '3') 
{
  digitalWrite(10, HIGH);                     //Sensing for 3.5 litle function ON
  digitalWrite(13, HIGH);                     //Pump 1 start to pump oil from main tank1 to Measure tank2
  Serial.println("Sensing auto filling 3.5");
}
}

}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

Are you trying to do digitalRead() on an output pin? (Why?)

Please enclose your code in [ code ] [ /code ] tags to stop the forum software from munging it.

majdi_mohammad:
1.When i send 0 or 1 serial data, pin 13 will be HIGH and LOW

Pin 13 can't be HIGH and LOW at the same time, do you mean you want pin 13 to be HIGH when you receive a '0' and pin 13 to be LOW when you receive a '1'?

2.When i send 2 serial data, pin 13 will HIGH and pin 11.

... and pin 11 what?

-Pin 13 i hook with 1k resistor and bc548 transistor to control relay. For pin 11 i hook with Green LED and 220 ohm resistor.
-i plan to used pin 11 as sensing if pin 11 High then it wait for LOW at Pin 2.

What? How do you plan on using pin 11 to sense if it is HIGH? Isn't pin 11 an output? If it's an output, then your code controls if it's HIGH or LOW, so you just need a simple variable to keep track.

-After pin 2 connected with ground and sense as LOW, pin 12 will on and pin 13 off.

Pin 2 is connected straight to ground? It will always sense LOW, so pin 12 will always be on and pin 13 will always be off.

*I want to digitalRead pin 11 and 10 to separate the input program sequence for each serial data received.

What does "input program sequence" mean?

Yup, i want to used output pin read for avoid from sensor 2.8 liter run their code before 3.5 liter sensor detected.

Here i attached a picture to help other understand better.

Let say the code is working, if i send serial data 2, pump1 start pumping oil from tank a to tank b, senosr 2.8 liter detected then pump 1 stop and pump2 start pumping oil from tank b to tank c. After over flow detected pump 2 stop.

But if i send serial data 3, it will be stuck on 2.8 liter sensor not 3.5 liter sensor.. ;(

If there any better suggestion please guide me..

Pin 13 can't be HIGH and LOW at the same time, do you mean you want pin 13 to be HIGH when you receive a '0' and pin 13 to be LOW when you receive a '1'?

Yes, it not HIGH & LOW at same time, it High when serial data send "0", and Low if serial data "1". ---This part work fine

... and pin 11 what?

Pin 11 will on an LED if serial data send "2"

What? How do you plan on using pin 11 to sense if it is HIGH? Isn't pin 11 an output? If it's an output, then your code controls if it's HIGH or LOW, so you just need a simple variable to keep track.

I used :

Not work on pin 11

if (digitalRead(11)==High)           // pin 11 ------------->LED------>220 ohm ---------GND
{ 
  if (digitalRead(2)==LOW)          // pin 2 ----^------> 20kOhm----------> 5DC
    {                                        //              l l sensor sense then connect to GND  

NEXT code here.....             
    }
}

Successfully work on pin 10

if (digitalRead(10)==High)           // pin 10 ------------->LED------>220 ohm ---------GND
{ 
  if (digitalRead(3)==LOW)          // pin 3 ----^------> 20kOhm----------> 5DC
    {                                        //              l l sensor sense then connect to GND  

NEXT code here.....
    }
}

What does "input program sequence" mean?

Input sequence i mean, if i choose to sensor 3.5 liter detected oil, then all program for sensor 2.8 liter will not run..

Here my schematic diagram

Hey guys, it work :wink: my bad soldering, i dont know why it act like that, but i mistaken join Pin11----Led----bypass the resistor-----GND.. Then the code not detected it as HIGH. After i remove the bad soldering and Pin11----LED---220 ohm ------ Gnd. Then it work perfectly. Thank guys for your time.