Close

Arduino Workshop-Light Sensor

mr-sarful-hassanMr. Sarful hassan wrote 06/15/2020 at 13:45 • 6 min read • Like
In this project, we will use an LDR to detect light and a piezo sounder to give audible feedback of the amount of the light detected, a light-dependent resistor, or LDR. As the name implies, the device is a resistor that depends on light. In a dark environment, the resistor will have very high resistance. As photons (light) land on the detector, the resistance will decrease. The more light there is, the lower the resistance will be. By reading the value from the sensor, we can detect if it is light, dark, or anywhere in-between Required Component : 1.Arduino 2. Piezo Sounder   3. Resistors 4. connecting wire 5. Breadboard
This book will help you to gain more knowledge about Arduino
Beginning Arduino Circuit diagram Arduino Light Sensor : First, make sure your Arduino is powered off by unplugging it from the USB cable. Then, connect up your parts so you have the circuit. Check all of your connections before reconnecting the power to the Arduino. The LDR can be inserted any way around; it does not have polarity. I found a 10kΩ resistor worked well with my LDR. You may need to try different resistor settings until you find one suitable for the LDR you have. A value between 1kΩ and 10kΩ should do the trick. Having a selection of different common resistor values in your component box will always come in handy. [caption id="attachment_448" align="alignnone" width="300"]Light Sensor Light Sensor[/caption] Code Arduino Light Sensor :
int piezoPin = 8; // Piezo on Pin 8
int ldrPin = 0; // LDR on Analog Pin 0
int ldrValue = 0; // Value read from the LDR
void setup() {
// nothing to do here
}
void loop() {
ldrValue = analogRead(ldrPin); // read the value from the
LDR
tone(piezoPin,1000); // play a 1000Hz tone from the piezo
delay(25); // wait a bit
noTone(piezoPin); // stop the tone
delay(ldrValue); // wait the amount of milliseconds in
ldrValue
}
When you upload this code to the Arduino, the Arduino will start to make short beeps. The gap between the beeps will be long if the LDR is in the shade and will be short when bright light is shone on it. This will give a Geiger counter-type effect, but with our detector detecting photon particles instead of ionizing radiation. You may find it more practical to solder a set of long wires to the LDR to allow you to keep your breadboard and Arduino on the table but move your LDR around to point it in dark and light areas. ALL ARDUINO TUTORIAL 
Like

Discussions