Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
deleted 151 characters in body; edited title
Source Link
dda
  • 1.6k
  • 1
  • 12
  • 18

can Can someone check my code, my? My Arduino isn't doing a consistent count cycle

WonderingI'm wondering if someone could have a look at my code and let me know if there's something wrong with it. I I had the code done for me a while back and did a quick test and it seemed to work. I I have now built a pneumatic machine for it to work on, and it's doing some strange things.

The first relay turns on and off a pneumatic solenoid, this is connected to a small pneumatic cylinder, it moves in and out. This This cylinder causes a pneumatic feeder to activate and move back and forth also.

The solenoid turns on for approx half a second and then back off again, this pushes the small cylinder out then back in. This sends the feeder forward, it then turns around and comes back toward its resting position. The arduinoArduino waits for the signal from the proximity sensor to tell it that the feeder is back in its resting position before doing it again.

After 20 sub cycles, the arduinoArduino turns on the second relay for about a second, before turning it back off again.

I just bought a new board and tried again, but now it counts to about five subcycles and then jumps the gun and doesn't wait for the signal from the proximity sensor before doing the next sub cycle. So once again the count ends up wrong. Any

Any ideas on what iI could try?

int Relay_1 = 10;           //first Relay
int Relay_2 = 11;           //second Relay
int Prox_Input = 12;        //input signal from proximity sensor
int Switch_Input = 13;      //the switch   

int Cycle_Number = 20;      //number of repeating number of "complete" cycle
int Sub_Cycle_Number = 20;  //number of repeating number of "sub" cycle
int Delay_Cycle=1000;Delay_Cycle = 1000;     //delay of the "Complete" Cycle in milleseconds
int Delay_Sub_Cycle=500;Delay_Sub_Cycle = 500;  //delay of the "Sub" Cycle  in milliseconds

bool Button_Pushed = true ; //the state required for the button
int i,j; j;

void setup() {
  /*configurate the output relays to be begin "low"*/
  pinMode(Relay_1 , OUTPUT);
  digitalWrite(Relay_1, LOW);
  
  pinMode(Relay_2 , OUTPUT);
  digitalWrite(Relay_2 , LOW);
  /*===========================================================*/
  /*configurate the input switch and sensor*/
  pinMode(Prox_Input , INPUT);
  pinMode(Switch_Input , INPUT_PULLUP);
  /*===========================================================*/
  /*configurate Serial port if you want it*/
  Serial.begin(9600);
  /*===========================================================*/
}

