user85833: 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);
}


user85833: 
firget about the servo for now ... write the simplest code that lights an LED when motion is detected –
-jsotola

It worked! Thank you so much.
All I had to do was add the servo library, write to the servo and upload it. Only 21 lines of code! Final code:
#include <Servo.h>
Servo servo;

void setup() {
  // put your setup code here, to run once:
  pinMode(2, INPUT);
  pinMode(3, OUTPUT);
  servo.attach(13);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(digitalRead(2) == HIGH) {
    digitalWrite(3, HIGH);
    servo.write(270);
  }
  else {
    digitalWrite(3, LOW);
    servo.write(0);
  }
}

Thank you to everyone. This was my first time posting on stack exchange, and it was a huge success. Thank you again!

85833: <p>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:</p>
<ol>
<li>Servo is turning extremely slowly</li>
<li>PIR is not turning the servo</li>
<li>Servo is turning to incorrect angles</li>
</ol>
<p>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.</p>
<p><a href="https://i.stack.imgur.com/55lFe.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/55lFe.jpg" alt="Schematic" /></a></p>
<p>My code:</p>
<pre><code>#include &lt;Servo.h&gt;
Servo servo;

void setup() {
  // put your setup code here, to run once:
  servo.attach(13);
  pinMode(2, INPUT);
  Serial.begin(9600);
  Serial.println(&quot;Please wait&quot;);
  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);
}
</code></pre>
 85833: <blockquote>
<p>firget about the servo for now ... write the simplest code that lights an LED when motion is detected –
-jsotola</p>
</blockquote>
<p>It worked! Thank you so much.
All I had to do was add the servo library, write to the servo and upload it. Only 21 lines of code! Final code:</p>
<pre><code>#include &lt;Servo.h&gt;
Servo servo;

void setup() {
  // put your setup code here, to run once:
  pinMode(2, INPUT);
  pinMode(3, OUTPUT);
  servo.attach(13);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(digitalRead(2) == HIGH) {
    digitalWrite(3, HIGH);
    servo.write(270);
  }
  else {
    digitalWrite(3, LOW);
    servo.write(0);
  }
}
</code></pre>
<p>Thank you to everyone. This was my first time posting on stack exchange, and it was a huge success. Thank you again!</p>
