Need some help with my code

trying to make a motion activated LED light, When I run the program the light just turns on and doesn't turn off, I'm beginning to suspect its an issue with my motion sensor but if you spot anything pls lmk. Sorry if I'm doing this wrong, It's my first time posting anything.

Hardware:
HC-SR501 PIR sensor
RGB LED
Elegoo UNO R3 board

coding:

#define pirsensor 1
#define LEDRED 4
#define LEDGREEN 3
#define LEDBLUE 2
int reading;
void setup() {
  pinMode(pirsensor, INPUT);
  pinMode(LEDRED, OUTPUT);
  pinMode(LEDGREEN, OUTPUT);
  pinMode(LEDBLUE, OUTPUT);
  Serial.begin(9600);
}
void loop() {
  reading = digitalRead(pirsensor);
  if (reading == HIGH) {
    Serial.println("motion");
    analogWrite(LEDRED, 0);
    analogWrite(LEDGREEN, 122);
    analogWrite(LEDBLUE, 200);
    delay(1000);

  }else {
    Serial.println("no motion");
    analogWrite (LEDRED, 0);
    analogWrite (LEDGREEN, 0);
    analogWrite (LEDBLUE, 0);
  }
}

I think that's all, please let me know if you see anything wrong.

Hi @meatnapkin ,

Welcome to the forum..

try a different pin for the pir, pin 1 is serial tx..

good luck.. ~q

Ill give it a shot, thanks!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.