void loop() {
  
  if (Check_Button() == Button_Pushed)      { //chechcheck the button
  {
    for (i=1i ;= i<=Cycle_Number1 ; i++)             i <= Cycle_Number ; i++) { //the loop of the "complete" Cycle
    {
      
      for (j=1j ;= j<=Sub_Cycle_Number1 ; j++)       j <= Sub_Cycle_Number ; j++) { //the loop of the "sub" Cycle
      {
        digitalWrite(Relay_1 , HIGH);                   
        delay(Delay_Sub_Cycle);
        digitalWrite(Relay_1 , LOW);
      
        while (digitalRead(Prox_Input) == HIGH) {}          // waiting the sensor signal 
      }
 
      digitalWrite(Relay_2 , HIGH);
      delay(Delay_Sub_Cycle);
      digitalWrite(Relay_2 , LOW);
 
      delay(Delay_Cycle);
    }  
  }
}

bool Check_Button()
   {
  int Reading_1;
  int Reading_2;
  
  Reading_1 = digitalRead(Switch_Input);
  delay(20);
  Reading_2 = digitalRead(Switch_Input);
 
  if ((Reading_1 == 1) && (Reading_2 == 1))
    return true;
  else
    return false;
}

can someone check my code, my Arduino isn't doing a consistent count cycle

Wondering if someone could have a look at my code and let me know if there's something wrong with it. I had the code done for me a while back and did a quick test and it seemed to work. I have now built a pneumatic machine for it to work on, and it's doing some strange things.

The first relay turns on and off a pneumatic solenoid, this is connected to a small pneumatic cylinder, it moves in and out. This cylinder causes a pneumatic feeder to activate and move back and forth also.

The solenoid turns on for approx half a second and then back off again, this pushes the small cylinder out then back in. This sends the feeder forward, it then turns around and comes back toward its resting position. The arduino waits for the signal from the proximity sensor to tell it that the feeder is back in its resting position before doing it again.

After 20 sub cycles, the arduino turns on the second relay for about a second, before turning it back off again.

I just bought a new board and tried again, but now it counts to about five subcycles and then jumps the gun and doesn't wait for the signal from the proximity sensor before doing the next sub cycle. So once again the count ends up wrong. Any ideas on what i could try?

int Relay_1 = 10;           //first Relay
int Relay_2 = 11;           //second Relay
int Prox_Input = 12;        //input signal from proximity sensor
int Switch_Input = 13;      //the switch   

int Cycle_Number = 20;      //number of repeating number of "complete" cycle
int Sub_Cycle_Number = 20;  //number of repeating number of "sub" cycle
int Delay_Cycle=1000;       //delay of the "Complete" Cycle in milleseconds
int Delay_Sub_Cycle=500;    //delay of the "Sub" Cycle  in milliseconds

bool Button_Pushed = true ; //the state required for the button
int i,j; 

void setup() {
  /*configurate the output relays to be begin "low"*/
  pinMode(Relay_1 , OUTPUT);
  digitalWrite(Relay_1, LOW);
  
  pinMode(Relay_2 , OUTPUT);
  digitalWrite(Relay_2 , LOW);
  /*===========================================================*/
  /*configurate the input switch and sensor*/
  pinMode(Prox_Input , INPUT);
  pinMode(Switch_Input , INPUT_PULLUP);
  /*===========================================================*/
  /*configurate Serial port if you want it*/
  Serial.begin(9600);
  /*===========================================================*/
}

void loop() {
  
  if (Check_Button() == Button_Pushed)       //chech the button
  {
    for (i=1 ; i<=Cycle_Number ; i++)                   //the loop of the "complete" Cycle
    {
      
      for (j=1 ; j<=Sub_Cycle_Number ; j++)             //the loop of the "sub" Cycle
      {
        digitalWrite(Relay_1 , HIGH);                   
        delay(Delay_Sub_Cycle);
        digitalWrite(Relay_1 , LOW);
      
        while(digitalRead(Prox_Input) == HIGH){}          // waiting the sensor signal 
      }
 
      digitalWrite(Relay_2 , HIGH);
      delay(Delay_Sub_Cycle);
      digitalWrite(Relay_2 , LOW);
 
      delay(Delay_Cycle);
    }  
  }
}

bool Check_Button()
 {
  int Reading_1;
  int Reading_2;
  
  Reading_1 = digitalRead(Switch_Input);
  delay(20);
  Reading_2 = digitalRead(Switch_Input);
 
  if((Reading_1 == 1) && (Reading_2 == 1))
    return true;
  else
    return false;
}

Can someone check my code? My Arduino isn't doing a consistent count cycle

I'm wondering if someone could have a look at my code and let me know if there's something wrong with it. I had the code done for me a while back and did a quick test and it seemed to work. I have now built a pneumatic machine for it to work on, and it's doing some strange things.

The first relay turns on and off a pneumatic solenoid, this is connected to a small pneumatic cylinder, it moves in and out. This cylinder causes a pneumatic feeder to activate and move back and forth also.

The solenoid turns on for approx half a second and then back off again, this pushes the small cylinder out then back in. This sends the feeder forward, it then turns around and comes back toward its resting position. The Arduino waits for the signal from the proximity sensor to tell it that the feeder is back in its resting position before doing it again.

After 20 sub cycles, the Arduino turns on the second relay for about a second, before turning it back off again.

I just bought a new board and tried again, but now it counts to about five subcycles and then jumps the gun and doesn't wait for the signal from the proximity sensor before doing the next sub cycle. So once again the count ends up wrong.

Any ideas what I could try?

int Relay_1 = 10;           //first Relay
int Relay_2 = 11;           //second Relay
int Prox_Input = 12;        //input signal from proximity sensor
int Switch_Input = 13;      //the switch

int Cycle_Number = 20;      //number of repeating number of "complete" cycle
int Sub_Cycle_Number = 20;  //number of repeating number of "sub" cycle
int Delay_Cycle = 1000;     //delay of the "Complete" Cycle in milleseconds
int Delay_Sub_Cycle = 500;  //delay of the "Sub" Cycle  in milliseconds

bool Button_Pushed = true ; //the state required for the button
int i, j;

void setup() {
  /*configurate the output relays to be begin "low"*/
  pinMode(Relay_1 , OUTPUT);
  digitalWrite(Relay_1, LOW);

  pinMode(Relay_2 , OUTPUT);
  digitalWrite(Relay_2 , LOW);
  /*===========================================================*/
  /*configurate the input switch and sensor*/
  pinMode(Prox_Input , INPUT);
  pinMode(Switch_Input , INPUT_PULLUP);
  /*===========================================================*/
  /*configurate Serial port if you want it*/
  Serial.begin(9600);
  /*===========================================================*/
}

void loop() {
  if (Check_Button() == Button_Pushed) { //check the button
    for (i = 1 ; i <= Cycle_Number ; i++) { //the loop of the "complete" Cycle
      for (j = 1 ; j <= Sub_Cycle_Number ; j++) { //the loop of the "sub" Cycle
        digitalWrite(Relay_1 , HIGH);
        delay(Delay_Sub_Cycle);
        digitalWrite(Relay_1 , LOW);
        while (digitalRead(Prox_Input) == HIGH) {} // waiting the sensor signal
      }
      digitalWrite(Relay_2 , HIGH);
      delay(Delay_Sub_Cycle);
      digitalWrite(Relay_2 , LOW);
      delay(Delay_Cycle);
    }
  }
}

bool Check_Button()  {
  int Reading_1;
  int Reading_2;

  Reading_1 = digitalRead(Switch_Input);
  delay(20);
  Reading_2 = digitalRead(Switch_Input);
  if ((Reading_1 == 1) && (Reading_2 == 1))
    return true;
  else
    return false;
}
Bumped by Community user
Bumped by Community user
Bumped by Community user

int Relay_1 = 10; //first Relay int Relay_2 = 11; //second Relay int Prox_Input = 12; //input signal from proximity sensor int Switch_Input = 13; //the switch

int Cycle_Number = 20; //number of repeating number of "complete" cycle int Sub_Cycle_Number = 20; //number of repeating number of "sub" cycle int Delay_Cycle=1000; //delay of the "Complete" Cycle in milleseconds int Delay_Sub_Cycle=500; //delay of the "Sub" Cycle in milliseconds

bool Button_Pushed = true ; //the state required for the button int i,j;

void setup() { /configurate the output relays to be begin "low"/ pinMode(Relay_1 , OUTPUT); digitalWrite(Relay_1, LOW);

pinMode(Relay_2 , OUTPUT); digitalWrite(Relay_2 , LOW); /===========================================================/ /configurate the input switch and sensor/ pinMode(Prox_Input , INPUT); pinMode(Switch_Input , INPUT_PULLUP); /===========================================================/ /configurate Serial port if you want it/ Serial.begin(9600); /===========================================================/ }

void loop() {

if (Check_Button() == Button_Pushed) //chech the button { for (i=1 ; i<=Cycle_Number ; i++) //the loop of the "complete" Cycle {

int Relay_1 = 10;           //first Relay
int Relay_2 = 11;           //second Relay
int Prox_Input = 12;        //input signal from proximity sensor
int Switch_Input = 13;      //the switch   

int Cycle_Number = 20;      //number of repeating number of "complete" cycle
int Sub_Cycle_Number = 20;  //number of repeating number of "sub" cycle
int Delay_Cycle=1000;       //delay of the "Complete" Cycle in milleseconds
int Delay_Sub_Cycle=500;    //delay of the "Sub" Cycle  in milliseconds

bool Button_Pushed = true ; //the state required for the button
int i,j; 

void setup() {
  /*configurate the output relays to be begin "low"*/
  pinMode(Relay_1 , OUTPUT);
  digitalWrite(Relay_1, LOW);
  
  pinMode(Relay_2 , OUTPUT);
  digitalWrite(Relay_2 , LOW);
  /*===========================================================*/
  /*configurate the input switch and sensor*/
  pinMode(Prox_Input , INPUT);
  pinMode(Switch_Input , INPUT_PULLUP);
  /*===========================================================*/
  /*configurate Serial port if you want it*/
  Serial.begin(9600);
  /*===========================================================*/
}

void loop() {
  
  if (Check_Button() == Button_Pushed)       //chech the button
  {
    for (i=1 ; i<=Cycle_Number ; i++)                   //the loop of the "complete" Cycle
    {
      
      for (j=1 ; j<=Sub_Cycle_Number ; j++)             //the loop of the "sub" Cycle
      {
        digitalWrite(Relay_1 , HIGH);                   
        delay(Delay_Sub_Cycle);
        digitalWrite(Relay_1 , LOW);
      
        while(digitalRead(Prox_Input) == HIGH){}          // waiting the sensor signal 
      }

      digitalWrite(Relay_2 , HIGH);
      delay(Delay_Sub_Cycle);
      digitalWrite(Relay_2 , LOW);

      delay(Delay_Cycle);
    }  
  }
}

bool Check_Button()
{
  int Reading_1;
  int Reading_2;
  
  Reading_1 = digitalRead(Switch_Input);
  delay(20);
  Reading_2 = digitalRead(Switch_Input);

  if((Reading_1 == 1) && (Reading_2 == 1))
    return true;
  else
    return false;
}

} }

