• Skip to main content
  • Skip to primary sidebar

Homemade Circuit Projects

Need circuit help? Post them in the comments! I've answered over 50,000!

Blog | Categories | About | Contact | Calculators-online
You are here: Home / Arduino Projects / Arduino Musical Tune Generator Circuit

Arduino Musical Tune Generator Circuit

Last Updated on December 5, 2024 by Swagatam 2 Comments

You can use this little Arduino musical tune generator circuit for a preferred application, such as for making an interesting door bell, as a car reverse horn, or music box for gifting somebody, or simply for personal amusement.

Hardware Required

The Hardware required for the project are given as follows:

  • Arduino or Genuino board
  • piezo buzzer or a speaker
  • hook-up wires

The Arduino is powered with a 9V, 500mA power supply input which could be from any standard SMPS AC to DC adapter, or you can also try your cell phone charger for the same.

Pin#8 from the Arduino can be directly configured with the speaker which must not be rated above 8 ohm, and 1 watt.

So one wire of the speaker connects with pin#8 of the Arduino board and the other wire goes to the negative line or the ground line of the board.

Tone Schematic 2

For Amplified Output

For louder or hugely amplified sound you can configure the pin#8 with a transistor driver stage, consisting of a TIP31 transistor, whose base may be connected with pin8 via a 1K resistor, emitter to ground and the collector to one of the wires of the speaker, the other wire of the speaker now connects with the positive supply that is the 9V supply (+).

Here make sure the speaker is rated at 8 ohms but at much higher wattage, may be at around 5 watts for an amplified music tune generation.

This sketch is coded to play and generate quite many random
melodies in sequence using a pentatonic scale
/*
Musician
Plays a (fairly) random tune until the program is stopped.
8-ohm speaker on digital pin 8.
//Copyright (c) 2012 Jeremy Fonte
//This code is released under the MIT license
//https://opensource.org/licenses/MIT
*/
int randomNote = 131;
int randomDuration = 2;
int noteStep = 1;
int notes[15];
void setup() {
pinMode(8, OUTPUT);
notes[1] = 131;
notes[2] = 147;
notes[3] = 165;
notes[4] = 196;
notes[5] = 220;
notes[6] = 262;
notes[7] = 294;
notes[8] = 330;
notes[9] = 392;
notes[10] = 440;
notes[11] = 523;
notes[12] = 587;
notes[13] = 659;
notes[14] = 784;
notes[15] = 880;
randomNote = random(1, 15);
}
void loop() {
noteStep = random(-3, 3);
randomNote = randomNote + noteStep;
if(randomNote < 1) {
randomNote = random(1, 15);
}
else if(randomNote > 15) {
randomNote = random(1, 15);
}
randomDuration = random(1, 8);
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000/randomDuration;
tone(8, notes[randomNote],noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(8);
}

The connection diagram for the proposed Arduino musical tune generator circuit is shown below:

Arduino Musical Tune Generator Circuit

For high power amplified listening, the same set up can be upgraded with a power transistor as indicated in the following figure:

arduino2Bmusic

You'll also like:

  • 1.  Fading an LED ON/OFF – Arduino Basics
  • 2.  Real Machine Gun Sound Effect Generator Circuit
  • 3.  Making an Automatic Stopwatch for Runners, Athletes and Sportpersons
  • 4.  High Current Motor Control Circuit using Arduino
  • 5.  Tuned Radio Frequency (TRF) Receiver Circuits
  • 6.  Buck Converter Circuit Using Arduino

About Swagatam

I am an electronics engineer with over 15 years of hands-on experience. I am passionate about inventing, designing electronic circuits and PCBs, and helping hobbyists bring their projects to life. That is why I founded homemade-circuits.com, a website where I share innovative circuit ideas and tutorials. Have a circuit related question? Leave a comment.... I guarantee a reply!

Previous Post: « 5 Simple Power Bank Circuits for Mobile Phones
Next Post: Arduino RGB Flowing Sequential Light Circuit »

Reader Interactions

Comments

  1. Unknown says

    April 17, 2016 at 12:04 am

    Hi! Does this example fits for 4ohms 3W speaker?

    Reply
    • Swagatam says

      April 17, 2016 at 2:28 pm

      yes you can try it, no issues.

      Reply

Need Help? Please Leave a Comment! We value your input—Kindly keep it relevant to the above topic! Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Subscribe to New Circuit Ideas

Categories

  • Arduino Projects (87)
  • Audio and Amplifier Projects (132)
  • Automation Projects (17)
  • Automobile Electronics (101)
  • Battery Charger Circuits (82)
  • Datasheets and Components (103)
  • Electronics Theory (143)
  • Free Energy (37)
  • Games and Sports Projects (11)
  • Grid and 3-Phase (19)
  • Health related Projects (25)
  • Home Electrical Circuits (12)
  • Indicator Circuits (14)
  • Inverter Circuits (87)
  • Lamps and Lights (142)
  • Meters and Testers (69)
  • Mini Projects (46)
  • Motor Controller (64)
  • Oscillator Circuits (27)
  • Pets and Pests (15)
  • Power Supply Circuits (108)
  • Remote Control Circuits (50)
  • Security and Alarm (64)
  • Sensors and Detectors (101)
  • Solar Controller Circuits (59)
  • Temperature Controllers (42)
  • Timer and Delay Relay (49)
  • Transmitter Circuits (29)
  • Voltage Control and Protection (37)
  • Water Controller (36)

Calculators

  • Battery Back up Time Calculator
  • Capacitance Reactance Calculator
  • IC 555 Astable Calculator
  • IC 555 Monostable Calculator
  • Inductance Calculator
  • LC Resonance Calculator
  • LM317, LM338, LM396 Calculator
  • Ohm’s Law Calculator
  • Phase Angle Phase Shift Calculator
  • Power Factor (PF) Calculator
  • Reactance Calculator
  • Transistor Astable Calculator
  • Transistor base Resistor Calculator
  • Voltage Divider Calculator
  • Wire Current Calculator
  • Zener Diode Calculator
  • Filter Capacitor Calculator
  • Buck Converter Calculator
  • Boost Converter Calculator
  • Solar Panel, Inverter, Battery Calculator
  • Wire Current Calculator
  • SMPS Transformer Calculator
  • IC SG3525, SG3524 Calculator
  • Inverter LC Filter Calculator

People Also Search

555 Circuits | 741 Circuits | LM324 Circuits | LM338 Circuits | 4017 Circuits | Ultrasonic Projects | SMPS Projects | Christmas Projects | MOSFETs | Radio Circuits | Laser Circuits | PIR Projects |

Recent Comments

  • Swagatam on Best Electronic Circuit Projects
  • TOMMY on Best Electronic Circuit Projects
  • Swagatam on Inverter Circuit with Feedback Control
  • Jerry Adeosun on Inverter Circuit with Feedback Control
  • Swagatam on Contact

Company

  • Privacy Policy
  • Cookie Policy
  • About Me
  • Contact
  • Disclaimer
  • Copyright
  • Videos
  • Sitemap

Social Profiles

  • Twitter
  • YouTube
  • Instagram
  • Pinterest
  • My Facebook-Page
  • Quora
  • Stack Exchange
  • Linkedin
  • © 2025 · Swagatam Innovations