1

I am a beginner trying to activate 2 sets of 3 air pistons sequentially by going through the YouTube Tutorials... Help, please, pretty please?? :-)

There are 3 sets of 2 pistons, each set working in opposition. So I have P1/P2, P3/P4, and P5/P6, each set working in opposition to squeeze at the center sequentially - Initial state at turn-on/Reset must be:

// Step 1 Run Once:
P1 Down/P2 Up  // Move simultaneously (joining at the center) and HOLD in position - 
P2 Up/P3 Down  // Move simultaneously and HOLD -
P5 Up/P6 Down  // Move simultaneously and HOLD -
// Wait for Start button -

I need to start/stop the sequencing with a toggle push-button - I have reed-switch sensors that will give me a set of two TRANSIENT contact closure for each piston moving to the Up and Down positions -

Once started, the sequence needs to be as follows:

// Loop until Reset button is pushed -
// STEP 2: - 
P1 Down/P2 Up (HOLD) // Old Initial State, unchanged - 
P3 Down/P4 Up (MOVE) // Piston 3 moves Down/Piston 4 moves Up and HOLDS - 
P5 Up/P6 Down (HOLD) // Still Old Initial State, unchanged - 

// PROBLEM: P3 Down AND P4 Sensors only give me a TRANSIENT closure: These two transients MUST occur to initiate Step 3, but they are not always exactly synched together, so my initial try by putting them in series fails... - // I need to use that set of contact closures to trigger the next command: -

// Step 3: - 
// The transient closures of P3 Down/P4 Up Sensors is the trigger needed for - 
P5 Down/P6 Up (MOVE) // P5 moves Down/P6 moves Up and HOLD - 
P1 Up/P2 Down (MOVE) // P1 moves Up/P2 moves Down and HOLD - 
P3 Down/P4 Up (HOLD)  // P3/P4 HOLD - 

// Back to Step 2 until the Reset button is pushed - 

I can send you my attempt at coding for this, but it does not work unless the two sensors close simultaneously, which only happens in simulation... ARGH.. :-(

Can someone send me a piece of code that will work for this, please? I would really, really appreciate that... Very frustrated right now! You can email me at XXXXXXX.XXXX@XXXXX.XXX or text/call at (XXX)XXX-XXXX Thanks either way. Sincerely, Michael

PS: I tried to wire for a separate toggle switching for each sensor, but I run out of pins on my Arduino UNO R3... Looking into it via YouTube https://www.youtube.com/watch?v=cAT07gy4DII "Increase the digital outputs on an Arduino (PART 1 & 2)" but that is way more complex... Trying to wade my way through that now...

5
  • do not expect two sensors to close simultaneously ... that does not happen in real life ... also, please review step 1 ... it does not make sense – jsotola Oct 9 '20 at 0:53
  • When you say simultaneously, what does that means in precision? down to microsecond? or millisecond? Without code and diagram it is hard to comment on how to improve it or solve your problem. All I could think of right now is that 1) you need to have a state machine to manage all the states and transitions, 2) to make sure all actuators acts together, you probably need to directly access the registers of the MCU for activating each pin than using Arduino commands like digitalWrite(). – hcheung Oct 9 '20 at 1:56
  • why do you have separate signals for opposing pistons? – jsotola Oct 9 '20 at 2:04
  • Writing your email address and phone number in clear text into an online site begs for receiving tons of spam and robot calls. When using this site, please also use this site for the communication. Simple Q&A – chrisl Oct 9 '20 at 7:42
  • Please include your code into the question. – chrisl Oct 9 '20 at 7:46
2

it does not work unless the two sensors close simultaneously

If I understand correctly, the problem is that when your Arduino detects the second transient signal, the first one is not active anymore, and your program doesn't remember it has already seen that first signal.

Your Arduino has memory. Thousands of bits of memory! So it can remember quite a few things. The solution to your problem is to simply make use of that memory. When you detect a signal that should be useful for a future decision, take note, store it in a variable. In order for the variable to be remembered across calls of the function where you set it, it has to be global. Or, better yet, static local.

Here is how that could look like in code:

// A `static' variable is a variable that remembers its state across
// calls of the function. A global variable would do the same, but
// code is usually clearer when variables are defined close to where
// they are used. A `bool' (for "boolean") is a variable that can only
// be either `true' or `false'.
static bool P5_is_up, P6_is_down;

// If the sensor tells us that the P5 piston went all the way up, take
// note of the fact and remember it.
if (digitalRead(P5_up_sensor) == LOW)
    P5_is_up = true;

// Same for P6 going down.
if (digitalRead(P6_down_sensor) == LOW)
    P6_is_down = true;

// If both pistons finished their travel, we can move to the next
// step. `&&' means "and".
if (P5_is_up && P6_is_down)
    goto_step_3();

You will need to reset those variables to false at the appropriate time. The example code above doesn't show that as it only deals with the logic for deciding when it is time to start step 3.

You will probably end up with many of these variables, and lots of repetitive code. So you will need to structure your program in order to avoid excessive repetition. But that is not your immediate problem. For now, try to make the logic work for a single step transition. Once you get the logic right, you can worry about generalizing the logic to any transition.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.