Arduino Fading Light
int inputPin = 10; // choose the input pin (for the PIR sensor)
int LDR = 0; // select the input pin for the LDR:A0
int ledPin = 11; // select the pin for the LED:gate of mosfet
int valone = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600); //start te serial monitor
pinMode(LDR, INPUT); // declare the LDR as an INPUT
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT: Connect IRF520 gate here.
pinMode(inputPin, INPUT); // declare pushbutton as input:PIR
}
void loop() {
valone = analogRead(LDR); // read the value from the sensor
int val = digitalRead(inputPin); // read input value from PIR sensor
//Serial.println(valone); //prints the LDR values to serial monitor
if (val == HIGH && valone < 100) // check if the input is HIGH from PIR and LDR and darkness setting
{
digitalWrite(ledPin, HIGH); // turn LED pin 11 on if motion detected
delay(30000);
int delayTime = 50;
for (int i = 255; i > 0; i--) // slowly turn the led off
{
analogWrite(ledPin, i);
delay(delayTime);
digitalWrite(ledPin, LOW);
}
}
}