Changes between Version 3 and Version 4 of ControlSystems/Electrical/Training/Arduino/Lesson4


Ignore:
Timestamp:
Oct 14, 2015, 9:28:43 PM (10 years ago)
Author:
David Albert
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ControlSystems/Electrical/Training/Arduino/Lesson4

    v3 v4  
    66You can connect your speaker to one of the arduino digital pins (red wire) and ground (black wire) and use the tone() function to generate sound!  Because the wires on the speaker are very thin, it may be hard to get them into the holes on the arduino or breadboard.  You can try using one lead from a resistor to push them in or ask a mentor or senior student for help.  If needed, we can solder thicker wire leads to the ends of the speaker wires.
    77
    8 * [http://www.instructables.com/id/Arduino-Basics-Making-Sound/ Instructable]
     8* [http://learning.codasign.com/index.php?title=Arduino_tone%28_%29 The simplest method]
     9* [https://www.arduino.cc/en/Tutorial/Melody Another approach] that's more complex, but more instructive
    910* [http://playground.arduino.cc/Code/MusicalAlgoFun a music program]
    1011* [https://www.arduino.cc/en/Tutorial/PlayMelody music with volume control]
    11 * [http://makezine.com/projects/make-35/advanced-arduino-sound-synthesis/ Advanced sound and waveform generator]
    1212
    1313**Exercises**:
     
    1818  * NOTE: later, we'll build a [https://learn.adafruit.com/adafruit-arduino-lesson-10-making-sounds/pseudo-theramin Thermin]
    1919
     20== Sound ==
     21Pure tones, such as the sound made by a [https://en.wikipedia.org/wiki/Piano_key_frequencies key on a piano], rise and fall in a ''sinusoidal'' pattern (sine wave).  Humans can typically hear sounds between 20Hz (sound rises and falls 20 times-per-second) and 20kHz (20,000 times per second); as we get older, we lose the ability to hear some of the higher frequencies which is why [http://www.noisehelp.com/ultrasonic-ringtones.html mosquito ring tones] were invented.  With most of the projects above, your Arduino has been making tones by turning the speaker on and off at some frequency.  The sound isn't great because we are using digital outputs to control the speaker; the outputs can only turn on or off, creating a square wave, not a sinusoidal pattern.  However, in the last project above you used an analog output that can vary the amplitude of its signal...this can be used to make better and different sounds as you'll see below.
     22
     23When you create more than one pure tone at a time, such as when you play a chord on a piano, the different [http://www.math.umn.edu/~rogness/math1155/soundwaves/ sound waves interact], add or subtract from each other and the result is a complex waveform.  Noise cancelling headphones work on this principle (they generate sound waves that are 180-degrees out of phase with the sounds around you so that when they mix, they cancel each other out.
     24
     25Your Arduino makes it easy to generate a single tone (using the tone() function), but it can also generate sounds that consist of multiple tones (this is called ''polyphony'').  Generating polyphonic music is more complex and there are several different approaches:
     26   * Use a library like [https://code.google.com/p/arduino-playtune/ Playtune], that generates several tones at once (each on a different pin) using dedicated Arduino hardware timers and then combine (add) the outputs together through series resistors to feed the speaker.  This is called [https://en.wikipedia.org/wiki/Additive_synthesis additive synthesis].
     27   * You can also use math to calculate the proper output; for example, calculating the amplitude of each tone and then adding the amplitudes together in software before sending the sum to the speaker.  This is called ''direct synthesis''.  Because some of the math calculations are complex and an small computers like an Arduino might not be able to perform them fast enough, we often use [http://telecnatron.com/articles/Simple-Direct-Digital-Synthesis-Tutorial/index.html tables of pre-computed values] to help generate the desired values; this is called [http://www.mobileer.com/wp/direct_vs_wavetable.pdf wavetable synthesis].  As digital hardware has gotten faster and faster, Direct Digital Synthesis is now a very popular way to generate waveforms.
     28
     29   * The [http://makezine.com/projects/make-35/advanced-arduino-sound-synthesis/ Advanced sound and waveform generator]
     30 project presents various approaches for generating polyphonic sound using an Arduino.
     31
     32== MP3 Player? ==
     33WAV files contain discrete measurements of the amplitude of sound waves you can [http://www.instructables.com/id/Simple-Wav-Player-Using-Arduino/?ALLSTEPS turn an Arduino into a .wav file player] or make it play back sounds you have recorded on your PC or perhaps [http://maxoffsky.com/maxoffsky-blog/how-to-play-wav-audio-files-with-arduino-uno-and-microsd-card/ yoda]
     34
    2035== Advanced Projects ==
    2136[http://www.tehnorama.ro/wp-content/uploads/2010/06/Arduino-LM386.png better sound]
    2237[http://blogspot.tenettech.com/?p=518 text to speech]
     38Make a polyphonic synthesizer