Introduction: Interactive Sound in a Box/jar
Like the title of the instructable implies, we shall be storing sound in a box/jar. Also, there is a little twist. In the project, we will be creating a Smartphone application. Here, we can select the music/sound we want to be played. This Smartphone is then attached to the bottom of the box and sealed close. The sound has been stored. Whenever we open the box or jar, the music starts playing. To remove a song, simply pour it away, as if pouring out liquid, by tilting the container being used.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: How It Works
Before we begin, I'll like to explain how the mobile application will work hand in hand with the box. It shall function in three main ways:
1--An audio is chosen from the SD card of the smartphone. The phone is attached to the bottom of a box (or a jar). The application features proximity sensors which can detect whether the cover is being used or not. The screen of the phone has to be facing upwards.
2--If the box is closed, (that is, the cover is used over the top), the phone remains silent. When the lid gets removed, the proximity sensors detect this. Then the audio begins playing.
3--To remove the audio, simply tilt the box, as if trying to pour out the content. Accelerometer sensors detect this change and implements a removal function
Step 2: What You Need
1--A cardboard box. Alternatively, a jar or any other container can be used.
2--A smaller box. (This one should be the size of your smartphone The tighter they fit, the better. .)
3--Tape or glue (They can both be gotten from craft shops)
4--A working Smartphone.(for testing)
5--A computer. (The system of your computer should be able to take the Android Studio bundle. It's a heavy program, just so you know. Without good processing speed, using it will go at snail-pace. It slows down the entire system. Processing speeds of 512Hz ++ and adequate computer space is required)
Step 3: Taping
Using either tape or glue, attach the small phone box to the bottom of the larger cardboard box. If you're using a jar, do the same.
Step 4: The App: Commencing.
We will be writing the application in the java programming language. If you don't have it already, download Android Studio. You can download it Android Studio will not work without the Java development kit so you will have download that too. With both programs installed, open Android studio and launch a new application. It is solely your choice to name it what you want. I named my app 'MagicJar'
Note: Being a beginner programmer, writing such an app was kind of difficult for me. There are probably a lot of bugs/errors. If you are familiar with programming and find errors, do point them out in the comment section.
The codes written here are just those which I depict most important for explanation. There are other classes and lines which will not be included here. If I try to post everything, it will be difficult to explain what each line does.
Step 5: The Manifest File
In Android Studio, the Manifest.xml is where we declare permissions. These permissions will later be picked up by the android operating system during use. Google Play also uses these permissions to portray only the apps compatible with the user's system, in case the application gets published. We will edit the Manifest file to hold permissions to read and write files, hardware feature and others.
Step 6: Activity_main.xml
Found under the layout directory, the activity_main.xml file is where we can customize the various objects such ad button, images and so on. To make this simpler, we won't be chasing complexity and shall stick to a simple TextView which tells you select which audio you want to play and a ListView, where we will select a suitable song.
Step 7: MainActivity.java --Importations
The MainActivity.java holds the processes. Without it, the app will be nothing but a page which does nothing. We first start by getting a set of importations. These importations will have to be there. Miss one and the application will have bugs.
Step 8: MainActivity.java -- Listing Audio
These lines of code follow beneath the various importations. The first parts of the code automatically gets a list of all audio stored in the SD card with the .mp3 or /MP3 extension. By specifying the file extension, only an audio files will be listed.
Step 9: MainActivity.java -- Playing Audio
There is the part which checks if the cover of the box/ jar is open or close. It uses proximity sensors to calculate whether or not an object( the cover) is close or not. Proximity sensors are particularly useful in applications like cameras where the app needs to know the distance from the screen to the face.
If there is a cover on the top (that is, the box/jar is closed), the audio doesn't play. When the cover gets removed, the sensors can detect no object close to the phone. Hence, the audio begins playing.
Step 10: MainActivity.java -- Deleting
To delete an audio, we want to give the impression that we are simply throwing it away, like one would with water in a jar. Since the phone will attached to the box/jar, when we tilt it, the phone also tilts. Depending on how you placed the phone, this tilt can either be left or right or up or down. In my case, the tilting would be upwards if someone is pouring with the right hand and downwards if someone is pouring with the left hand. I
Sensors can detect tilt. We shall be writing codes which get the tilt of the device using coordinates. In my case, I used the y-coordinate. If the device moves 30+ degrees on either side, the audio will get removed.
Step 11: Finish
With this fun project, you can amaze people with a really interactive box/jar. I find it really impressive to make a sound recording of my voice and select it in the app. After putting the phone in the container and closing it, I place it on my headboard and go to bed. After waking up, it's cool to open the container and hearing my own voice greeting me with a fresh new message.