Introduction: Light Sensor Buzzer
In this experiment we are going to work with a sensor which is a resistor that depends on light. In a dark environment, the resistor will have a very high resistance. As photons light lands on the detector, the resistance will decrease. The more light is we will have a lower resistance. By reading different values from the sensor, we can detect if is it light , dark or a value between them. Another element that we are going to use on this experiment is Buzzer.
Step 1: Circuit Setup and Beadboard
The schematic consists on 3 elements which are: Photoresistor (LDR), Piezo Buzzer, 1 – 10 kΩ. The LDR can be connected any way you want because it doesn’t have polarity. For resistance you can use from 1-10 KΩ because different LDR's have different settings. Try different values of resistor to fit the best settings with your LDR.
Step 2: Code
int piezoPin = 8; // Declaring Piezo Buzzer on Pin 8
int ldrPin = 0; // Declaring LDR on Analog Pin 0
int ldrValue = 0; // Reading different values from the LDR
void setup
()
{ }
void loop()
{ // Starting the cycle functions below
ldrValue = analogRead(ldrPin); // read the value from the LDR
tone(piezoPin,1000); // Play a 1000Hz tone from the piezo (beep)
delay(25); // wait a bit, change the delay for fast response.
noTone(piezoPin); // stop the tone after 25 ms in this case
delay(ldrValue); // wait the amount of milliseconds in ldrValue} //
End of cycle functions
Step 3: Materials
1. Breadboard
2. Arduino Board
3. Male Wires
4. Resistors
5. Piezo Buzzer
6. Light Sensor