This project consists in be able with an arduino code and one LDR to change the sound of a buzzer depending on the light the LDR recieves
This had been an "easy" project because it didn't gave me many problems with the code and the circuit neither, I managed well with it
This is the Arduino code I have used
/*
* Speaker sketch with photoresistor
*/
const int outputPin = 6; // Speaker connected to digital pin 6
const int sensorPin = A0; // connect sensor to analog input 0
const int low = 200;
const int high = 800;
const int minDuration = 1; // 1 ms on, 1 ms off (500 Hz)
const int maxDuration = 10; // 10 ms on, 10 ms off (50 Hz)
void setup()
{
pinMode(outputPin, OUTPUT); // enable output on the led pin
}
void loop()
{
int sensorReading = analogRead(sensorPin); // read the analog input
int delayval = map(sensorReading, low, high, minDuration, maxDuration);
delayval = constrain(delayval, minDuration, maxDuration);
digitalWrite(outputPin, HIGH); // set the pin on
delay(delayval); // delay is dependent on light level
digitalWrite(outputPin, LOW); // set the pin off
delay(delayval);
}
This is the diagram of the circuit:
Here you can see a video I did showing my results