I am working on this code to turn a servo when the PIR motion sensor detects no motion, but it is not working. Some symptoms include:
- Servo is turning extremely slowly
- PIR is not turning the servo
- Servo is turning to incorrect angles
I have tried test programs, and when I type in the serial monitor, the servo turns (slowly and inaccurately) (I coded the serial monitor to do this). I have input from the PIR sensor but it is constantly high, even after waiting 2 minutes for it to initialize. My code and schematic are shown below.
My code:
#include <Servo.h>
Servo servo;
void setup() {
// put your setup code here, to run once:
servo.attach(13);
pinMode(2, INPUT);
Serial.begin(9600);
Serial.println("Please wait");
delay(60000);
}
void ifMos() {
if (digitalRead(2) == HIGH) {
int USER = 270;
}
}
void loop() {
// put your main code here, to run repeatedly:
int USER = Serial.parseInt();
servo.write(USER);
Serial.println(USER);
ifMos();
delay(10000);
}