Example Code for Arduino-Alarm
Last revision 2026/01/08
The article offers a complete guide to creating an Arduino alarm system, covering hardware and software preparation, wiring diagrams, and detailed sample code to generate custom alarm frequencies using sinusoidal calculations.
Wiring Diagram

Sample Code
/*
Alarm
*/
float sinVal;
int toneVal;
void setup(){
pinMode(8, OUTPUT);
}
void loop(){
for(int x=0; x<180; x++){
// convert degrees to radians then obtain value
sinVal = (sin(x*(3.1412/180)));
// generate a frequency from the sin value
toneVal = 2000+(int(sinVal*1000));
tone(8, toneVal);
delay(2);
}
}
Was this article helpful?