bool Check_Button() { int Reading_1; int Reading_2;

Reading_1 = digitalRead(Switch_Input); delay(20); Reading_2 = digitalRead(Switch_Input);

if((Reading_1 == 1) && (Reading_2 == 1)) return true; else return false; }

int Relay_1 = 10; //first Relay int Relay_2 = 11; //second Relay int Prox_Input = 12; //input signal from proximity sensor int Switch_Input = 13; //the switch

int Cycle_Number = 20; //number of repeating number of "complete" cycle int Sub_Cycle_Number = 20; //number of repeating number of "sub" cycle int Delay_Cycle=1000; //delay of the "Complete" Cycle in milleseconds int Delay_Sub_Cycle=500; //delay of the "Sub" Cycle in milliseconds

bool Button_Pushed = true ; //the state required for the button int i,j;

void setup() { /configurate the output relays to be begin "low"/ pinMode(Relay_1 , OUTPUT); digitalWrite(Relay_1, LOW);

pinMode(Relay_2 , OUTPUT); digitalWrite(Relay_2 , LOW); /===========================================================/ /configurate the input switch and sensor/ pinMode(Prox_Input , INPUT); pinMode(Switch_Input , INPUT_PULLUP); /===========================================================/ /configurate Serial port if you want it/ Serial.begin(9600); /===========================================================/ }

