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

Proteus simulation 4x4 Matrix Keypad with Arduino and LCD screen

Digital Clock with Arduino and RTC Module and P10 LEDmatrix

Interfacing KY038 sound sensor with Raspberry pi Pico