his book will help you to gain more knowledge about Arduino
Beginning Arduino
Circuit diagram Arduino Piezo Sounder Alarm :
First, make sure your Arduino is powered off by unplugging it from the USB cable Then Connect up your Arduino Piezo Sounder Alarm and connect your Arduino back to the
USB cable and power it up
[caption id="attachment_439" align="alignnone" width="300"] Piezo Sounder Alarm[/caption]
Code :
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.