title: I've connected servo and PIR with NodeMCU and Servo isn't working
body: <p>I've connected NodeMCU with Pir Sensor and Servo Motor and the code is for rotating the servo whenever motion is detected so I've put to rotate it once I <code>void setup()</code> and that works fine but later in <code>void loop()</code> it doesn't worked</p>
  
  <pre><code>#include&lt;Servo.h&gt;
  Servo servo;
  int pirPin = 2;
  int state = LOW;
  void setup() {
  Serial.begin(115200);
  servo.attach(13);
  servo.write(30);
  pinMode(pirPin, INPUT);
  }
  
  void loop(){
  if(digitalRead(pirPin) == HIGH) 
      {       
      if (state == LOW) {
      Serial.println("Motion detected");
      int angle;
      servo.write(90);
      delay(1000);
      state = HIGH;
      }
  
      } else {
  
      if (state == HIGH){
    Serial.println("Motion not detected");
    servo.write(90);
    state = LOW;
    }
  
    }
    }
  </code></pre>