Once procuctC =5 I want the boxC to add one to the boxC

productC = 1;
while (productC <= 5) {
  Serial.println(productC);
  productC = productC + 1; 
  delay(T); 
}
boxC = 0;
if (productC == 5) {
  boxC = boxC + 1;
  Serial.println(boxC);
  delay(T);
  
  
}

Serial.println(" Box is full");
Serial.println(" Full boxes");
delay(T);

the productC stops at 5 but nothing gets added to boxC

Welcome to the forum

Your topic was MOVED to its current forum category which is more appropriate than the original

Please post your full sketch using code tags when you do

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Look at Your code. What makes the while end?
What do You think boxC = 0 does?

1 Like

There is no second while. It's just an if.

1 Like

I want boxC = 0 because its not full until 5 productC is in it.
Should I "break" after the while loop to get the box counter to work?
Im new to this

Why do You reply to only one of the questions?
Take pen and paper and note what is happening for every iteration.

Corrected now.

I thought I responded to both, my bad.
When I bring u the serial monitor it counts to 5 and prints" Box is full" and right below that is prints "Full boxes". My logic is that after 5 it will add 1 to the box.

Thanks for the responses!

is that code in the loop?

if so you do boxC = 0;at every iteration, so boxC will never go above 1

side note : Don't post snippets (Snippets R Us!)

1 Like

I took out boxC = 0; and its kinda working, thank you!

kinda ? or fully working ?

post your full code if you still have questions

nope
This code won't work as you expecting

Yeah it works. I just had to change a few other things. Thank you for the help. I’ll probably be back with more questions soon

When while runs and the count == 5 it increments to 6 at the end. Then in the if statement You test if count == 5, but it is 6 now..... the if will not execute.

1 Like

This Is what I ended up with. Now I need to figure out how to get it to restart the loop after the first pallet is filled.

int productC;
int boxC;
int palletC;
int T = 300;
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:

productC = 0;
while (productC <= 5) {
  Serial.println(productC);
  productC = productC + 1; 
  delay(T); 
}
Serial.println("Box is full");
Serial.println();

do  {
  boxC = boxC + 1;
  
} while (productC ==5);
  
  Serial.print(boxC);
  Serial.println(" Full boxes");
  Serial.println( );
  delay(T);
  
 do {
  palletC = palletC + 1;
  
 } while (boxC == 6);
  Serial.print(palletC);
  Serial.print(" Boxes on pallet");
  Serial.println( );
  Serial.println( );
  delay(T);

  if (palletC == 6) {
    Serial.println("Pallet is full");
    delay(T);
  }
 
}  

Please post your code according to forum guidelines and fix your post above.

How is that? do I put </> before and after the code?

According to the forum guide, which has been cunningly hidden so that no one will ever read it by using the words "please read it".

You should post code by using code-tags. There are two simple ways to do this.

First way is to click on the code tags icon at the top of the posting window
ArduinoForum

Another wasy is to use an automatic function for doing this in the Arduino-IDE.

Three steps

1)press Ctrl-T for autoformatting your code
2)do a rightclick with the mouse and choose "copy for forum"
3)paste clipboard into write-window of a posting

1 Like

Thank you for adding the code tags. Your code will repeat correctly with this change to the end of your sketch

Serial.print(palletC);
  Serial.print(" Boxes on pallet");
  Serial.println( );
  Serial.println( );
  delay(T);
  productC=0;
  boxC=0;
 

  if (palletC == 6) {
    Serial.println("Pallet is full");
    palletC=0;
    delay(T);
  }