How to Create logic

Hi,
Now I am working on Logical project, Let me explain what I want to do,
I have 4 inputs
INPUT 1, INPUT 2, INPUT 3, INPUT 4 (I Don’t know where to give input/Which pin of arduino can use as input)
Now I want output at PIN ** (I don’t know where to receive Output/which pin of arduino can use as output)
I need output at output pin after some time like I want to add “Wait (1000)” like at every pin,
Eg: if I am give input at pin , receive output at pin after some particular time.
Now I want to create logic, like if PIN** & PIN** high than PIN** should HIGH
Please guide me how to create this logic.

INPUT 1, INPUT 2, INPUT 3, INPUT 4 (I Don’t know where to give input/Which pin of arduino can use as input)
Now I want output at PIN ** (I don’t know where to receive Output/which pin of arduino can use as output)

You can use any of the I/O pins as input or output, but stay away from pins 0 and 1 as they are used for serial comms.

I need output at output pin after some time like I want to add “Wait (1000)” like at every pin,

"wait is called delay and you should never use it! - See the blink without delay example and FSM’s (Finite State Machines) in the playground.

Now I want to create logic, like if PIN** & PIN** high than PIN** should HIGH

Read the reference section!.

Mark

holmes4:
Read the reference section!.

Specifically look at the digitalRead() and digitalWrite() functions. If you're familiar with other microcontrollers this should get you on the way. As Mark mentioned above delay() might not be ideal for your project as it is a blocking function - your code will mostly not respond to external inputs while it is running. I wouldn't go so far as to say never use it, but it's rare that it's the best choice for anything more than the most simple cases.

If you are completely unfamiliar with Arduino there are some excellent tutorials available not just here, but also on youtube. This series by Jeremy Blum is a good place to start imo.

All the best,
Geoff

SO finally m with my logic... let me know if any one can help me to achieve req output....

i have 4 input

Consider input as push button and OUTPUT as LED

INPUT= P1 OUTPUT= S1
INPUT= p2 OUTPUT= S2
INPUT= L1 OUTPUT= S3
INPUT= L2 OUTPUT= S4

now see my logic req.

CASE 1
When P1 on
S1 and S3 on for 10 sec
but if

L2 on
Close S1 and S3
and Open S2 and S4 for 10 swcond

IF
L1 on
Close S1,S2,S3,S4

CASE 2

when P2 on
S3 on for 10 sec

but

if L2 on

close S3
Open S4 for 1o sec

If L1 on
Close Close S1,S2,S3,S4

Consider OPEN as On and CLOSE as Off

please let me know if any one can solve this logic

chetan0412:
CASE 1
When P1 on
S1 and S3 on for 10 sec
but if

L2 on
Close S1 and S3
and Open S2 and S4 for 10 swcond

The sort of behaviour you're describing is certainly feasible and not difficult to code once you have got the hang of it. However, although your description is reasonably detailed it still has some ambiguity. For example, in the situation where P1 is on and L2 is also on, it's not clear which should take precedence with respect to the behaviour described above. Similarly for the other parts of the code where different input states affect the same outputs.

hi PeterH,

currently we are working on hydraulic system which we want to control by arduino.

here P1 is piston and L2 is limit switch , which is at the bottom limit of the piston strock.

when p1 coming at down side it will Activate L2(push L2)

Means

CASE 1
When P1 on (Piston going down side, Piston supply connected to P1)
S1 and S3 on for 10 sec (Same time S1 and S3 pin should be high)
but if

L2 on
Close S1 and S3
and Open S2 and S4 for 10 second
(means when piston push L2 limit switch after reaching/triggering L2, S1 and S3 should be Low and S2 and S4 High for 10 sec)

Hi to all,

Just i tried to complete some part, but i am stuck at some place , let me know if anyone can solve this problem.

In this program if i want off all LED at the same time when P1 and L2 both are HIGH(on).

I've tried to use boolean AND operator,if, do while, while

