I am trying to write this code so that i can get a servo to actuate something for me on a delay. I am almost entirely following a video on Youtube created by Rachel De Barros ( Motion-activated Servo Motors with Arduino and PIR Sensor) but ive run into an issue. I included the Servo Library and im trying to "Declare" my servo as largeservo as you can see below in my copy pasted code (dont know a better way to do this) however i keep getting an error "Compilation error: 'largeServo' was not declared in this scope. I thought this was a global declaration and i have even tried to put that declaration into every scope but it makes no difference. also dont know if it matters but when i include the servo library my <Servo.h> does not change colors like other peoples do and neither does my declaration line Servo largeServo;
Can anyone help me understand whats wrong please!?!?
Thank you in advance
#include <Servo.h>
Servo largeServo;
int pirPin = 12;
int servoPin = 9;
int motionStatus = 0;
int pirState = 0;
void setup() {
Serial.begin(9600);
pinMode (pirPin, INPUT);
largeServo.attach(servoPin);
largeServo.write(0);
delay(1000);
}
void loop() {
motionStatus + digitalRead(pirPin);
if (motionStatus == HIGH) {
largeServo.write(90);
delay(3000);
largeServo.write(0);
if (pirState == LOW) {
Serial.println("Motion Detected");
pirState = HIGH;
}
}
else {
if(pirState == HIGH) {
Serial.println("Motion Ended");
pirState = LOW;
}
}
}