Try It: Buzzer Alert Pattern Designer
Try Keep the pattern selector on Double Beep and change Beep Duration (ms) from 100 to 200.
Observe At the opening settings, two bars represent a 400 ms pattern with a 50% On/Off Ratio.
Explain For Double Beep, total duration counts 2 beep-and-pause pairs; the ratio divides beep time by beep plus pause time.
Calculate alert timing
Reset
Technical boundaries. The calculation assumes identical pauses after every beep, including the last. SOS triples the middle three beep lengths; the page draws timing bars and generates Arduino code without playing audio.
viewof alert_type = Inputs. select (["Single Beep" , "Double Beep" , "Triple Beep" , "SOS Pattern" , "Alarm (Alternating)" , "Custom" ], {value : "Double Beep" , label : "Alert Pattern" })
viewof beep_freq = Inputs. range ([200 , 4000 ], {value : 1000 , step : 100 , label : "Frequency (Hz)" })
viewof beep_on_ms = Inputs. range ([50 , 500 ], {value : 100 , step : 25 , label : "Beep Duration (ms)" })
viewof beep_off_ms = Inputs. range ([50 , 500 ], {value : 100 , step : 25 , label : "Pause Duration (ms)" })
alert_patterns = ({
"Single Beep" : {beeps : 1 , desc : "Quick acknowledgment" },
"Double Beep" : {beeps : 2 , desc : "Confirmation / success" },
"Triple Beep" : {beeps : 3 , desc : "Warning / attention needed" },
"SOS Pattern" : {beeps : 9 , desc : "Emergency (3 short, 3 long, 3 short)" },
"Alarm (Alternating)" : {beeps : 6 , desc : "Urgent alert with frequency variation" },
"Custom" : {beeps : 1 , desc : "Your own pattern" }
})
alert_info = alert_patterns[alert_type]
alert_total_ms = alert_type === "SOS Pattern"
? (3 * (beep_on_ms + beep_off_ms)) + (3 * (beep_on_ms * 3 + beep_off_ms)) + (3 * (beep_on_ms + beep_off_ms))
: alert_info. beeps * (beep_on_ms + beep_off_ms)
alert_duty = (beep_on_ms / (beep_on_ms + beep_off_ms) * 100 ). toFixed (0 )
alert_audibility = beep_freq >= 1000 && beep_freq <= 3000 ? "Excellent" : beep_freq >= 500 && beep_freq <= 4000 ? "Good" : "Poor"
alert_audibility_color = alert_audibility === "Excellent" ? "#16A085" : alert_audibility === "Good" ? "#E67E22" : "#E74C3C"
html `<div style="background: var(--bs-light, #f8f9fa); padding: 1rem; border-radius: 8px; border-left: 4px solid #3498DB; margin-top: 0.5rem;">
<div style="display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.75rem;">
${ Array . from ({length : Math . min (alert_info. beeps , 9 )}, (_, i) => {
let w = alert_type === "SOS Pattern" && i >= 3 && i < 6 ? beep_on_ms * 3 : beep_on_ms
let maxW = 80
let barW = Math . min (Math . max (w / 5 , 10 ), maxW)
return `<div style="display: inline-flex; align-items: flex-end; gap: 2px;">
<div style="width: ${ barW} px; height: 30px; background: #3498DB; border-radius: 3px;" title=" ${ w} ms on"></div>
<div style="width: ${ Math . min (beep_off_ms / 10 , 20 )} px; height: 10px; background: #ddd; border-radius: 2px;" title=" ${ beep_off_ms} ms off"></div>
</div>`
}). join ("" )}
</div>
<p style="margin: 0.3rem 0;"><strong>Pattern:</strong> ${ alert_type} -- ${ alert_info. desc } </p>
<p style="margin: 0.3rem 0;"><strong>Frequency:</strong> ${ beep_freq} Hz | <strong>Audibility:</strong> <span style="color: ${ alert_audibility_color} ; font-weight: bold;"> ${ alert_audibility} </span> (1-3 kHz is optimal for human hearing)</p>
<p style="margin: 0.3rem 0;"><strong>Total Duration:</strong> ${ alert_total_ms} ms | <strong>On/Off Ratio:</strong> ${ alert_duty} %</p>
<details style="margin-top: 0.5rem;">
<summary style="cursor: pointer; color: #3498DB; font-weight: bold;">Show Arduino Code</summary>
<pre style="background: #2C3E50; color: #ecf0f1; padding: 0.75rem; border-radius: 4px; margin-top: 0.5rem; font-size: 0.85em;"> ${ alert_type === "SOS Pattern"
? `// SOS Pattern
void playSOS() {
// 3 short beeps
for (int i = 0; i < 3; i++) {
tone(BUZZER_PIN, ${ beep_freq} , ${ beep_on_ms} );
delay( ${ beep_on_ms + beep_off_ms} );
}
// 3 long beeps
for (int i = 0; i < 3; i++) {
tone(BUZZER_PIN, ${ beep_freq} , ${ beep_on_ms * 3 } );
delay( ${ beep_on_ms * 3 + beep_off_ms} );
}
// 3 short beeps
for (int i = 0; i < 3; i++) {
tone(BUZZER_PIN, ${ beep_freq} , ${ beep_on_ms} );
delay( ${ beep_on_ms + beep_off_ms} );
}
noTone(BUZZER_PIN);
}`
: alert_type === "Alarm (Alternating)"
? `// Alternating Alarm
void playAlarm() {
for (int i = 0; i < 3; i++) {
tone(BUZZER_PIN, ${ beep_freq} , ${ beep_on_ms} );
delay( ${ beep_on_ms + beep_off_ms} );
tone(BUZZER_PIN, ${ Math . round (beep_freq / 2 )} , ${ beep_on_ms} );
delay( ${ beep_on_ms + beep_off_ms} );
}
noTone(BUZZER_PIN);
}`
: `// ${ alert_type}
void playAlert() {
for (int i = 0; i < ${ alert_info. beeps } ; i++) {
tone(BUZZER_PIN, ${ beep_freq} , ${ beep_on_ms} );
delay( ${ beep_on_ms + beep_off_ms} );
}
noTone(BUZZER_PIN);
}` } </pre>
</details>
</div>`
Back to the chapter