Stop/Start Loop when a n number of balls pass thru a detector

Hi all

Im a total newby on arduino, im doing a project a i find some troubles that i cannot solve due to my lack of competences, maybe someone can help me.

i have a solenoid connected to a relay with a sketch that works pretty well, what i want to do is that the loop restarts when a specific number o objects are pushed by the solenoid.

Ex.
The loop starts, objects are pushed by the solenoid and pass thru a proximity detector, when the detector counts 10 objects then the loop stops for 30 sec then restarts.

This is the sketch i have at the moment:

// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

I have connected a relay with a solenoid as Led

Thanks for the help

Put everything that's currently in loop(), in a for()-loop (still inside loop() of course), and do the 30s delay after that's finished.

(Assuming that works for you right now, you might want to look at a delay-less way of doing this though. Maybe one day you will want to add a stop button for example, and right now it won't be very responsive due to the delays. )

Thanks for response, but also i need to restar the loop when a certain number of objects pas thru a laser detector...

Sorry, didn't read it carefully enough.

Before you get to specific counts, you'll need to prove to yourself that you can read the proximity detector. What is it and do you have a sketch yet to read it?

// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
prox_count = 0; //input from the prox. Whenever prox is high, we'll increment this.

digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
prox_count = prox_count +1;
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second

//if statement that sees if count is greater than or equal to 10. On the offcase the prox double counts and gets
//bigger than 10, the ">=" condition will save us some heartache.
if (prox_count >= 10){
prox_count = 0; // reset prox_count
delay(30000); // delay 30 seconds.
}

}

Thank you very much, let me try this and see what happens.