0% found this document useful (0 votes)
3 views

7.ino

The document contains an Arduino sketch that sets up a pushbutton, LED, and buzzer. When the pushbutton is pressed, the LED toggles its state and the buzzer emits a sound. The setup function initializes the pins, while the loop function continuously checks the button state and performs actions accordingly.

Uploaded by

amitbaghel821848
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

7.ino

The document contains an Arduino sketch that sets up a pushbutton, LED, and buzzer. When the pushbutton is pressed, the LED toggles its state and the buzzer emits a sound. The setup function initializes the pins, while the loop function continuously checks the button state and performs actions accordingly.

Uploaded by

amitbaghel821848
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

// constants won't change.

They're used here to set pin numbers:


const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
const int buzzerPin = 9; // the number of the Buzzer pin
bool ledStatus = true;

// variables will change:


int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);

// initialize the Buzzer pin as an output:


pinMode(buzzerPin, OUTPUT);

// initialize the pushbutton pin as an input:


pinMode(buttonPin, INPUT);
}

void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed. If it is, the buttonState is HIGH:


if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin,ledStatus);

digitalWrite(buzzerPin, HIGH);
delay(100);
digitalWrite(buzzerPin, LOW);

ledStatus=!ledStatus; // Toggle current LED status


}
}

You might also like