Expected unqualified-id before "if"

I get this error on my code please help.

int Pin1=2;
int buzz1=12;
unsigned long time;
void setup() {
pinMode (Pin1, INPUT);
pinMode (buzz1, OUTPUT);
Serial.begin(9600);
}
void loop() {
int sensorValue1 = digitalRead(Pin1);
}

if (sensorValue1==0)
{
digitalWrite(buzz1, HIGH); }
else
digitalWrite(buzz1, LOW);
time = millis();
Serial.print(time);
Serial.print("\t");
Serial.print(sensorValue1);
Serial.print("\n");
delay(100);

"expected unqualified-id before 'if' "

The "if" is not in any function.

1 Like

Check your curly braces.

Use Ctrl + T in the IDE to Auto Format your code.

1 Like

Please read the guide on HOW TO POST CODE
and EDIT your first post, replacing the wrongly inserted code block.

Thanks :hugs:

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.