How do I make a toggleable Infrared motion detection module I just got an Arduino and an Infrared motion detection module. What I tried making is, that if the module detected movement, a led would turn on, and if it detected movement again, it would turn off. So I wrote this code and tried looking online for solutions, but couldn't find it. I really don't know what to change about my code to make it work. Does anyone have solutions for this? 

(Sensor value can be 0 or 1, 0 means nothing detected, 1 means something detected. After detection the value automatically goes back to 0 in a few seconds)

int Sensor = 4;
int led = 13;
bool bool1 = false;

void setup() {
pinMode(Sensor, INPUT);
pinMode(led, OUTPUT);
Serial.begin(9600);
}

void loop() {
int SensorValue = digitalRead(Sensor);

if(SensorValue == 1){
  bool1 = !bool1;
  }

if(bool1 == true){
  digitalWrite(led, HIGH);
  }
if(bool1 == false){
  digitalWrite(led, LOW);
  }
}
Consider using a state machine with 4 states.  Currently you only have 2 states.  One where "bool1" is TRUE and another when "bool1" is FALSE.  The 4 states needed are: 


When the LED is OFF &amp; the PIR is NOT-ACTIVE. 
When the LED is OFF &amp; the PIR is ACTIVE. 
When the LED is ON and the PIR is ACTIVE. 
When the LED is ON and the PIR is NOT-ACTIVE.


As you travel between these 4 states, you will find you only want to turn the LED ON when traveling between states 2 &amp; 3.  And you will only want to turn the LED OFF when traveling between states 4 &amp; 1.