Troubleshooting Buzzer Delay
code: [select]
int variable = 0;
void setup() {
// put setup code here, run once:
pinmode(a1, input); //photocell
pinmode(12, output); //led voltage
pinmode(6, output); //buzzer (pwm
float val;
}
void loop() {
// put main code here, run repeatedly:
float val = analogread(a1);
if (val < 300) { // if gets dark out
digitalwrite(12, 1); // led turns on
digitalwrite(6, 0); // buzzer remains off
variable = 1;
delay(1000);
}
else { // if bright outside
digitalwrite(12, 0); // led turns off
if (variable = 1) {
analogwrite(6, 10); // buzzer pwm turns on
delay(1000); // wait second
digitalwrite(6, 0); // buzzer pin turns off
variable = 0;
}
}
}
hey guys,
i trying use input photocell voltage control output of led , buzzer. led sub circuit works well, buzzer not working properly. want have buzz 1 second, once turns on not turn off until val < 300 again. how can fix problem? thank in advance.
Arduino Forum > Using Arduino > Programming Questions > Troubleshooting Buzzer Delay
arduino
Comments
Post a Comment