Notifications
Clear all

Take a Break II – Arduino Festive Carols

5 Posts
2 Users
4 Likes
335 Views
ron bentley
(@ronbentley1)
Honorable Member
Joined: 11 months ago
Posts: 383
Topic starter  

Take a Break II – Arduino Festive Carols

“Post early for Christmas”, so the Post Office tells us, so, here is my Christmas post for my “Take a Break” article for any interested forum members...

 

Christmas Carols splash

 

A little while ago I posted an article called “Take a Break – The Collatz Conjecture”, to offer a little respite from the deep thinking, soldering, wiring, etc that many members engage in day to day in their pursuits and projects. Its purpose was to provide a little light relief and interest.

Well, the festive season is approaching and I thought I would offer a second “Take a Break” post for those that may have an interest in using an Arduino (and a few basic components) to play carols. It may be something you can load up and have playing in the workshop background during the holidays to bring a little festive cheer and atmosphere? Anyway, I offer this for your interest and amusement, so, why not switch off the soldering iron, put on the coffee, grab a biscuit and take a short break?

What the Sketch Does

The Arduino sketch, included below, will play 10 well known carols cyclically, shuffling their play order between cycles. The 10 carols are:

  • Away In A Manger
  • Ding Dong Merrily
  • Good King Wenceslas
  • Jingle Bells
  • O Come All Ye Faithful
  • Silent Night
  • The First Nowell
  • The Holly And The Ivy
  • We Three Kings
  • We Wish You A Merry Christmas

 

What You Will Need

  • 1 x Arduino or compatible MCU, any should do, e.g. UNO, MEGA, etc
  • A bread board, a small one is perfect
  • 1 x 0.25 Watt, 8 ohm speaker (you could use a buzzer but the sound quality is poor)
  • 1 x 100 Ohm resistor
  • 2 x of M-M connecting wires
  • Arduino IDE or whatever you use as your editor
  • The Carols Sketch

 

Use the breadboard to wire up the circuit which is very simple:

arduino and speaker

 

I used an UNO and pin 11, but any pin should be ok, and the speaker I recycled from an old desk top.

And here is the sketch:

 

That’s it, plug and play away!

 

Final Notes, Observations & Limitations

The sketch incorporates the standard public pitch values of notes over several octaves. This is often seen as a “pitches.h” file (see github), but I brought its macros it into the sketch because I wanted to modify the note/tone names and add flats to the standard list.

The limitation of the sketch is that will only support a single channel because it is based on the standard tone() function.  This aside, the tunes are still reproduced faithfully and surprisingly well.

You may, of course, add your own tunes using the sketch – follow its lead. Indeed, I have many well known tunes already coded by, for example, the Beatles, The Dubliners, John Denver, Don McLean, etc.,  but can’t distribute due to copyright.  As far as I know the carols I have included are royalty free.

One last point about the sketch design for the keen eyed – you will see that the musical scores are not defined as preset arrays of notes and durations, rather, they are crafted as a succession of ‘play’ and ‘rest’ function calls following a score note by note.  This is because many musical scores have repeated passages which are much easier to represent using standard C++ constructs, e.g. for loops. 

 

Conclusion

Hopefully you will find this post of interest and, who knows, add another string (pun definitely intended) to your bow (violin?).  If you wish to explore the subject of this “Take a Break” post further then you will find a more comprehensive article on the Arduino Project Hub: Christmas Carols.  You will also find links at the end of Hub article to two other music related articles – “Music & Lights Workbench” and “Let’s Make Music”.  I won’t describe these latter two articles here but if you are interested the do follow the links via the “Christmas Carols” article on the Arduino Project Hub.

Have a great holiday!

Cheers

Ron B

(I have not looked to port the sketch to an ESP32 platform but this should work okay – just check the random functions are suitably defined – if the ESP32 is running wifi/blue tooth then the random seed call may not be needed. Also change the pin number used to drive the speaker.)

 

Ron Bentley
Creativity is an input to innovation and change is the output from innovation. Braden Kelley
A computer is a machine for constructing mappings from input to output. Michael Kirby
Through great input you get great output. RZA
Gauss is great but Euler rocks!!


   
Quote
ron bentley
(@ronbentley1)
Honorable Member
Joined: 11 months ago
Posts: 383
Topic starter  

Update:

I have extracted the musical notes and standard tempos that the christmas_carol sketch uses into a header file which I attach here should anyone wish to grab a copy for their future use.

The header file should be located under the Arduino/libraries directory in a file called "musical_notes".

 If you wish to use the header file and its macros then add "#include <musical_notes.h> at the top of your sketch.

Note that this file is largely the standard public "pitches.h" header file but is enhanced by the addition of flats.

Regards

Ron B

 

Ron Bentley
Creativity is an input to innovation and change is the output from innovation. Braden Kelley
A computer is a machine for constructing mappings from input to output. Michael Kirby
Through great input you get great output. RZA
Gauss is great but Euler rocks!!


   
ReplyQuote
TBerryKev
(@tberrykev)
Active Member
Joined: 3 months ago
Posts: 9
 

What great fun!

 

Do you have any recommendation on the speaker?

-- Kevin


   
ron bentley reacted
ReplyQuote
ron bentley
(@ronbentley1)
Honorable Member
Joined: 11 months ago
Posts: 383
Topic starter  

@tberrykev

Hi Kev, thanks for your kind post, so pleased it landed well with you.

I used an old reclaimed PC speaker which worked a treat. So long as you source a decent diaphragm speaker, 0.25 watt 8 ohm that should work just fine.

Alternatively, and this is something I haven't tried, connect to an audio amp with suitable precautions to protect the MCU as necessary/appropriate.

If you are musically inclined you will see how to transcribe a score using standard musical notations by following the sketch and, for a greater insight, my Arduino Project Hub link for "Let's Make Music".

Enjoy

Ron B

 

Ron Bentley
Creativity is an input to innovation and change is the output from innovation. Braden Kelley
A computer is a machine for constructing mappings from input to output. Michael Kirby
Through great input you get great output. RZA
Gauss is great but Euler rocks!!


   
ReplyQuote
ron bentley
(@ronbentley1)
Honorable Member
Joined: 11 months ago
Posts: 383
Topic starter  

@tberrykev

Hi Kev,

Just done a quick net search and a suitable speaker can be sourced from:

https://www.adafruit.com/product/1891

Its 0.25 watt  8 ohm and around $1.75 plus p&p

Regards

Ron b

Ron Bentley
Creativity is an input to innovation and change is the output from innovation. Braden Kelley
A computer is a machine for constructing mappings from input to output. Michael Kirby
Through great input you get great output. RZA
Gauss is great but Euler rocks!!


   
ReplyQuote