Control Bulb Using Arduino And LDR in Proteus

Опубликовано: 21 Май 2026
на канале: Simulate IoT Academy
39
6

Turn On Bulb Based On Darkness Level Measured or Detected By Light Dependent Resistor
You Can Do it Yourself

Use this Code Below But Remember That you Can Change Pins
// Pin Definitions
const int ldrAnalogPin = A1; // Connected to A0 of LDR Module
const int ldrDigitalPin = 2; // Connected to D0 of LDR Module
const int ledPin = 13; // The LED

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(ldrDigitalPin, INPUT); // D0 provides a signal to the Arduino

Serial.begin(9600);
Serial.println("LDR Dual-Mode System Starting...");
}

void loop() {
// 1. Read Analog Value (0 to 1023)
int lightIntensity = analogRead(ldrAnalogPin);

// 2. Read Digital Value (0 or 1)
int isDark = digitalRead(ldrDigitalPin);

// Print data for debugging
Serial.print("Intensity: ");
Serial.print(lightIntensity);
Serial.print(" | Digital Status: ");
Serial.println(isDark);

// Logic: Use the Digital pin to toggle the LED
// NOTE: On most 4-pin modules, D0 goes LOW when light is detected
// and HIGH when it is DARK.
if (isDark == HIGH) {
digitalWrite(ledPin, HIGH); // Turn LED ON in the dark
} else {
digitalWrite(ledPin, LOW); // Turn LED OFF in the light
}

delay(200);
}