USING IR Proximity senor to start a cycle.

Hey all,

I've been trying to start off a cycle where different relays are switched on based on timings mentioned. I need to interlock this cycle with a reciprocating cylinder.

I'm controlling 4 cylinders using arduino. These are timed according to my need. However, this entire cycle needs to run when another cylinder(not controlled by arduino) reaches it's home position. The problem is that the cylinder (not controlled by arduino) does not stay stationary throughout the cycle. After reaching it's home, it stays there for some time and then moves forward where it stays there for some time and comes to home again. How can I sync my entire cycle with this cylinder? My code for the cycle is here.

const byte relay1Pin = 12;//loader
const byte relay2Pin = 11;//exit gate
const byte relay3Pin = 10;//sequencer
const byte relay4Pin = 9;//entry gate
int sensor =6; //proximity sensor

struct CycleStep {
  uint32_t durationMs;
  byte relay1;
  byte relay2;
  byte relay3;
  byte relay4;
};

const CycleStep sequence[] = 
{
  {1000, HIGH,  LOW, HIGH,  HIGH}, // exit opens for 1 second
  
  {1050,  HIGH,  HIGH,  HIGH,  LOW}, //  entry opens after 50milli seconds when exit closes
  {1150,  HIGH, HIGH,  HIGH,  HIGH}, // entry closes after 150 milliseconds of opening
  {1300,  LOW,   HIGH,  HIGH, HIGH}, // Loader is activated 150milliseconds after gate closes
  {1400, LOW, HIGH , LOW, HIGH}, //Sequencer opens 400 milliseconds after loader is started
  {1800, LOW, HIGH, HIGH, HIGH}, //Sequencer closes after 400 milliseconds of opening. 
  {2500, HIGH,HIGH,HIGH,HIGH},// evertything closes
  
};

const int STEPS = sizeof(sequence) / sizeof(sequence[0]);
uint32_t stepStartMs;
int currentStep = 0;

void setup() {
  pinMode(relay1Pin, OUTPUT);
  pinMode(relay2Pin, OUTPUT);
  pinMode(relay3Pin, OUTPUT);
  pinMode(relay4Pin, OUTPUT);
  pinMode(sensor, INPUT);

  currentStep = 0;
  doStep();
  stepStartMs = millis();
}

void loop() {

 if(millis() - stepStartMs >= sequence[currentStep].durationMs) {
    currentStep ++;
    if(currentStep >= STEPS) currentStep = 0;
    doStep();
    stepStartMs = millis();
  }


}

void doStep() {
  digitalWrite(relay1Pin, sequence[currentStep].relay1);
  digitalWrite(relay2Pin, sequence[currentStep].relay2);
  digitalWrite(relay3Pin, sequence[currentStep].relay3);
  digitalWrite(relay4Pin, sequence[currentStep].relay4);
}

A description of the machine would be a big help? What is it for, what does it do? Also a diagram of it showing the positioning of the sensors would be useful. Knowing the context makes it much easier to help.

What IR sensor are you using? Post a link to its datasheet.

How fast are the cylinders moving?

What position of the 5th cylinder do you want to use as the synchronization point?

...R

After reaching it's [sic] home, it [the 5th cylinder] stays there for some time and then moves forward where it stays there for some time and comes to home again.

Does the cycle always complete in the time the 5th cylinder is homed, so the cylinders are ready to start a new cycle next time #5 moves away and re-homes? If not, what's supposed to happen if #5 moves away from home while the cycle is active?- does the cycle complete? or abort? or do some orderly shutdown? Or what? And what's supposed to happen if the cycle is still running and #5 moves away and comes home again before the cycle finishes?- should the current cycle finish and then start a new one (because #5 has re-homed) or should it immediately start at the beginning of the cycle (without finishing) (because #5 has re-homed), or should it finish and ignore the fact #5 came home while it was busy and wait for a new-re-home (if that makes sense).

You might have that clear in your mind (I kinda hope you do) because you're working on this project, but the details will dictate when #5's home sensor needs to be checked, and of course dictates what happens when it's read.

havingFunSoFar:
Does the cycle always complete in the time the 5th cylinder is homed, so the cylinders are ready to start a new cycle next time #5 moves away and re-homes? If not, what's supposed to happen if #5 moves away from home while the cycle is active?- does the cycle complete? or abort? or do some orderly shutdown? Or what? And what's supposed to happen if the cycle is still running and #5 moves away and comes home again before the cycle finishes?- should the current cycle finish and then start a new one (because #5 has re-homed) or should it immediately start at the beginning of the cycle (without finishing) (because #5 has re-homed), or should it finish and ignore the fact #5 came home while it was busy and wait for a new-re-home (if that makes sense).

You might have that clear in your mind (I kinda hope you do) because you're working on this project, but the details will dictate when #5's home sensor needs to be checked, and of course dictates what happens when it's read.

Yes, the cycle indeed has to complete in the time taken for 5th cylinder to reach home. I'm attaching a small diagram showing cylinders and how work. So the cycle needs to be triggered upon sensing a position and go on. Upon sensing the same position, I'm guessing the cycle will restart. IMG_20180806_162914.jpg - Google Drive

Also, I'm attaching a .gif file showing how the cycle works with 4 cylinders. So you can have a better understanding of the process. You can look at the .gif file following this link.

@sahilsahni, please make your images visible in your Post. See this Simple Image Guide

...R

Robin2:
@sahilsahni, please make your images visible in your Post. See this Simple Image Guide

...R

I did try the same. But my images are larger than 2MB so they don't show there. Any other suggestions on how I can accommodate the same?

sahilsahni:
I did try the same. But my images are larger than 2MB so they don't show there. Any other suggestions on how I can accommodate the same?

Make the images smaller. 640x480 is usually quite sufficient.

...R

I've attached a machine schematic with cylinder arrangement. I hope it's clear and explanatory.

Robin2:
Make the images smaller. 640x480 is usually quite sufficient.

...R

sahilsahni:
I've attached a machine schematic with cylinder arrangement.

Thank you.

Now please make it visible in your Reply.

...R

Robin2:
Thank you.

Now please make it visible in your Reply.

...R

Did that.

Thanks for the picture.

Am I correct to think that the sequence is like this

  • The motion of Cylinder5 is not controlled by the Arduino but the Arduino can detect its position
  • When Cylinder5 reaches PositionA it represents the start.
  • Then a sequence of events happens involving Cylinders 1 to 4 which are controlled by the Arduino
  • Cylinder5 continues to move and the sequence for Cylinders 1 to 4 must have completed before Cylinder5 reaches PositionB
  • Cylinder5 continues its motion and eventually returns to PositionA at which point the process repeats

And, if that is correct what part of the process do you need help with?

...R