void loop() {

if (Check_Button() == Button_Pushed) //chech the button { for (i=1 ; i<=Cycle_Number ; i++) //the loop of the "complete" Cycle {

  for (j=1 ; j<=Sub_Cycle_Number ; j++)             //the loop of the "sub" Cycle
  {
    digitalWrite(Relay_1 , HIGH);                   
    delay(Delay_Sub_Cycle);
    digitalWrite(Relay_1 , LOW);
  
    while(digitalRead(Prox_Input) == HIGH){}          // waiting the sensor signal 
  }

  digitalWrite(Relay_2 , HIGH);
  delay(Delay_Sub_Cycle);
  digitalWrite(Relay_2 , LOW);

  delay(Delay_Cycle);
}  

} }

bool Check_Button() { int Reading_1; int Reading_2;

Reading_1 = digitalRead(Switch_Input); delay(20); Reading_2 = digitalRead(Switch_Input);

if((Reading_1 == 1) && (Reading_2 == 1)) return true; else return false; }

int Relay_1 = 10;           //first Relay
int Relay_2 = 11;           //second Relay
int Prox_Input = 12;        //input signal from proximity sensor
int Switch_Input = 13;      //the switch   

int Cycle_Number = 20;      //number of repeating number of "complete" cycle
int Sub_Cycle_Number = 20;  //number of repeating number of "sub" cycle
int Delay_Cycle=1000;       //delay of the "Complete" Cycle in milleseconds
int Delay_Sub_Cycle=500;    //delay of the "Sub" Cycle  in milliseconds

bool Button_Pushed = true ; //the state required for the button
int i,j; 

void setup() {
  /*configurate the output relays to be begin "low"*/
  pinMode(Relay_1 , OUTPUT);
  digitalWrite(Relay_1, LOW);
  
  pinMode(Relay_2 , OUTPUT);
  digitalWrite(Relay_2 , LOW);
  /*===========================================================*/
  /*configurate the input switch and sensor*/
  pinMode(Prox_Input , INPUT);
  pinMode(Switch_Input , INPUT_PULLUP);
  /*===========================================================*/
  /*configurate Serial port if you want it*/
  Serial.begin(9600);
  /*===========================================================*/
}

