• Skip to main content
  • Skip to primary sidebar

Homemade Circuit Projects

Get free circuit help 24/7

New Projects | Privacy Policy | About us | Contact | Disclaimer | Copyright | Videos | Circuits for Beginners | Basic Circuits | Hobby Projects | Transistor Circuits | LED Drivers 

You are here: Home / Arduino Engineering Projects / Arduino Musical Tune Generator Circuit

Arduino Musical Tune Generator Circuit

Last Updated on June 24, 2019 by Swagatam

caution electricity can be dangerous

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.

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 spaker 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:

You'll also like:

  • 1.  PIC Tutorial- From Registers to Interrupts
  • 2.  Making a Stethoscope Amplifier Circuit
  • 3.  10 Useful Active Filter Circuits Explored
  • 4.  Password Security Lock Circuit Using 4×4 Keypad and Arduino
  • 5.  Introduction to EEPROM in Arduino
  • 6.  Playing a Melody Using the Tone() function in Arduino

About Swagatam

I am an electronic engineer (dipIETE ), hobbyist, inventor, schematic/PCB designer, manufacturer. I am also the founder of the website: https://www.homemade-circuits.com/, where I love sharing my innovative circuit ideas and tutorials.
If you have any circuit related query, you may interact through comments, I'll be most happy to help!

Have Questions? Please Comment below to Solve your Queries! Comments must be Related to the above Topic!!

2 Comments
Newest
Oldest
Inline Feedbacks
View all comments

Primary Sidebar

Calculators

  • 3-Phase Power (15)
  • 324 IC Circuits (19)
  • 4017 IC Circuits (52)
  • 4060 IC Circuits (25)
  • 555 IC Circuits (98)
  • 741 IC Circuits (19)
  • Arduino Engineering Projects (83)
  • Audio and Amplifier Projects (114)
  • Battery Chargers (82)
  • Car and Motorcycle (94)
  • Datasheets (46)
  • Decorative Lighting (Diwali, Christmas) (33)
  • Electronic Components (100)
  • Electronic Devices and Circuit Theory (36)
  • Electronics Tutorial (116)
  • Fish Aquarium (5)
  • Free Energy (34)
  • Fun Projects (13)
  • GSM Projects (9)
  • Health Related (20)
  • Heater Controllers (29)
  • Home Electrical Circuits (102)
  • How to Articles (20)
  • Incubator Related (6)
  • Industrial Electronics (28)
  • Infrared (IR) (40)
  • Inverter Circuits (98)
  • Laser Projects (12)
  • LED and Light Effect (93)
  • LM317/LM338 (21)
  • LM3915 IC (25)
  • Meters and Testers (65)
  • Mini Projects (148)
  • Motor Controller (67)
  • MPPT (7)
  • Oscillator Circuits (26)
  • PIR (Passive Infrared) (8)
  • Power Electronics (34)
  • Power Supply Circuits (77)
  • Radio Circuits (10)
  • Remote Control (48)
  • Security and Alarm (61)
  • Sensors and Detectors (120)
  • SG3525 IC (5)
  • Simple Circuits (75)
  • SMPS (29)
  • Solar Controllers (60)
  • Timer and Delay Relay (53)
  • TL494 IC (5)
  • Transformerless Power Supply (8)
  • Transmitter Circuits (40)
  • Ultrasonic Projects (16)
  • Water Level Controller (45)

Calculators

  • AWG to Millimeter Converter
  • 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
  • Small Signal Transistor(BJT) and Diode Quick Datasheet
  • Transistor Astable Calculator
  • Transistor base Resistor Calculator
  • Voltage Divider Calculator
  • Wire Current Calculator
  • Zener Diode Calculator

© 2023 · Swagatam Innovations

wpDiscuz