Programming PIR sensor

So I have already had some help from the forum. I am trying to make the led toggle with an PIR sensor (change the state of the led to the opposite when a movement is detected. led is off-movement-the led is on-movement- led off again etc). This is the code I have so far. There is a problem the led is constantly on so I wanted to see the reading on the serial screen and it is constantly at 0. I have no idea what is wrong with the code.

int inPin = A0; // the number of the input pin
int outPin = 10; // the number of the output pin

int state = HIGH; // the current state of the output pin
int reading; // the current reading from the input pin
int previous = LOW; // the previous reading from the input pin

// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase if the output flickers
int minval=0;//= the minimal value of the sensor- i dont know it yet)
int maxval=1023; //= maximum value of the sensor - i dont know it yet)

void setup()
pinMode(inPin, INPUT);
pinMode(outPin, OUTPUT);

void loop()

reading = digitalRead(inPin);
reading = map(1,minval,maxval,0,1);

// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading == 1 && previous == 0 && millis() - time > debounce) {
if (state == HIGH)
state = LOW;
state = HIGH;

time = millis();

digitalWrite(outPin, state);

previous = reading;

Any help is big help :slight_smile:
Thank You!

The sensor gives 0 or 1. Depends on which one you actually have to know which it gives when movement sensed. Scrap all that min max val stuff.

Once you know what value it gives on detection, you only care when it is a new one.

Then it’s just doing something like using a bool variable named state, for example.
digitalWrite (led, state);
state = !state;

And if you've already received help, that means you've created another thread for the same project, where you were probably told to post using code tags. So you've crossposted as well as ignored forum guidelines of posting code again.