I want to light one led with two sensors, the first one is a PIR and the other one is a Photocell sensor.
The idea is to turn on the led if the PIR sensor detects movement, and also to turn the led on if the room gets darker(detected by the photocell).
I managed to make a code, but with TWO led's, a different one for every sensor.
int ledPin = 13;
int ledPin1=12;
const int ldrPin = A0;
int inputPin = 2;
int pirState = LOW;
int val = 0;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(ledPin1, OUTPUT);
pinMode(inputPin, INPUT);
pinMode(ldrPin, INPUT);
}
void loop() {
int ldrStatus=analogRead(ldrPin);
if(ldrStatus<=400)
{
digitalWrite(ledPin, HIGH);
delay(500);
Serial.println("LED ON");
}
else digitalWrite(ledPin, LOW);
val = digitalRead(inputPin);
if (val == HIGH) {
digitalWrite(ledPin1, HIGH);
if (pirState == LOW) {
Serial.println("Motion detected!");
pirState = HIGH;
}
} else {
delay(5000);
digitalWrite(ledPin1, LOW);
if (pirState == HIGH){
Serial.println("Motion ended!");
pirState = LOW;
}
}
}
pirState
come from? It hasn't been defined or initialized. And what signal is oninputPin
? The general logic for doing something depending on either of two conditions isif( condition1 || condition2 ){ // do something here }
I want to light one led with two sensors
.... you wantmonitor two sensors and light one LED
.... you said that you have done it with two LEDs, so just modify your code so that both sensors have to satisfy a goal before the LED is activated