PIR Sensor Issue

My sensor is not working properly.

I have 5V connected to VCC, GND connected to GND, and Out connected to 13.

this is my code -

int inputPin = 13; // choose the input pin (for PIR sensor) int pirState = LOW; // we start, assuming no motion detected int val = 0; // variable for reading the pin status

void setup() { pinMode(inputPin, INPUT); // declare sensor as input

Serial.begin(9600); }

void loop(){ val = digitalRead(inputPin); // read input value if (pirState == LOW) { // we have just turned on Serial.println("Motion detected!"); // We only want to print on the output change, not state pirState = HIGH; }

if (pirState == HIGH){ // we have just turned of Serial.println("Motion ended!"); // We only want to print on the output change, not state pirState = LOW; } }

I'm just getting an infinite loop even if the sensor isn't connected. What am I doing wrong?

val = digitalRead(inputPin); // read input value

I don't see you actually use that value.

Maybe you mean this..

if (val == HIGH && pirState == LOW) {

Leo..

Gr1m: My sensor is not working properly.

I have 5V connected to VCC, GND connected to GND, and Out connected to 13.

this is my code -

int inputPin = 13; // choose the input pin (for PIR sensor) int pirState = LOW; // we start, assuming no motion detected int val = 0; // variable for reading the pin status

void setup() { pinMode(inputPin, INPUT); // declare sensor as input

Serial.begin(9600); }

void loop(){ val = digitalRead(inputPin); // read input value if (pirState == LOW) { // we have just turned on Serial.println("Motion detected!"); // We only want to print on the output change, not state pirState = HIGH; }

if (pirState == HIGH){ // we have just turned of Serial.println("Motion ended!"); // We only want to print on the output change, not state pirState = LOW; } }

I'm just getting an infinite loop even if the sensor isn't connected. What am I doing wrong?

Hi Gr1m,

May I take a look at your sensor's pic?