void loop() {
  
  if (Check_Button() == Button_Pushed)       //chech the button
  {
    for (i=1 ; i<=Cycle_Number ; i++)                   //the loop of the "complete" Cycle
    {
      
      for (j=1 ; j<=Sub_Cycle_Number ; j++)             //the loop of the "sub" Cycle
      {
        digitalWrite(Relay_1 , HIGH);                   
        delay(Delay_Sub_Cycle);
        digitalWrite(Relay_1 , LOW);
      
        while(digitalRead(Prox_Input) == HIGH){}          // waiting the sensor signal 
      }

      digitalWrite(Relay_2 , HIGH);
      delay(Delay_Sub_Cycle);
      digitalWrite(Relay_2 , LOW);

      delay(Delay_Cycle);
    }  
  }
}

bool Check_Button()
{
  int Reading_1;
  int Reading_2;
  
  Reading_1 = digitalRead(Switch_Input);
  delay(20);
  Reading_2 = digitalRead(Switch_Input);

  if((Reading_1 == 1) && (Reading_2 == 1))
    return true;
  else
    return false;
}
Source Link

can someone check my code, my Arduino isn't doing a consistent count cycle

Wondering if someone could have a look at my code and let me know if there's something wrong with it. I had the code done for me a while back and did a quick test and it seemed to work. I have now built a pneumatic machine for it to work on, and it's doing some strange things.

The first relay turns on and off a pneumatic solenoid, this is connected to a small pneumatic cylinder, it moves in and out. This cylinder causes a pneumatic feeder to activate and move back and forth also.

The feeder has a proximity sensor attached which lights up when the feeder is in its resting position.

The solenoid turns on for approx half a second and then back off again, this pushes the small cylinder out then back in. This sends the feeder forward, it then turns around and comes back toward its resting position. The arduino waits for the signal from the proximity sensor to tell it that the feeder is back in its resting position before doing it again.

It then repeats this sub cycle about 20 times.

After 20 sub cycles, the arduino turns on the second relay for about a second, before turning it back off again.

It then does this whole complete cycle 20 times before stopping.

There's a momentary switch as well, which when pushed, is supposed to restart everything again.

It almost works, the closest i have had is where it was doing the cycles but counting them wrong. i changed the subcycle to 16 instead of 20 and it would count somewhere between 10 and 16. it seems to count different each time.

I just bought a new board and tried again, but now it counts to about five subcycles and then jumps the gun and doesn't wait for the signal from the proximity sensor before doing the next sub cycle. So once again the count ends up wrong. Any ideas on what i could try?

int Relay_1 = 10; //first Relay int Relay_2 = 11; //second Relay int Prox_Input = 12; //input signal from proximity sensor int Switch_Input = 13; //the switch

int Cycle_Number = 20; //number of repeating number of "complete" cycle int Sub_Cycle_Number = 20; //number of repeating number of "sub" cycle int Delay_Cycle=1000; //delay of the "Complete" Cycle in milleseconds int Delay_Sub_Cycle=500; //delay of the "Sub" Cycle in milliseconds

bool Button_Pushed = true ; //the state required for the button int i,j;

void setup() { /configurate the output relays to be begin "low"/ pinMode(Relay_1 , OUTPUT); digitalWrite(Relay_1, LOW);

pinMode(Relay_2 , OUTPUT); digitalWrite(Relay_2 , LOW); /===========================================================/ /configurate the input switch and sensor/ pinMode(Prox_Input , INPUT); pinMode(Switch_Input , INPUT_PULLUP); /===========================================================/ /configurate Serial port if you want it/ Serial.begin(9600); /===========================================================/ }

void loop() {

if (Check_Button() == Button_Pushed) //chech the button { for (i=1 ; i<=Cycle_Number ; i++) //the loop of the "complete" Cycle {

  for (j=1 ; j<=Sub_Cycle_Number ; j++)             //the loop of the "sub" Cycle
  {
    digitalWrite(Relay_1 , HIGH);                   
    delay(Delay_Sub_Cycle);
    digitalWrite(Relay_1 , LOW);
  
    while(digitalRead(Prox_Input) == HIGH){}          // waiting the sensor signal 
  }

  digitalWrite(Relay_2 , HIGH);
  delay(Delay_Sub_Cycle);
  digitalWrite(Relay_2 , LOW);

  delay(Delay_Cycle);
}  

} }

bool Check_Button() { int Reading_1; int Reading_2;

Reading_1 = digitalRead(Switch_Input); delay(20); Reading_2 = digitalRead(Switch_Input);

if((Reading_1 == 1) && (Reading_2 == 1)) return true; else return false; }

enter image description here