Arduino UNO (Beginner) Push Button and Buzzer Project

Instructions

One of the easiest and most useful beginner projects is connecting a push button and a buzzer. .

When the button is pressed, the buzzer will produce a sound. When the button is released, the sound stops.

componentconnection
Push buttonOne side to GND
Push buttonOther side to pin 2
Buzzer (+)Pin 8
Buzzer (-)GND
const int buttonPin = 2;
const int buzzerPin = 8;

void setup() {
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(buzzerPin, OUTPUT);
}

void loop() {
  int buttonState = digitalRead(buttonPin);

  // Button pressed
  if (buttonState == LOW) {
    tone(buzzerPin, 1000);
  } else {
    noTone(buzzerPin);
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *