Simple PIR sensor test troubleshooting

Hello I am trying to utilize the PIR sensor with conditionals in the arduino language and I wrote this very simple code to see if the sensor works;

int readpin=11;
int ledpin=7;
int readval;
void setup() {
Serial.begin(2000000);
pinMode(readpin, INPUT);
pinMode(ledpin,OUTPUT);
}

void loop() {
readval=digitalRead(readpin);
Serial.println(readval);
if (readval==1){
  pinMode(ledpin, HIGH);
  }
else {
  pinMode(ledpin,LOW);
  }
}

and it seems like the sensor does work and I see the the value of 1 on the serial monitor when it detects movement however it does not turn on the led hooked up to pin 7. I made sure the LED is actually working. (The PIR sensor out is connected to pin 11).

You meant digitalWrite(), not pinMode() to turn a LED on and off.

BTW, very good idea for getting to know a sensor.

a7

1 Like

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