0% found this document useful (0 votes)
5 views1 page

Smart Solar Powered Project

The document contains a code snippet for an Arduino project that controls an LED based on light and motion detection. It uses a Light Dependent Resistor (LDR) to determine if it is day or night and a PIR sensor to detect motion. The LED brightness is adjusted accordingly, with full brightness during night and motion detection, and a lower brightness for energy saving when no motion is detected.

Uploaded by

swapnilnaio9
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Smart Solar Powered Project

The document contains a code snippet for an Arduino project that controls an LED based on light and motion detection. It uses a Light Dependent Resistor (LDR) to determine if it is day or night and a PIR sensor to detect motion. The LED brightness is adjusted accordingly, with full brightness during night and motion detection, and a lower brightness for energy saving when no motion is detected.

Uploaded by

swapnilnaio9
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

// Pin Definitions

const int LDR_PIN = A0; // LDR connected to Analog Pin 0


const int PIR_PIN = 2; // PIR sensor connected to Digital Pin 2
const int LED_PIN = 9; // LED connected to PWM Pin 9

// Thresholds
const int DARK_THRESHOLD = 500; // Adjust based on your room lighting
int ldrValue = 0;
bool motionDetected = false;

void setup() {
pinMode(PIR_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
[Link](9600); // For debugging via Serial Monitor
}

void loop() {
ldrValue = analogRead(LDR_PIN);
motionDetected = digitalRead(PIR_PIN);

if (ldrValue > DARK_THRESHOLD) {


// It is NIGHT time
if (motionDetected) {
analogWrite(LED_PIN, 255); // 100% Brightness (Full Power)
} else {
analogWrite(LED_PIN, 50); // ~20% Brightness (Energy Saving Mode)
}
} else {
// It is DAY time
analogWrite(LED_PIN, 0); // Light OFF
}

delay(100); // Stability delay


}

You might also like