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

Arduino UNO R4 WiFi Controlled Light Sensor with Dual LED Indicator

View and Edit Project In Cirkit DesignerImage of Arduino UNO R4 WiFi Controlled Light Sensor with Dual LED Indicator

Circuit Documentation

Summary

This circuit is designed to control two LEDs (one red and one blue) based on the light intensity detected by a photocell (Light Dependent Resistor, LDR). The Arduino UNO R4 WiFi microcontroller reads the analog value from the LDR and determines whether the environment is dark or light. If the LDR is covered (indicating darkness), the blue LED blinks. If the LDR is uncovered (indicating light), the red LED blinks. The circuit includes resistors for current limiting and voltage division purposes.

Component List

Arduino UNO R4 WiFi

Photocell (LDR)

Resistors

LED: Two Pin (red)

LED: Two Pin (blue)

Wiring Details

Arduino UNO R4 WiFi

Photocell (LDR)

Resistors

LED: Two Pin (red)

LED: Two Pin (blue)

Documented Code

/*
 * This Arduino sketch controls two LEDs based on the input from a photocell (LDR).
 * When the photocell is uncovered, the red LED blinks. When the photocell is
 * covered, the blue LED blinks.
 */

const int redLEDPin = 2; // Pin connected to the anode of the red LED
const int blueLEDPin = 4; // Pin connected to the anode of the blue LED
const int ldrPin = A0; // Pin connected to the LDR
const int threshold = 500; // Threshold value to determine covered/uncovered state

void setup() {
  pinMode(redLEDPin, OUTPUT); // Set red LED pin as output
  pinMode(blueLEDPin, OUTPUT); // Set blue LED pin as output
  pinMode(ldrPin, INPUT); // Set LDR pin as input
}

void loop() {
  int ldrValue = analogRead(ldrPin); // Read the value from the LDR
  if (ldrValue < threshold) {
    // If LDR is covered, blink the blue LED
    digitalWrite(blueLEDPin, HIGH);
    delay(500);
    digitalWrite(blueLEDPin, LOW);
    delay(500);
  } else {
    // If LDR is uncovered, blink the red LED
    digitalWrite(redLEDPin, HIGH);
    delay(500);
    digitalWrite(redLEDPin, LOW);
    delay(500);
  }
}

The code is written for the Arduino platform and is saved with the .ino file extension. It initializes the pins connected to the LEDs and the LDR, then continuously reads the LDR value in the loop function. Depending on the light intensity, it blinks the appropriate LED.