hello,
I've bought an Arduino last week and I do therefore a bit of experimentation, but I have one problem , I have a PIR sensor and a photoressistor and the idea is that if it is dark and when the PIR sensor detects movement that then the LEDs turn on. But I tried many codes and i can't get it work, What I did succeed , the sensors separately controlling for example, that if the photoressistor doesn't see light that the LED turns on. does anyone know how I can get this working? I made this code:
int led = 13; // The pin where the LED light is attached (LED)
int sensor = 2; // The pin where the sensor is attached to (PIR sensor)
photoressistor int = 7;
int state = LOW;
int val = 0;
void setup () {
pinMode (LED, OUTPUT); // Led as exhausts
pinMode (sensor, INPUT); // Light sensor input
pinMode (sensor, INPUT); // Motion sensor input
Serial.begin (9600);
}
void run () {
val = digital read (sensor); // View motion sensor
if (val == HIGH)
val = digital read (photoressistor); // light sensor View
if (val == LOW) {
Digital write (LED, HIGH); // Do the led to
}
else {
Digital write (led, LOW); // Do the LED out
delay (200); // Waits 200 milliseconds
if (state == HIGH)
Serial.println ("movement stopped!");
state = LOW; // Update to "low"
if (state == LOW)
Serial.println ("Light");
state = HIGH;
}
}
I hope that someone can help me!