user87410: I'm making photoresister alarm. When distance under 5cm over notes[] 5 times, piezo speaker off. And I want to turn off the led rgb by pressing the 4, 5, 6 switches in sequence. The code to turn off the led rgb by pressing the 4, 5, 6 switches in sequence does not work. What's wrong? Here is a code below.
int pins[]={4,5,6};
int melody[]={262,294,330};
int notes[]={392,392,440,440,392,392,330};
int b=0,r=0,g=0;

void setup() {
  // put your setup code here, to run once:
 randomSeed(analogRead(A0));
 for(int i=0;i<3;i++){
   pinMode(pins[i],INPUT);
 }
}
int c=0;
int value1=digitalRead(4);
int value2=digitalRead(5);
int value3=digitalRead(6);

void loop() {
  // put your main code here, to run repeatedly:
  int vin=analogRead(A0);
  if (c>5){
    //  b=0,r=0,g=0;
    noTone(8);
    //analogWrite(11,b);
    //analogWrite(10,r);
    //analogWrite(9,g);
   // return;
  }
  if(digitalRead(0)==HIGH){
    if(digitalRead(1)==HIGH){
      if(digitalRead(2)==HIGH){
       b=0,r=0,g=0;
       noTone(8);
       analogWrite(11,b);
       analogWrite(10,r);
       analogWrite(9,g);
       return;
      }
    }
  }
  if(vin>800){
    for(int i=0; i<7 ;i++){
      tone(8,notes[i],100);
      delay(200);
      noTone(8);
      analogWrite(11,random(256));
      analogWrite(10,random(256));
      analogWrite(9,random(256));
      delay(200);
    }
  }
  long duration = pulseIn(3,HIGH);
  long distance=duration/58.2;
  if(duration == 0){
    return;
  }
  if (distance<5){
    c++;
  }

}

The code to turn off the RGB LED by pressing the 4, 5, 6 switches in sequence, RGB LED is off. And when distance under 5cm over notes[] 5 times, piezo speaker off.

user87320: This might not be correct because I'm new in arduino projects but i think the problem comes from here
On your setup
for (int i=0;i<3;i++) 
pinMode(i,OUTPUT);

SHOULD BE
for (int i=4;i<=6;i++)
pinMode(i,OUTPUT);

