Laser Beam Break alarm with Arduino and Passive Buzzer

 


Arduino sketch for Alarm circuit

int button = 2;// connect a Normally open push button to pin 2 and GND of Arduino

int passive_buzzer = 11;// connect a Passive buzzer to pin 11 and GND of Arduino

void setup() {

  pinMode (passive_buzzer, OUTPUT);// declared buzzer as an out put

  pinMode (button, INPUT_PULLUP);// declared button as an input and internally Pulled Up(default value is +)

}

void loop()

{

  int buttonState = digitalRead(button);// variable buttonState will store the value of Pushbutton


  if (buttonState == HIGH)// if Button is not pressed ring the Alarm

  {

    for (int i = 0; i < 250; i++)

    {

      digitalWrite(passive_buzzer, HIGH);

      delay(1);

      digitalWrite(passive_buzzer, LOW);

      delay(1);

    }

    for (int i = 0; i < 125; i++)

    {

      digitalWrite(passive_buzzer, HIGH);

      delay(2);

      digitalWrite(passive_buzzer, LOW);

      delay(2);

    }

  }

}


Comments

Popular posts from this blog

4 Stage Timer With DS3231RTC Module.

Interfacing KY038 sound sensor with Raspberry pi Pico

Interfacing MQ2 Gas & Smoke Sensor With Raspberry Pi Pico