• 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

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.

Table of Contents
  • Hardware Required
  • For Amplified Output

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.  Converting Analogue to Digital (Analogue Read Serial) – Arduino Basics
  • 2.  Crystal Radio Sets with Amplifier Circuit
  • 3.  How to Make LED Air Pollution Meter Circuit with Arduino
  • 4.  Single Transistor Radio Receiver Circuit
  • 5.  Guitar Amplifier Circuit with Fuzz Effect Genertaor
  • 6.  60 Watt Amplifier Circuit

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 Circuits

Categories

  • Arduino Projects (87)
  • Audio and Amplifier Projects (132)
  • Automation Projects (17)
  • Automobile Electronics (101)
  • Battery Charger Circuits (83)
  • Datasheets and Components (104)
  • 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)




  • Privacy Policy
  • Cookie Policy
  • Disclaimer
  • Copyright
  • Videos
  • Sitemap




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 |

Social Profiles

  • Twitter
  • YouTube
  • Instagram
  • Pinterest
  • My Facebook-Page
  • Quora
  • Stack Exchange
  • Linkedin



  • © 2025 · Swagatam Innovations