Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Smart Light Control with LDR and Relay

View and Edit Project In Cirkit DesignerImage of Arduino UNO Smart Light Control with LDR and Relay

Circuit Documentation

Summary

This circuit is designed to control a light bulb based on the ambient light intensity detected by a Light Dependent Resistor (LDR). The system uses an Arduino UNO microcontroller to read the light intensity from the LDR and control a relay, which in turn switches the light bulb on or off.

Component List

  1. Arduino UNO

    • Description: A microcontroller board based on the ATmega328P.
    • Pins: SDA, AREF, GND, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, A5, A4, A3, A2, A1, A0, Vin, 5V, 3.3V, RESET, IOREF, SCL
  2. BULB

    • Description: A standard light bulb.
    • Pins: +, -
  3. LDR

    • Description: A Light Dependent Resistor used to measure light intensity.
    • Pins: A0, D0, GND, VCC
  4. 1 Channel Relay 5V

    • Description: A relay module used to switch the light bulb on or off.
    • Pins: VCC, GND, IN, NC, COM, NO

Wiring Details

Arduino UNO

BULB

LDR

1 Channel Relay 5V

Code Documentation

#define LDR_PIN 2
#define Relay 9

const int LIGHT_THRESHOLD_HIGH = 800;    // High light intensity threshold
const int LIGHT_THRESHOLD_LOW = 500;     // Low light intensity threshold

void setup() {
  Serial.begin(115200);
  pinMode(LDR_PIN, INPUT); // DEFINE PIN AS INPUT SENSOR
  pinMode(Relay, OUTPUT);  // DEFINE PIN AS OUTPUT FOR RELAY
  Serial.println("LDR Sensor Test");
}

void loop() {
  int lightIntensity = analogRead(LDR_PIN); // Read sensor
  // Light intensity-based control
  if (lightIntensity >= LIGHT_THRESHOLD_HIGH) {
    digitalWrite(Relay, LOW); // Turn light OFF
    Serial.println("LIGHT IS OFF");
  } else if (lightIntensity <= LIGHT_THRESHOLD_LOW) {
    digitalWrite(Relay, HIGH); // Turn light ON
    Serial.println("LIGHT IS ON");
  } else {
    digitalWrite(Relay, LOW); // Turn light OFF
    Serial.println("LIGHT IS OFF");
  }

  // Debugging output
  Serial.print("Light Intensity: ");
  Serial.println(lightIntensity);

  delay(500); // Wait for 500 ms
}

This code reads the light intensity from the LDR and controls the relay to turn the light bulb on or off based on the predefined light intensity thresholds. The setup function initializes the serial communication and sets the pin modes. The loop function continuously reads the light intensity and controls the relay accordingly, providing debugging output via the serial monitor.