user73304: //Make an LED Turn ON after pressing a push button switch for five times. Add a reset switch to turn OFF the LED whenever the reset switch is pressed

**void setup()

{
  
  pinMode(11, OUTPUT);

  pinMode (4,INPUT);

}

void loop()

{

  int y= digitalRead(6); // push button 2

  static int counter {} ; 

  int x= digitalRead(4);// push button 1 

  if (x==1&& y==0 )
   
    counter++;

else if (counter == 5) // If counter is pressed 5 times

{

  digitalWrite(11, HIGH); // Turn on the LED

}

if (counter >= 5) // If counter is greater than 5 led will still on

{

  digitalWrite (11, 1);

 
}

  else if 

  
   (y==1&& x==0 ) // if pressed push button 2  led of 
  {

    digitalWrite(11,0);

  
}

  counter = 0; // Make counter variable = 0

}



user73341: You can try implementing a counter system in your Arduino program.
For example, if this is your loop() function:
void loop(){
int buttonState = digitalRead(1); // Give the variable buttonState the value of pin 1, or whatever your button is connected to
static int counter{}; // Have a counter variable. Static means it doesn't reset to 0 after loop() restarts

if (buttonState == HIGH) // If the button is pressed
{
  ++counter; // Increase the value of counter by 1
}

else if (counter == 5) // If counter is pressed 5 times
{
  digitalWrite(11, HIGH); // Turn on the LED
}
// RESET:
if (counter > 5) // If counter is greater than 5 (you clicked the button again)
{
  digitalWrite (11, LOW);
  counter = 0; // Make counter variable = 0
}
} 

Edit In the comments, Python Schlage made very good suggestions: to change buttonState to a boolean and change int to byte to save space on board the Arduino
Try following this tutorial: https://www.arduino.cc/en/Tutorial/BuiltInExamples/Button and modifying it to work with the counter.
Hope this helps! Please let us know if you need help with the setup() function or if anything is unclear.

73304: <pre><code>//Make an LED Turn ON after pressing a push button switch for five times. Add a reset switch to turn OFF the LED whenever the reset switch is pressed

**void setup()

{
  
  pinMode(11, OUTPUT);

  pinMode (4,INPUT);

}

void loop()

{

  int y= digitalRead(6); // push button 2

  static int counter {} ; 

  int x= digitalRead(4);// push button 1 

  if (x==1&amp;&amp; y==0 )
   
    counter++;

else if (counter == 5) // If counter is pressed 5 times

{

  digitalWrite(11, HIGH); // Turn on the LED

}

if (counter &gt;= 5) // If counter is greater than 5 led will still on

{

  digitalWrite (11, 1);

 
}

  else if 

  
   (y==1&amp;&amp; x==0 ) // if pressed push button 2  led of 
  {

    digitalWrite(11,0);

  
}

  counter = 0; // Make counter variable = 0

}
</code></pre>
<p><a href="https://i.stack.imgur.com/ILLSb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ILLSb.png" alt="enter image description here" /></a></p>
 73341: <p>You can try implementing a counter system in your Arduino program.</p>
<p>For example, if this is your loop() function:</p>
<pre><code>void loop(){
int buttonState = digitalRead(1); // Give the variable buttonState the value of pin 1, or whatever your button is connected to
static int counter{}; // Have a counter variable. Static means it doesn't reset to 0 after loop() restarts

if (buttonState == HIGH) // If the button is pressed
{
  ++counter; // Increase the value of counter by 1
}

else if (counter == 5) // If counter is pressed 5 times
{
  digitalWrite(11, HIGH); // Turn on the LED
}
// RESET:
if (counter &gt; 5) // If counter is greater than 5 (you clicked the button again)
{
  digitalWrite (11, LOW);
  counter = 0; // Make counter variable = 0
}
} 
</code></pre>
<p><em>Edit</em> In the comments, Python Schlage made very good suggestions: to change <code>buttonState</code> to a boolean and change <code>int</code> to <code>byte</code> to save space on board the Arduino</p>
<p>Try following this tutorial: <a href="https://www.arduino.cc/en/Tutorial/BuiltInExamples/Button" rel="nofollow noreferrer">https://www.arduino.cc/en/Tutorial/BuiltInExamples/Button</a> and modifying it to work with the counter.
Hope this helps! Please let us know if you need help with the setup() function or if anything is unclear.</p>
