light sensor module controled code

Hello Everyone

I am just starting out with arduino. my first project is a outdoor light box for the cat run.

i am running an LED module controlled by a PIR sensor on a 4 minute delay. Because this is a night time only sensor i have added a Light sensor module (3pin) but am having some issues with coding.

i want to set the code so that during the day the PIR and LED are always off and after dusk the LED runs off the PIR module.

the current code i am running is one i found on the internet. can anyone tell me what i need to add in make the light sensor module work?

int ledPin = 13; // choose the pin for the LED int inputPin = 2; // choose the input pin (for PIR sensor) int pirState = LOW; // we start, assuming no motion detected int val = 0; // variable for reading the pin status int lightLevel;

void setup() { pinMode(ledPin, OUTPUT); // declare LED as output pinMode(inputPin, INPUT); // declare sensor as input

Serial.begin(9600); }

void loop(){ lightLevel = analogRead(A0); val = digitalRead(inputPin); // read input value if (val == HIGH) { // check if the input is HIGH digitalWrite(ledPin, HIGH); // turn LED ON if (pirState == LOW) { // we have just turned on Serial.println("LED ON!"); delay(40000); // We only want to print on the output change, not state pirState = HIGH;

} } else { digitalWrite(ledPin, LOW); // turn LED OFF if (pirState == HIGH){ // we have just turned off Serial.println("LED OFF!"); // We only want to print on the output change, not state pirState = LOW; } } }

The best way to learn is by doing it yourself.

Rather than asking us to work though this, do it yourself then ask about what you do not understand.

Consider what happens in any circumstances that you can think of.

Weedpharma