I get the error "52:1: error: expected unqualified-id before '{' token". I'm using tinkercad to program my project before I assemble it. This code is for a PIR sensor and a buzzer combined with the coding for a ultrasonic sensor with a buzzer. I'm very new to coding I've never done it before so I used a two YouTube videos to help me with the circuit and the coding. the error is the "{" above the line "//Clears the trigPin"
int pinSensor =2;
int pinLed =12;
int pinBuzzer =13;
int pirSensor =0;
const int trigPin = 9;
const int echoPin = 10;
const int buzzer = 11;
const int ledPin = 13;
long duration;
int distance;
int safetyDistance;
void setup()
{
pinMode(pinSensor, INPUT);
pinMode(pinLed, OUTPUT);
pinMode(pinBuzzer, OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(buzzer, OUTPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
pirSensor = digitalRead(pinSensor);
if (pirSensor == HIGH)
{
digitalWrite(pinLed, HIGH);
tone(pinBuzzer, 1000, 500);
}
else {
digitalWrite(pinLed, LOW);
}
delay(10);
}
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance= duration*0.034/2;
safetyDistance = distance;
if (safetyDistance <= 5){
digitalWrite(buzzer, HIGH);
digitalWrite(ledPin, HIGH);
}
else{
digitalWrite(buzzer, LOW);
digitalWrite(ledPin, LOW);
}
Serial.print("Distance: ");
Serial.println(distance);
}
What I have tried:
I tried searching on how to combine two codes