on your loop
if(digitalRead(0)==HIGH){
    if(digitalRead(1)==HIGH){
      if(digitalRead(2)==HIGH){
       b=0,r=0,g=0;
       noTone(8);
       analogWrite(11,b);
       analogWrite(10,r);
       analogWrite(9,g);
       return;
      }

I think you need to change the pin to
if digitalRead(4).....
if digitalRead(5)......
if digitalRead(6)....

Just change it that way maybe it may work.
Remember to remove the // on the b=0,r=0,g=0
And also remove the double slash // from the analogWrite
And I see you declaring value 1,2,3 and not using them.
hint...
int value1;
int value2;
int value3;
int delaytime=500; //half a second

value1=digitalRead(4); /* you are supposed to press the button on pin 4 by now */
if (value1==HIGH) {
  delay(delaytime);
  value2=digitalRead(5); /* you are supposed to press the button on pin 5 by now */

  if (value2==HIGH) {
    delay(delaytime);
    value3=digitalRead(6); /* button on pin 6 is supposed to be pressed by now */
    if (digitalRead(6)==HIGH) {
       b=0,r=0,g=0;
       noTone(8);
       analogWrite(11,b);
       analogWrite(10,r);
       analogWrite(9,g);
       return;
      }
  }
}

I added the delay because that might be the greatest problem you have. Arduino is fast at processing, so in order for it to work when you press the three button you will need to press the three all at once before it can give you the output. But if you want to press them one by one, you need to add the delay and make sure you press the three button before the delay time elapse.

87410: <p>I'm making photoresister alarm. When distance under 5cm over notes[] 5 times, piezo speaker off. And I want to turn off the led rgb by pressing the 4, 5, 6 switches in sequence. The code to turn off the led rgb by pressing the 4, 5, 6 switches in sequence does not work. What's wrong? Here is a code below.</p>
<pre><code>int pins[]={4,5,6};
int melody[]={262,294,330};
int notes[]={392,392,440,440,392,392,330};
int b=0,r=0,g=0;

void setup() {
  // put your setup code here, to run once:
 randomSeed(analogRead(A0));
 for(int i=0;i&lt;3;i++){
   pinMode(pins[i],INPUT);
 }
}
int c=0;
int value1=digitalRead(4);
int value2=digitalRead(5);
int value3=digitalRead(6);

void loop() {
  // put your main code here, to run repeatedly:
  int vin=analogRead(A0);
  if (c&gt;5){
    //  b=0,r=0,g=0;
    noTone(8);
    //analogWrite(11,b);
    //analogWrite(10,r);
    //analogWrite(9,g);
   // return;
  }
  if(digitalRead(0)==HIGH){
    if(digitalRead(1)==HIGH){
      if(digitalRead(2)==HIGH){
       b=0,r=0,g=0;
       noTone(8);
       analogWrite(11,b);
       analogWrite(10,r);
       analogWrite(9,g);
       return;
      }
    }
  }
  if(vin&gt;800){
    for(int i=0; i&lt;7 ;i++){
      tone(8,notes[i],100);
      delay(200);
      noTone(8);
      analogWrite(11,random(256));
      analogWrite(10,random(256));
      analogWrite(9,random(256));
      delay(200);
    }
  }
  long duration = pulseIn(3,HIGH);
  long distance=duration/58.2;
  if(duration == 0){
    return;
  }
  if (distance&lt;5){
    c++;
  }

}
</code></pre>
<p>The code to turn off the RGB LED by pressing the 4, 5, 6 switches in sequence, RGB LED is off. And when distance under 5cm over notes[] 5 times, piezo speaker off.</p>
 87320: <p>This might not be correct because I'm new in arduino projects but i think the problem comes from here
On your setup</p>
<pre><code>for (int i=0;i&lt;3;i++) 
pinMode(i,OUTPUT);
</code></pre>
<p>SHOULD BE</p>
<pre><code>for (int i=4;i&lt;=6;i++)
pinMode(i,OUTPUT);
</code></pre>
<p>on your loop</p>
<pre><code>if(digitalRead(0)==HIGH){
    if(digitalRead(1)==HIGH){
      if(digitalRead(2)==HIGH){
       b=0,r=0,g=0;
       noTone(8);
       analogWrite(11,b);
       analogWrite(10,r);
       analogWrite(9,g);
       return;
      }
</code></pre>
<p>I think you need to change the pin to</p>
<pre><code>if digitalRead(4).....
if digitalRead(5)......
if digitalRead(6)....
</code></pre>
<p>Just change it that way maybe it may work.
Remember to remove the // on the b=0,r=0,g=0
And also remove the double slash // from the analogWrite
And I see you declaring value 1,2,3 and not using them.</p>
<p>hint...</p>
<pre><code>int value1;
int value2;
int value3;
int delaytime=500; //half a second

value1=digitalRead(4); /* you are supposed to press the button on pin 4 by now */
if (value1==HIGH) {
  delay(delaytime);
  value2=digitalRead(5); /* you are supposed to press the button on pin 5 by now */

  if (value2==HIGH) {
    delay(delaytime);
    value3=digitalRead(6); /* button on pin 6 is supposed to be pressed by now */
    if (digitalRead(6)==HIGH) {
       b=0,r=0,g=0;
       noTone(8);
       analogWrite(11,b);
       analogWrite(10,r);
       analogWrite(9,g);
       return;
      }
  }
}
</code></pre>
<p>I added the delay because that might be the greatest problem you have. Arduino is fast at processing, so in order for it to work when you press the three button you will need to press the three all at once before it can give you the output. But if you want to press them one by one, you need to add the delay and make sure you press the three button before the delay time elapse.</p>
