query about coding

Hello,
In my project three conditions must be satisfied before turning an arduino pin HIGH. If any one condition is also not satisfied then arduino should not perform this task. My query is how to make sure whether all three conditions are satisfied? Is it possible to do it with "IF" statement? Could somebody please help me with an example code.

You could use consecutive nested "if"s, or a single "if" and the logical AND operator "&&" (also spelled "and")

You could also use four consecutive, non-nested " if"s and a count. Lots of ways of skinning this particular cat.

In my case these are the conditions to be satisfied before performing the task.
voltage1=voltage2, frequency1=frequency2, phasesequence1= phasesequence2.
how do i put them with "if" statement?

if( voltage1=voltage2 && frequency1=frequency2 && phasesequence1= phasesequence2)
outputPin = HIGH;

is this the way? please correct me if i'm wrong.

You're almost certainly wrong.
Use == not =

Almost, but all of a sudden you forgot how to check if two things are the same. Hint, it's not = :wink:

Darn, AWOL was quicker and spoiled it :stuck_out_tongue:

One more thing to consider: voltage1 will almost never be EXACTLY the same as voltage2 etc. depending on the resolution of your variables. You should test for a margin e. g. abs(voltage1 - voltage2) < x

Actually, it becomes obvious that none of the three comparisons would be an "equal" if they involve measurements.

There are clearly vastly more complex considerations here than a simple logic statement.

While "&&" groupings have their place, nested "if"s are generally easier to read - and thus, debug.

There is also the matter of comparison execution and sequence. If the first comparison fails, the following comparison code is not executed - it is in fact translated into nested "if"s by the compiler.

I'm grateful for all your suggestions. Could you please provide me an example code for "nested If" statement.
I am also stuck with phase sequence measurement. How to make sure whether phase sequence is R,Y,B or X,Y,Z. Do i have to use PLL ? I have attached a journal paper in this post. In the paper they have used optocoupler to find phase sequence. Could someone help me how to find phase sequence using optocoupler.

V3I5-IJERTV3IS051720.pdf (727 KB)

Nested "if"s

if (this) 
{
  if (that)
  {
    if (theOther)
    {
     //some action that depends on all three conditions being true
    }
  }
}

Thank you AWOL. Could you please help me to find the phase sequence.

I'm on my phone; I'm not going to download 3/4 MB of document.

Document is 728kb AWOL. I have attached the diagram from the above paper in this post. Please check.

Hi,
Is this a school/college/university project, it seems familiar.

Tom... :slight_smile:

sachin88:
Document is 728kb AWOL. I have attached the diagram from the above paper in this post.


Not too keen on that circuit! Tell you why later (I'm off to bed :grinning: )

sachin88:
Could you please help me to find the phase sequence.

Hang on - whose project is this?

For a start, tell me how you would expect to find the phase sequence?

You are right TOM.

PAUL__B that figure is from the journal paper which i am referring.
In my project i am synchronizing two alternators to drive excessive load which can not be handled by single alternator. So before synchronizing i need to maker sure the phase sequence of second alternator is same as that of the first one. For example, if first alternators phase sequence is ABC, then even the second alternator sequence must be ABC to synchronize. Hence i want to check the phase sequence of alternators.

i have also attached my reference paper in one of the previous post.

OK, so you have three inputs from one alternator and three inputs from another. (Actually to tell phase sequence, knowing it is three phase, you only need two inputs from each.)

Now sit down (if you think better that way) and describe the logic of how you would decide whether one set of inputs matched the other (in both sequence and timing). Then write down that logic.

You also need to determine the direction of the mismatch in order to control the supplementary engine speed.

while manually synchronizing alternators we use dark lamp method. How if i use LDR sensors to read lamp and use arduino to close the switch to synchronize? This could work i guess

So, you explain to me how the "dark lamp" method works, and I can suggest how to code it.

(LDR? You must be joking! :grinning: )

In Darklamp method if phases are properly connected, all the lamps will be bright and dark at the same time. If this is not the case, then it means phase sequences are not correct. In order to correct phase sequence,two leads of line of incoming machine should be interchanged. I have attached the darklamp method lamp connection diagram in this post. After finally adjusting the incoming voltage, the synchronization switch is closed at the middle of the dark period.
Is it possible to possible to use LDR to decide whether lamps are dark or bright? Will this logic work Paul__B ?

darklamp.jpg

e15ce04ed093f5a86643ffeb3d9286a16398f985.jpg

And of course in that design, each lamp is actually two lamps in series because it may see twice the line voltage. That diagram does not look quite correct either ("A" and "C" transposed).

Anyway, the code that corresponds to that is to use an exclusive-or function to match each corresponding phase over time, so a counter builds up each interval that the two do not match and runs down each time they do match. If the counter stays near zero, then it has determined that the two signals match.

You only need to match two of the three phases; if both match then both phase and sequence are correct, if one matches but the other does not then the sequence is reversed.

This would correspond to a version of your diagram where two lamps were directly across a pole of the closing switch and you could safely close if both were dark. As it stands, I think it appears sufficient if L1 is dark and both L2 and L3 are fully lit.

(Please just forget the LDRs! :grinning: )