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