Introduction: Arduino Nightlight
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);
}
2 Comments
1 year 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?
5 years ago
Great Introductory Arduino tutorial.