/* * Buzzer Sargam - Hindustani Classical Music on Barduino * Fab Academy 2026 - Week 4: Embedded Programming * Shivangi Pande | Fab Lab Barcelona * * Maps the 7 swaras of Hindustani classical music * to frequencies and plays them through the Barduino buzzer (pin 46). * * Swara → Frequency (Hz) — based on C4 scale approximation: * Sa = 261 (C4) * Re = 293 (D4) * Ga = 329 (E4) * Ma = 349 (F4) * Pa = 392 (G4) * Dha = 440 (A4) * Ni = 493 (B4) * Sa' = 523 (C5 — upper Sa) */ // ---- Pin definitions ---- #define BUZZER_PIN 46 // ---- Swara frequencies (Hz) ---- #define SA 261 #define RE 293 #define GA 329 #define MA 349 #define PA 392 #define DHA 440 #define NI 493 #define SA_H 523 // Upper Sa // ---- Timing ---- #define BEAT 400 // Duration of one beat (ms) #define PAUSE 50 // Silence between notes (ms) void playNote(int frequency, int duration) { tone(BUZZER_PIN, frequency, duration); delay(duration + PAUSE); } void setup() { pinMode(BUZZER_PIN, OUTPUT); Serial.begin(115200); Serial.println("Buzzer Sargam — Sa Re Ga Ma Pa Dha Ni Sa"); } void loop() { // --- Ascending scale: Aaroha --- Serial.println("Aaroha (ascending):"); playNote(SA, BEAT); playNote(RE, BEAT); playNote(GA, BEAT); playNote(MA, BEAT); playNote(PA, BEAT); playNote(DHA, BEAT); playNote(NI, BEAT); playNote(SA_H, BEAT * 2); // Hold upper Sa delay(500); // --- Descending scale: Avroha --- Serial.println("Avroha (descending):"); playNote(SA_H, BEAT); playNote(NI, BEAT); playNote(DHA, BEAT); playNote(PA, BEAT); playNote(MA, BEAT); playNote(GA, BEAT); playNote(RE, BEAT); playNote(SA, BEAT * 2); // Hold lower Sa delay(1000); // --- Simple melody: "Twinkle Twinkle" in swaras --- // Sa Sa Pa Pa Dha Dha Pa — Serial.println("Melody:"); playNote(SA, BEAT); playNote(SA, BEAT); playNote(PA, BEAT); playNote(PA, BEAT); playNote(DHA, BEAT); playNote(DHA, BEAT); playNote(PA, BEAT * 2); // Ma Ma Ga Ga Re Re Sa — playNote(MA, BEAT); playNote(MA, BEAT); playNote(GA, BEAT); playNote(GA, BEAT); playNote(RE, BEAT); playNote(RE, BEAT); playNote(SA, BEAT * 2); delay(2000); // Pause before repeating }