Introduction

This project shows how to make a simple system that turns lights on and off by itself. It uses an Arduino (a small computer) and an LDR (Light Dependent Resistor). The light comes on when it is dark and turns off when it is bright.

How It Works

We need three main parts

The Circuit

Circuit

The Code (Explained Simply)

const int LEDPin = 11;   // LED connected to PWM pin 11
const int LDRPin = A0;   // LDR connected to analog pin A0
int threshold = 500;     // Adjust based on your environment

void setup() {
  Serial.begin(9600);
  pinMode(LEDPin, OUTPUT);
}

void loop() {
  int lightLevel = analogRead(LDRPin);  // Read light level (0-1023)

  if (lightLevel <= threshold) {       // Dark condition
    digitalWrite(LEDPin, HIGH);
    Serial.print("Dark - LED ON: ");
  } else {                             // Bright condition
    digitalWrite(LEDPin, LOW);
    Serial.print("Light - LED OFF: ");
  }
  
  Serial.println(lightLevel);  // Display value for calibration
  delay(500);                  // Stabilize readings
}

Code Breakdown

1. Initialization

2. Setup Function

3. Main Loop

2025-09-29_21h41_36

Practical Uses

This simple project can be used in many ways

How to Improve It

To make the system work better

What You Learn

By doing this project, you practice

Conclusion

This LDR and LED project is a great way to start learning electronics and automation. With just a few parts, you can make a "smart" light that reacts to brightness. It shows how simple ideas can be used in real life to save energy and add convenience.

By understanding this system, you can build more advanced projects that make our homes and cities smarter.