Design a night lamp using a ldr and a led using arduino uno and find out the time delays associated in keeping on the lamp

design a night lamp using a ldr and a led using arduino uno and find out the time delays associated in keeping on the lamp.

design a night lamp using a ldr and a led using arduino uno and find out the time delays associated in keeping on the lamp.

Answer: Designing a night lamp using an LDR (Light Dependent Resistor) and an LED with an Arduino Uno is a straightforward project. The LDR senses ambient light levels, and when it gets dark, the LED will turn on automatically. You can also add a time delay to control how long the LED stays on after it gets dark. Here’s a step-by-step guide to creating this project:

Components Needed:

  1. Arduino Uno
  2. LDR (Light Dependent Resistor)
  3. LED (any color)
  4. 220-330-ohm resistor
  5. Breadboard and jumper wires
  6. USB cable for Arduino
  7. Power source for Arduino (battery or USB connection to a computer)

Circuit Connections:

  1. Connect one leg of the LDR to the 5V pin on the Arduino.
  2. Connect the other leg of the LDR to one end of a resistor (220-330 ohms).
  3. Connect the other end of the resistor to one leg of the LED (longer lead, the positive side).
  4. Connect the other leg of the LED (shorter lead, the negative side) to the GND pin on the Arduino.
  5. Connect the junction between the LDR and the resistor to analog pin A0 on the Arduino.

Arduino Code:

const int LDRPin = A0;   // LDR connected to analog pin A0
const int LEDPin = 13;   // Built-in LED on pin 13

int threshold = 500;     // Adjust this value to set the light threshold
int delayTime = 5000;    // Delay time in milliseconds (5 seconds)

void setup() {
  pinMode(LEDPin, OUTPUT);
}

void loop() {
  int lightLevel = analogRead(LDRPin);

  if (lightLevel < threshold) {
    digitalWrite(LEDPin, HIGH);  // Turn on the LED
    delay(delayTime);             // Keep the LED on for the specified delay
    digitalWrite(LEDPin, LOW);   // Turn off the LED
  }
}

Explanation:

  • The LDR is connected to analog pin A0 to read the light level.
  • The code checks the light level using analogRead() and compares it to the threshold. If the light level falls below the threshold, it turns on the LED.
  • The LED remains on for the specified delayTime (in this example, 5 seconds) and then turns off.

Adjustments:

  • You can change the threshold value to set the level of darkness at which the LED turns on.
  • Modify the delayTime to control how long the LED stays on after it gets dark.
  • Experiment with these values to suit your preferences.

Upload the code to your Arduino Uno, and you should have a night lamp that turns on when it gets dark and stays on for the specified time delay.