Why we are going towards apparently easy tutorials on Arduino than couple of years back? These basic projects with components are helpful to learn using sensor based logic. Was not LCD with LDR was difficult project? Why Automatic LED Control Using LDR and Arduino looks simillar? Our older guides were mostly just using modules with libraries and this guide has more at the end for creating complex projects. For future complex projects, we need the users to get used with handling the basic electronic components and manipulating code with understanding. Here is How to Turn On LED in Dark With LDR and Arduino. Very easy circuit diagram with minimum components. Here is small video on how the thing will look like :
Circuit and Code to Turn On LED in Dark With LDR and Arduino
We need the following components :
Arduino Uno or similar board
One 10 K Ohm resistor
You need to build the circuit like this :
Now, first run this code :
int LDR_Pin = A0;
int LDRReading = analogRead(LDR_Pin);
Open Arduino serial monitor and get values of reading at room, at dark and sunlight etc. Now, this is our final code for the thing we need :
I set the
(sensorReading<1000) based on my available light's reading on Arduino serial monitor. The mechanism how the values are being printed is described in Arduino Analog vs digital pin.
So, for your need,
(sensorReading<1000) may be lower or higher than 1000. Secondly, you can add multiple LEDs by simple modification.
In real life, we need this action for electric lights. That will need using an Arduino relay module.
So, with one Arduino, one LDR, one resistor, one relay module, we can actually control many household bulbs in real life. Commercial unit for the same action would cost higher if you build the Arduino from components or use cheap China clone. Furthermore, you can adjust the value for different seasons.
Follow the Author of this article :