Serial.println("The button is being pressed") ĭigitalWrite(BUZZER_PIN, HIGH) // turn on Int buttonState = digitalRead(BUTTON_PIN) // read new state PinMode(BUZZER_PIN, OUTPUT) // set arduino pin to output mode PinMode(BUTTON_PIN, INPUT_PULLUP) // set arduino pin to input pull-up mode Arduino Code – Simple Sound const int BUTTON_PIN = 7 // Arduino pin connected to button's pinĬonst int BUZZER_PIN = 3 // Arduino pin connected to Buzzer's pin Now copy the following code and upload it to Arduino IDE Software. Here is a simple step-by-step guide on “ How to Add Libraries in Arduino IDE“. Installing Librariesīefore you start uploading a code, download and unzip the following libraries at /Progam Files(x86)/Arduino/Libraries (default), in order to use the sensor with the Arduino board. Here is a simple step-by-step guide on “ How to install Arduino IDE“. Make connections according to the circuit diagram given below.įirst, you need to install Arduino IDE Software from its official website Arduino. If you want to stop the sound when the button is released you can use noTone(8) it is after the previous if statement.You can replace the frequency 1000 with the desired frequency in hertz, for example, 2000 for 2Khz. If the button is pressed, use the tone() function to generate a tone on the buzzer pin: In the loop() function, use the digitalRead() function to check the state of the pushbutton.In the setup() function, configure the pushbutton pin as input by adding the following line:.In your Arduino sketch, configure the buzzer pin as an output by adding the following line in the setup() function:.Connect one pin to digital pin 2 and the other pin to one of the GND pins on the board. Connect the pushbutton to the Arduino board.Connect the positive terminal to digital pin 8 and the negative terminal to one of the GND pins on the board. The buzzer typically has two pins: one for the positive terminal (usually labeled “+” or “S”) and one for the negative terminal (usually labeled “-” or “N”). Connect the 5V piezoelectric buzzer to the Arduino Uno board.You can modify the code to add additional functionality or integrate it into your own projects. The provided Arduino code reads the temperature data from the DHT11 sensor and activates the Piezo Buzzer when the temperature drops below 26 degrees Celsius. In this guide, you have learned how to control an automated system using an Arduino UNO board, a DHT11 temperature and humidity sensor, and a Piezo Buzzer. Serial.println(F("Failed to read from DHT sensor!")) After 10 seconds, it sets the Buzzer pin to LOW, turning off the buzzer.įloat temperature = dht.readTemperature() The `activateBuzzer()` function sets the Buzzer pin to HIGH, causing the buzzer to buzz, and then waits for 10 seconds using the `delay()` function. If the temperature is below 26 degrees Celsius, the `activateBuzzer()` function is called. In the `loop()` function, the code reads the temperature data from the DHT11 sensor using the `readTemperature()` function. It then initializes the DHT11 sensor and sets the pinMode for the Buzzer pin. The code starts by including the necessary libraries and defining the pin numbers for the DHT11 sensor and the Piezo Buzzer. To set up the circuit, follow the diagram below: The code reads the temperature data from the DHT11 sensor and activates the Piezo Buzzer to buzz for 10 seconds when the temperature drops below 26 degrees Celsius.īefore proceeding, make sure you have the following components: This guide provides Arduino code for controlling an automated system using an Arduino UNO board, a DHT11 temperature and humidity sensor, and a Piezo Buzzer.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |