his book will help you to gain more knowledge about Arduino
Beginning Arduino
![Piezo Sounder Alarm](https://www.mechatronicslab.net/my_uploads/2020/06/Piezo-Sounder-Alarm-300x215.jpg)
float sinVal;
int toneVal;
void setup() {
pinMode(8, OUTPUT);
}
void loop() {
for (int x=0; x<180; x++) {
// convert degrees to radians then obtain sin value
sinVal = (sin(x*(3.1412/180)));
// generate a frequency from the sin value
toneVal = 2000+(int(sinVal*1000));
tone(8, toneVal);
delay(2);
}
}
Once you have uploaded the code, there will be a slight delay, and then your piezo will start to emit sounds. If everything is working as planned, you will hear a rising and falling siren-type alarm, similar to a car alarm.
ALL ARDUINO TUTORIAL
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.