Upload
others
View
4
Download
0
Embed Size (px)
Citation preview
Self-Playing Xylophone
Matt McKinney, Electrical Engineering
Project Advisor: Dr. Tony Richardson
April 1, 2018
Evansville, Indiana
Acknowledgements
I would like to thank Jeff Cron, Dr. Howe, and Dr. Richardson for helping me through
the senior project process.
Table of Contents
I. Introduction
II. Background and Problem Definition
A. Background
B. Problem Statement
III. Design Approach
A. Design process
B. Software Design
C. Hardware Design
D. Mechanical Design
E. Parts List
F. Standards and Constraints
G. Costs
IV. Results
V. Conclusions and Recommendations
A. Recommendations
B. Conclusions
Appendix A
Appendix B
Appendix C
References
List of Figures
1. Picture of Xylophone
2. Software Flowchart
3. SD Card Circuit
4. Key Striking Circuit
5. Solenoid Mechanical Layout
6. Final Project
List of Tables
1. Table of Costs
I. Introduction
Many engineers struggle with the concept of music and many musicians struggle with the
concepts of engineering. Music and engineering are simply two very different subjects. This
project, a self-playing xylophone, blends these two unlike subjects. This is done by using
engineering principles to create music. To do this first a microcontroller reads in a song. Next
the microcontroller uses pin manipulation as an input to supporting circuitry. Finally this
circuitry controls solenoids which strike xylophone keys to play a song. The final result plays a
song. This project is useful for STEM education purposes. It could be taken into a school and
used as a demonstration piece to excite kids about the possibilities of engineering.
II. Background and Problem Statement
A. Background
Before addressing how to play a xylophone with solenoids, it is important to explain how
humans play xylophones. The musician holds two mallets. The instrument is a collection of keys
that each play a specific note when struck by a mallet [1]. Striking these keys in the right order
plays a song. A xylophone is pictured in Figure 1.
Figure 1: Picture of Xylophone [2]
B. Problem Definition
The minimum specification of the project was to play a simple song. This was done by
using the microcontroller to control 4 solenoids that strike the keys of the xylophone. The
microcontroller had a song preloaded on it. It will directly control 4 pins that were each linked
to a solenoid. The microcontroller used its programming of the song to play the xylophone.
After this was done the project was expanded upon.
After a simple machine capable of playing music was created, the next step was to
improve the system. This was done by adding features and expanding on what was already
completed. The project currently plays 15 keys. A demultiplexing system allows for controlling
more solenoids. A power circuit powers the solenoids. The software also plays more keys and
reads in musical files. The final product is also user accessible both in price and function. This
means that a normal person should be able to use this product and also afford it.
III. Design Approach
A. Design Process
The first task is to read in the song and interpret it. To read in the song it was chosen to
use an SD card. The challenge with this was to access the contents of the SD card with the
microcontroller. This was further complicated when one of the pins for this was already in use as
an output. The problem had to be worked around by rewriting the output code to use different
pins. The first musical file format it was planned to use was MIDI, but MIDI was overly
complicated for this project. So instead, ABC file notation was used. It is not overly complicated,
but still holds all the song information that this project needs. ABC is also easily interpreted as
characters by the microcontroller.
For the output to control the solenoids, the project uses pin manipulation. The challenge
was to pick the correct pins because the microcontroller has a limited number of pins. This
problem became further complicated by the use of an SD card and using serial communication
for debugging. The solenoid activation pins had to be reassigned.
The circuitry must be capable of controlling and powering the solenoids. It is necessary
for the logic circuit to be able to control all of the solenoids given a limited number of
microcontroller pins. This problem was further complicated by the fact that it is not easy to
locate the correct parts. Many of the ideal parts are no longer in production. When powering the
solenoids, it was important to find the right components that could provide the necessary amount
of power, not burn out while providing that power, and also be cost effective.
The solenoids must be able to play the song while also not drawing too much power.
They must also be cost effective.
The mechanical had to be made so that the project could be supported. First a small
prototype was built only using a couple of keys. After that a full design was created and
constructed considering aesthetics, durability, functionality, and cost.
B. Software Design
At the highest level the software reads in a musical file from an SD card. Then it uses the
file information to control I/O pins that play the xylophone keys
The microcontroller establishes communications with the SD card. Next, it opens up the
musical song file. Once the ABC (file overview of ABC file notation in Appendix A) is being
read off the SD card, the next step is to create an output based on the ABC file input. Stepping
through the file line by line, each character is evaluated. First, the header section of the ABC file
is ignored. Next, each note is read in. The code checks where the note is on the scale and how
long it is played. This is done determining if the note is an upper or lower case letter. Then
subtracting based on whether it is upper or lower case. Then it is checked if the note has a
character a certain character after it. If there is, another subtraction is made. Through these two
subtractions, the note in the song is converted into a number which correlates to a position in an
array. The position in the array correlates to the physical key on the xylophone which is to be
played. After determining the note, the next character is checked to see how long the note is to
be played and a delay is set that correlates to how long the note should be played. Finally, to
play the note the physical key to be played is loaded into the I/O pins. The output is quickly
enabled and disabled to strike the key and then there is a delay corresponding to how long the
note is to be played. If the note is within range, the note is played for the desired time. Then the
next note in the song is checked and the process is repeated until the song is over. A flow chart
of the code is given below in Figure 2.
Figure 2: Software Flow Chart
C. Hardware Design
At a high level, the hardware provides power to the project, allows for the SD card to
communicate with the microcontroller, controls and powers solenoids, and provides power to the
project.
The SD card circuit is straightforward with wires running directly between the
microcontroller and SD card reader. The circuit shown below in Figure 3.
Figure 3: SD card circuit
After the music file is interpreted by the microcontroller the next step is to demultiplex
the 5 pins from the microcontroller into a single output. This was done by making a 5 to 32
demultiplexer. This was done by cascading five 3 to 8 demultiplexers. The demultiplexers are
active high because the solenoid retracts when they are turned on. This circuit runs on 5 volts.
After the demultiplexer there is a power circuit which powers the solenoids. This circuit consists
of an NPN transistor which is being used as a switch and a diode snubber. This circuit is
triggered by the 5 volt logic circuit, but provides 12 volts to the solenoid. The circuit is shown
below in Figure 4.
Figure 4: Key striking circuit
The solenoid is used to strike the xylophone key. The solenoid has an electromagnet
which retracts the cylinder when it is turned on and releases the cylinder when it is turned off. To
strike the key the solenoid is quickly turned off and then back on. This is shown below in Figure
5.
Figure 5: Solenoid mechanical layout.
D. Mechanical Design
The goal of the mechanical design is to support the rest of the project. The mechanical
design consists of two parts: the xylophone and the support apparatus. The xylophone was first
altered by cutting off the extra plastic with a Dermal tool. After doing this there was only the
xylophone. Next, polycarbonate was cut and drilled and mounted above the xylophone with a
hole above each key. A solenoid was mounted in each hole so that it can strike its corresponding
key. A polycarbonate sheet was mounted above the unused sharps and flats keys to support all of
the hardware and software electronics. The mechanical design is shown in Figure 6.
E. Parts List
SD Card Module: Used to interface SD card with microcontroller. [3]
UNO R3 Board ATmega328P: Microcontroller used in project. Picked because this
Atmel chipset is well developed, cost effective and the engineer had experience with it.
[4][5]
MM74HCT138N: 3:8 demultiplexer used to link micro output to solenoid power circuit.
Also active high which is required for project. [6]
N2222: NPN transistor used to power solenoids. Cost effective transistor that fits within
the power specifications.
1N4001: Diode used for snubber circuit. Cost effective diode that fits within the power
specifications [7]
3V-12V DC 80mA-350mA Micro solenoid: This solenoid provides enough power to
strike the solenoids with good sound quality and also does not draw too much current. [8]
NOTE: These solenoids did not end up being used because the supplier sent the wrong
solenoids. The solenoids that where shipped are lower power and do not work as well.
#10-24 Screws/nuts: A good size machine screw that is robust enough to support the
project
Polycarbonate: Used for mounting solenoids. Strong enough to support mechanical stress.
Also clear so that project can be viewed.
25 Note Xylophone: Children’s xylophone that can handle the mechanical apparatus
attached to it and also produce reasonable sound quality. [9]
PS-5231-5DF1-LF power supply: The power supply was chosen because provides
necessary voltages.[10]
F. Standards and Constraints
When designing this project it is important to take several factors into account.
Economically/Manufacturability, the design will is able to be produced so that it if it ever
becomes a consumer product it can be manufactured economically. This is done by choosing
parts that are easily mass produced. This means that the parts are manufactured or produced
cheaply. Environmental impacts must also be considered. Solenoids draw a lot of current and
thus power. This power is reduced to decrease the environmental impact. Also, if this product
were mass produced the manufacturing techniques would need to be analyzed for environmental
impact. Social/political/ethical, most people think of music as simple entertainment, but some
people use it for harm. Many songs have been shown to be racist, offensive, and political. This
product will have the capability to play these songs. To do this may be wrong, but since I am not
personally playing the song I will leave that choice up to the individual. Two factors come into
health and safety. If water is spilled on the project it could short out and become a shock hazard.
The final project has taken steps to reduce this risk. Also, the solenoids contain cylinders which
have the potential to come free. These cylinders could then be choked on. The project has tried to
eliminate this threat by making it so the solenoids are unable to come free.
For this project ISO/ICE/IEEE standard 24748-5-2017 [11] was considered. This
standard relates to the life cycle of software. The project has software so the life cycle of said
software is important.
G. Costs
The table of costs is given below in Table 1.
Table 1: Costs
IV. Results
The overall result is a working prototype of a self-playing xylophone. This prototype
could be adapted to go into full scale production. The entire working project has several
working sub parts. Working hardware includes an SD card reader, logic circuit, and key striking
mechanism. The working code sections that read in an ABC file form an SD card, interpret ABC
Product: Quantity: Cost: Part Total:
Microcontroller $1.00 $30.00 $30.00
Solenoids 15 $7.99 $119.85
Demultiplexer 4 $0.59 $2.36
Transistors 15 $0.02 $0.30
Diodes 15 $0.05 $0.75
SD Card Adapter 1 $5.99 $5.99
Polycarbonate Sheet 1 $10.99 $10.99
Hardware 1 $4.99 $4.99
Xylophone 1 $32.55 $32.55
Power Supply 1 $14.99 $14.99
Total $222.77
file notation, and create an output based on the ABC file notation. The project also has a solid
mechanical design. Which could also be adapted to if the project went into production. A picture
of the project is below in Figure 6.
Figure 6: Final project
V. Conclusions and Recommendations
A. Recommendations
If this project were to be remade or put into production, there are several things to be
considered. The solenoids right now are active high instead of active low. This means that to
retract they need to be turned on. The power consumption of this project could be optimized if
they were active low. Before going into production it would be important to get a reliable
solenoid supplier. For this project the solenoids were purchased from an unreliable supplier and
the wrong solenoids were delivered.
B. Conclusions
As stated in the results, this is a working project. It can be used to get kids interested in
STEM. The project could be expanded on to include controlling more keys, playing cords, or
adding a touch screen. There are many different directions that this project could be taken into.
Also, the way that the project is now, it could be taken into production. So to summarize this
project is working as is and can be expanded on or taken into production.
Appendix A
This appendix discusses ABC file notation. The first thing in an ABC file is the header.
It contains information about the song. The header is denoted in Figure 5. The next part of the
file is the notes. The notes correlate to the notes in the song. This is also denoted in Figure 5
below. [12]
Figure 6: ABC file example [12]
Appendix B
This appendix includes the code used on the Self-Playing Xylophone project.
const int enablePin = 9;// Control pins
const int controlPin0 = 2; const int controlPin1 = 3; const int controlPin2 = 5; const int controlPin3 = 6; const int controlPin4 = 7; const int button = 8; char song[] = "C, D, E, F, | G, A, B, C|D E F G|A B c d|e f g a|b c' d' e'|f' g' a' b'"; byte notecontrol[] = {0x01,0x02,0xFE,0xFE,0xFE,0xFE,0x00,0x08,0x09,0x03,0x04,0x05,0x06,0x07,0x0FF,0xFF,0x0A,0x0B,0x0C,0x0D,0x0E,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
void setup() { // put your setup code here, to run once: Serial.begin(9600);
pinMode(enablePin, OUTPUT); pinMode(controlPin0, OUTPUT); pinMode(controlPin1, OUTPUT);
pinMode(controlPin2, OUTPUT); pinMode(controlPin3, OUTPUT); pinMode(controlPin4, OUTPUT); pinMode(button, INPUT); digitalWrite(enablePin, LOW); } void loop() { // put your main code here, to run repeatedly: for (int i=0; i < sizeof(song) ; i++){ int note = song[i];
if ((song[i] >= 'A' && song[i] <= 'G')){ note = note - 58; if (song[i+1] == ',') { note = note - 7; } Serial.println(notecontrol[note]); Playnote(notecontrol[note]); } if ((song[i] >= 'a' && song[i] <= 'g')){ note = note - 83;
if (song[i+1] == 39) { note = note + 7;
} Serial.println(notecontrol[note]);
Playnote(notecontrol[note]); } delay(250); } } void Playnote(byte n){ Serial.println("Playing note"); Serial.println(n);
if( (n & 0x01) != 0){ digitalWrite(controlPin0, HIGH); Serial.print("1"); } else{ digitalWrite(controlPin0, LOW); Serial.print("0"); } if( ((n>>1) & 0x01) != 0){ digitalWrite(controlPin1, HIGH); Serial.print("1"); } else{ digitalWrite(controlPin1, LOW);
Serial.print("0"); } if( ((n>>2) & 0x01) != 0){
digitalWrite(controlPin2, HIGH); Serial.print("1"); } else{ digitalWrite(controlPin2, LOW); Serial.print("0"); } if( ((n>>3) & 0x01) != 0){ digitalWrite(controlPin3, HIGH); Serial.print("1");
} else{ digitalWrite(controlPin3, LOW); Serial.print("0"); }
if( ((n>>4) & 0x01) != 0){ digitalWrite(controlPin4, HIGH);
Serial.println("1"); } else{ digitalWrite(controlPin4, LOW); Serial.println("0"); } digitalWrite(enablePin, HIGH); delay(50); digitalWrite(enablePin, LOW);
}
Appendix C
This appendix includes the circuit schematic used on the Self-Playing Xylophone project.
References
[1] ‘How Does a Xylophone Work?’ [Online]. Available: https://ourpastimes.com/how-does-a-
xylophone-work-12165630.html [2] ‘Kids Xylophone’ [Online] Available: www.educationaltoysplanet.com/wood-
xylophone.html [3] ‘SD Card Module Slot Socket Reader for Arudino UNO R3 Mega 2560 Nano’ [Online]
Available:
https://www.amazon.com/gp/product/B00WH7WXRC/ref=oh_aui_detailpage_o02_s00?ie=UTF8&psc=1
[4] ‘ARDUINO UNO REV3’ [Online] Available: https://store.arduino.cc/arduino-uno-rev3 [5] ‘AVR 28 Pin 20MHz 32K 6A/D - ATMega328P’ [Online] Available:
https://www.sparkfun.com/products/9061
[6] ‘MM74HCT138N’ [Online] Available: https://www.mouser.com/productdetail/on-semiconductor-fairchild/mm74hct138n?qs=%2FXEtZmhGuCGdB8ctGZq3Og%3D%3D
[7] ‘100x 1N4001 Molded Plastic Case Rectifier Diodes, 1A, 50V DO-41’ [Online] Available: https://www.amazon.com/gp/product/B06XC1V28Z/ref=oh_aui_detailpage_o02_s00?ie=UTF8
&psc=1
[8] ‘3V-12V DC 80mA-350mA Micro solenoid electromagnet push and pull dc Miniture electromagnet Mini Solenoid Electromagnet’ [Online] Available:
https://www.amazon.com/gp/product/B00ZC53KB4/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1
[9] ‘Lyons 25-Note Xylophone (Glockenspiel) with Case’ [Online] Available:
https://www.amazon.com/Lyons-25-Note-Xylophone-Glockenspiel-Case/dp/B001VO7FPC/ref=sr_1_1?s=industrial&ie=UTF8&qid=1521143716&sr=8-
1&keywords=25+note+xylophone [10] ‘Server Supply’ [Online] Available:
https://www.serversupply.com/products/part_search/query.asp?q=PS-5231-5DF1-
LF&msclkid=7c383f8a1ccd167ce61c655562d48266 [11] ‘ISO/IEC/IEEE 24748-5:2017’ [Online] Available:
https://www.iso.org/standard/60062.html [12] ‘How to understand abc (the basics)’ [Online] Available:
http://abcnotation.com/blog/2010/01/31/how-to-understand-abc-the-basics/