Functions: Syntax Error

Hello everybody! I am pretty new to Arduino and am trying to use the RFID module, the buzzer, two LED's, and a motion sensor to create a project where when motion is detected, the buzzer sounds until you scan your RFID tag. I am running into an error. I put the code below. The error codes are at the bottom as well.

#include <SPI.h>
#include <MFRC522.h>
int red = 4;
int green = 5;
int buzzer = 7;
int sensor = 2;
int state = LOW;
int val = 0;
long duration, inches;
#define SS_PIN 10
#define RST_PIN 9
#define BUZZER 1 //buzzer pin
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.

void setup() {
  // put your setup code here, to run once:
  String content = "";
  Serial.begin(9600);   // Initiate a serial communication
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
  pinMode(green, OUTPUT);
  pinMode(red, OUTPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(sensor, INPUT);


}

void loop() {
  // put your main code here, to run repeatedly:
  val = digitalRead(sensor);
  Serial.println(state);
  motion();
  rfid();
 

  // if (content.substring(1) == "53 E7 96 05") //enter card number(S) here
  //above line is what you use to find out the RFID status
  //if (inches < x) use for UltraSonic

  if (content.substring(1) == "53 E7 96 05" or content.substring(1) == "93 ED 8E 0D" {
    state == high
  }



  void rfid() {

    // Look for new cards
    if ( ! mfrc522.PICC_IsNewCardPresent())
    {
      return;
    }
    // Select one of the cards
    if ( ! mfrc522.PICC_ReadCardSerial())
    {
      return;
    }
    //Show UID on serial monitor
    Serial.print("UID tag :");
    Serial.println();
    String content = "";
    byte letter;
    for (byte i = 0; i < mfrc522.uid.size; i++)
    {
      Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
      Serial.print(mfrc522.uid.uidByte[i], HEX);
      content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
      content.concat(String(mfrc522.uid.uidByte[i], HEX));
    }
    Serial.println();
    Serial.print("Message : ");
    content.toUpperCase();
  }

  void motion() {
    if (val == HIGH) {           // check if the sensor is HIGH
      digitalWrite(red, HIGH);   // turn LED ON
      delay(500);                // delay 100 milliseconds

      if (state == LOW) {
        Serial.println("Motion detected!");
        blinkRed();
        tone(buzzer, 150);
        state = HIGH;       // update variable state to HIGH

      }
    }
    else {
      digitalWrite(led, LOW); // turn LED OFF
      delay(500);             // delay 200 milliseconds

      if (state == HIGH) {
        Serial.println("Motion stopped!");
        blinkGreen();
        noTone(buzzer)
        state = LOW;       // update variable state to LOW
      }
    }
  }

  void blinkRed() {
    digitalWrite(red, HIGH);
    delay(100);
    digitalWrite(red, LOW);
    delay(100);
  }

  void blinkGreen() {
    digitalWrite(green, HIGH);
    delay(100);
    digitalWrite(green, LOW);
    delay(100);
  }






Arduino: 1.8.19 (Mac OS X), Board: "Arduino Uno"

/Users/(SENSORD)/Documents/Arduino/FinalProject/FinalProject.ino: In function 'void loop()':
FinalProject:33:3: error: 'motion' was not declared in this scope
motion();
^~~~~~
/Users/(SENSORD)/Documents/Arduino/FinalProject/FinalProject.ino:33:3: note: suggested alternative: 'min'
motion();
^~~~~~
min
FinalProject:34:3: error: 'rfid' was not declared in this scope
rfid();
^~~~
/Users/(SENSORD)/Documents/Arduino/FinalProject/FinalProject.ino:34:3: note: suggested alternative: 'red'
rfid();
^~~~
red
FinalProject:41:7: error: 'content' was not declared in this scope
if (content.substring(1) == "53 E7 96 05" or content.substring(1) == "93 ED 8E 0D" {
^~~~~~~
FinalProject:41:86: error: expected ')' before '{' token
if (content.substring(1) == "53 E7 96 05" or content.substring(1) == "93 ED 8E 0D" {
^
FinalProject:114:3: error: expected statement at end of input
}
^
FinalProject:114:3: error: expected '}' at end of input
Multiple libraries were found for "MFRC522.h"
Used: /Users/(SENSORD)/Documents/Arduino/libraries/MFRC522
Not used: /Users/(SENSORD)/Documents/Arduino/libraries/rfid-master
exit status 1
'motion' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Arduino: 1.8.19 (Mac OS X), Board: "Arduino Uno"

/Users/(SENSORD)/Documents/Arduino/FinalProject/FinalProject.ino: In function 'void loop()':
FinalProject:33:3: error: 'motion' was not declared in this scope
motion();
^~~~~~
/Users/(SENSORD)/Documents/Arduino/FinalProject/FinalProject.ino:33:3: note: suggested alternative: 'min'
motion();
^~~~~~
min
FinalProject:34:3: error: 'rfid' was not declared in this scope
rfid();
^~~~
/Users/(SENSORD)/Documents/Arduino/FinalProject/FinalProject.ino:34:3: note: suggested alternative: 'red'
rfid();
^~~~
red
FinalProject:41:7: error: 'content' was not declared in this scope
if (content.substring(1) == "53 E7 96 05" or content.substring(1) == "93 ED 8E 0D" {
^~~~~~~
FinalProject:41:86: error: expected ')' before '{' token
if (content.substring(1) == "53 E7 96 05" or content.substring(1) == "93 ED 8E 0D" {
^
FinalProject:114:3: error: expected statement at end of input
}
^
FinalProject:114:3: error: expected '}' at end of input
Multiple libraries were found for "MFRC522.h"
Used: /Users/(SENSORD)/Documents/Arduino/libraries/MFRC522
Not used: /Users/(SENSORD)/Documents/Arduino/libraries/rfid-master
exit status 1
'rfid' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Thank you

Any wisdom is helpful.

Thank you.

A simplified version of the problem below:


int led = 2;
void setup(){
pinMode(2, HIGH);

void loop(){
blink():
}

void blink()[
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000)
//thank you

looks like your right and left braces are not matched.

Do auto-format in arduino (Ctrl-T) and it will be easier to look for braces.

I don't understand what that means. :frowning_face:

You missed the right brace at the end of blink() procedure

That was just an error of me typing it in. In the code it is not like that. The current errors that I am getting are about not declaring "motion" or "rfid' in the scope.

You have a lot typos in this code:

After fixing all of this the code compiled fine.
So your problem has nothing to do with function blink()

Find similar errors in your main code and fix it.

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project.

For a newbie - it is good to remember, when faced with compiler errors, that a single code error can result in many, many compile errors, and that those errors are 'symptoms' of a problem, but do not necessarily point directly at the error. Why? The compiler may parse many lines between your innocent error and the first line where that error makes the compiler say "huh? No comprendo!", because until you, for example, actually use that variable who's scope is incorrect due to poor {} placement, the compiler doesn't have any sense that theres a problem.

If a statement goes off the side of the window it make it harder to notice that there is a ')' missing near the end of the line.

In johnwassers sample :slight_smile:
state == high
should be state = HIGH; // it’s an assignment (not ==)

and perhaps should end with a ';' - since we're correcting corrections, let's correct correctly!

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