Hey I'm pretty new to arduino and am having trouble get the buzzer to stay completely silent whenever the light is blocked on the resistor, here's my code
const int photocellPin = A0; //photocell attach to
int sensorValue = 0; // value read from the sensor
const int buzzerPin = 9;
void setup()
{
pinMode(buzzerPin, OUTPUT); //initialize buzzer as an output
}
void loop()
{
sensorValue = analogRead(photocellPin); //read the value of A0
analogWrite(buzzerPin, 255); //
delay(sensorValue); //wait for a while,and the delay time depend on the sensorValue
analogWrite(buzzerPin, 0);
delay(sensorValue);