You are saying "if (i=0)" when you mean "if (i == 0)".
Since things happen in sequence anyway you can get rid of the loop since each time through the loop a different block of code is executed:
for(i=0; i<3; i++) {
if (i=0) {
digitalWrite(led1, HIGH);
delay(200);
digitalWrite(led2, LOW);
delay(0);
digitalWrite(led3, LOW);
delay(0);
int sensorReading = analogRead(0);
if (sensorReading > threshold) {
tone(8, NOTE_C4, 20);
tone(8, NOTE_D4, 20);
}
}
if (i=1) {
digitalWrite(led2, HIGH);
delay(200);
digitalWrite(led1, LOW);
delay(0);
digitalWrite(led3, LOW);
delay(0);
int sensorReading = analogRead(0);
if (sensorReading > threshold) {
tone(8, NOTE_A4, 20);
tone(8, NOTE_AS4, 20);
tone(8, NOTE_B4, 20);
tone(8, NOTE_C4, 20);
}
}
if (i=2) {
digitalWrite(led3, HIGH);
delay(200);
digitalWrite(led1, LOW);
delay(0);
digitalWrite(led2, LOW);
delay(0);
int sensorReading = analogRead(0);
if (sensorReading > threshold) {
tone(8, NOTE_C4, 20);
tone(8, NOTE_D4, 20);
}
}
does the same thing as:
digitalWrite(led1, HIGH);
delay(200);
digitalWrite(led2, LOW);
delay(0);
digitalWrite(led3, LOW);
delay(0);
int sensorReading = analogRead(0);
if (sensorReading > threshold) {
tone(8, NOTE_C4, 20);
tone(8, NOTE_D4, 20);
}
digitalWrite(led2, HIGH);
delay(200);
digitalWrite(led1, LOW);
delay(0);
digitalWrite(led3, LOW);
delay(0);
int sensorReading = analogRead(0);
if (sensorReading > threshold) {
tone(8, NOTE_A4, 20);
tone(8, NOTE_AS4, 20);
tone(8, NOTE_B4, 20);
tone(8, NOTE_C4, 20);
}
digitalWrite(led3, HIGH);
delay(200);
digitalWrite(led1, LOW);
delay(0);
digitalWrite(led2, LOW);
delay(0);
int sensorReading = analogRead(0);
if (sensorReading > threshold) {
tone(8, NOTE_C4, 20);
tone(8, NOTE_D4, 20);
}