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.

code: [select]
    if (variable = 1)whoops !

= assignment
== comparison


Arduino Forum > Using Arduino > Programming Questions > Troubleshooting Buzzer Delay


arduino

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

esp8266 (nodemcu 0.9) client.write très lent ???