1

I wanted the sensor to be high when I press the button, but when DigitalRead does low, the LED turns on, when it does high, the LED goes off. Whereas when the digitalRead is high, isn't it supposed to turn on the led?

int pirPin = 8;
int ledPin = 13;
int state;
unsigned long previousMillis = 0;        // will store last time LED was updated
const long interval = 1000;

void setup() { pinMode(pirPin, INPUT); pinMode(ledPin, OUTPUT);

}

void loop() {

unsigned long currentMillis = millis(); state = digitalRead(pirPin); Serial.println(durum);

if (state == HIGH) { previousMillis = currentMillis; } if (currentMillis - previousMillis >= interval) { digitalWrite(ledPin, LOW); } else digitalWrite(ledPin, HIGH); }

chrisl
  • 16,622
  • 2
  • 18
  • 27
Sabri73
  • 51
  • 8

0 Answers0