Still it's not working ..Let me know if there is any logical error

my code is,

const int P1 = 2;     // the number of the pushbutton pin
const int P2 = 3;     // the number of the pushbutton pin
const int L1 = 4;     // the number of the pushbutton pin
const int L2 = 5;     // the number of the pushbutton pin

 int S1 =  8;      // the number of the LED pin
 int S2 =  9;      // the number of the LED pin
 int S3 =  10;      // the number of the LED pin
 int S4 =  11;      // the number of the LED pin


// variables will change:
int P1State = 0;         // variable for reading the pushbutton status
int P2State = 0;         // variable for reading the pushbutton status
int L1State = 0;         // variable for reading the pushbutton status
int L2State = 0;         // variable for reading the pushbutton status


void setup() {
  // initialize the LED pin as an output:
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
  pinMode(S4, OUTPUT);  
  
  // initialize the pushbutton pin as an input:
  pinMode(P1, INPUT);
  pinMode(P2, INPUT);  
  pinMode(L1, INPUT);
  pinMode(L2, INPUT);
}

void loop(){


  // FOR  P1 ACTIVE
  P1State = digitalRead(P1);
  P2State = digitalRead(P2);
  L1State = digitalRead(L1);
  L2State = digitalRead(L2);
  

if (P1State == HIGH)
{
    // turn LED on:    
    digitalWrite(S1, HIGH);  
    digitalWrite(S3, HIGH); 
     digitalWrite(S2, LOW);  
    digitalWrite(S4, LOW); 
   
} 
if (L2State == HIGH)
 {
   digitalWrite(S1, LOW);  
    digitalWrite(S3, LOW);
    digitalWrite(S2, HIGH);  
    digitalWrite(S4, HIGH);
 }
    
  
    if (L1State ==HIGH)
 {
   digitalWrite(S1, LOW);  
    digitalWrite(S3, LOW);
    digitalWrite(S2, LOW);   
    digitalWrite(S4, LOW);
 } 
     if (L2State ==HIGH && P1State==HIGH)
 {
   digitalWrite(S1, LOW);  
    digitalWrite(S3, LOW);
   
 }

  }

Still it's not working

whatever that means.

still This part is not working.

if i want off all LED at the same time when P1 and L2 both are HIGH(on).

Where is your debug output?

when we press L2 and P1 all the LED glow i.e all O/P are high at same time where as they should have been low.

Also this part of our code is not working

 if (L2State ==HIGH && P1State==HIGH)
 {
   digitalWrite(S1, LOW);  
    digitalWrite(S3, LOW);
   
 }

  }

Also this part of our code is not working

It is doing something, but you haven't said what.

Slow down, post a schematic, show how you are preventing your inputs from floating.
Bear in mind that what you observe may not be what is actually happening - the processor is very fast.

Could plz tell me how to fix the floating outputs

This is the circuit we used with 4 O/P and I/P(repeated the same circuit 4 times)

http://www.seeedstudio.com/wiki/images/thumb/5/55/Arduino_Sidekick_Pushbutton_LED.jpg/400px-Arduino_Sidekick_Pushbutton_LED.jpg

you need to debounces the input, without which pressing the button once would appear to the code as multiple presses.

Your diagram shows that you have got pull-down resistors in place so you do not have floating inputs. (I assume these resistors are in place for all four inputs used by your sketch.)

I think the problem is that these conditions are not all mutually exclusive:

if (P1State == HIGH)
if (L2State == HIGH)
if (L1State ==HIGH)
if (L2State ==HIGH && P1State==HIGH)

This means that even if you correctly turn the outputs off in one piece of code, they could be turned on again by another piece of code.

I suggest you restructure so that they are mutually exclusive and the precedence between them is defined explicitly, e.g.:

if (L2State == HIGH && P1State == HIGH)
{
}
else
{
    if (P1State == HIGH)
    {
    }
    if (L2State == HIGH)
    {
    }
}
if (L1State == HIGH)
{
}