Arduino Nightlight

Introduction: Arduino Nightlight

About: Makeistan is a makerspace at Information Technology University in Lahore, Pakistan.

Today you will be learning how to make a simple nightlight using Arduino, and this is a project for beginners. So, lets get started! The principle this will use is the LDR will measure the intensity of the light, so we have programmed the Arduino to turn on LED's if the intensity is less than a certain threshold, and if it is greater than a threshold the LED's will remain off.

Step 1: What You Will Need

You will need:

- an Arduino

- a Breadboard

- 5 Male-Male Jumper Wires

- 1-4 LED's

- a Light Dependent Resistor(LDR)

- and a 1k Ohm Resistor

Step 2: Making the Circuit

Here is a diagram of the circuit.

Step 3: The Code

Here is the code:

int led = 13;
int ldr = A0;

int value;

void setup() {

pinMode(led, OUTPUT);

pinMode(ldr, INPUT);

}

void loop() {

value = analogRead(ldr);

if (value > 300){

digitalWrite(led, HIGH);

}

else{

digitalWrite(led, LOW);

}

delay(100);

}

Be the First to Share

    Recommendations

    • Tinkercad to Fusion 360 Challenge

      Tinkercad to Fusion 360 Challenge
    • Digital Fabrication Student Design Challenge

      Digital Fabrication Student Design Challenge
    • Home and Garden Contest

      Home and Garden Contest

    2 Comments

    0
    IramWithencroft
    IramWithencroft

    3 months ago on Step 3

    Hi there!

    I tried this out and it worked, but the code had a small issue. Where LED is high I think it should have a less than symbol rather than greater than. Otherwise mine came on when the lights were on and went out when the lights were off. How would you go about using this for an addressable LED strip?