There were many labs this week that helped me better understand programming the Arduino. The first was using photosensors to control the sound out of a speaker. After spending much time using the photosensor last week, it was the type of analog sensor I felt most comfortable with.

Witness Dhru demonstrate the beauty of the program… and what not to do in nail care.

Dhru also led me to do a bit of research after the second lab. In order to play the music, I needed the pitches.h file, but it wasn’t a pre-built library so I made a second script by cutting and pasting the code list. I noticed in the lab you call it with #include “pitches.h”, but I had learned that in C you call a library with < and > framing it. Dhru thought maybe the Arduino wasn’t in C, but after reading up a bit more, I realized the parenthesis was because we were calling another named script. In the servo lab when you include an actual library, it is represented the way I learned it.

Screen Shot 2015-09-25 at 4.40.44 PMScreen Shot 2015-09-25 at 4.41.04 PM

And here’s the video of the song playing.

The third lab was the first time I have ever used FSR sensors and I found making music with it rather amusing. However, it’s not easy to press sensors and hold the camera steady so please pardon my shaky cam.

And the final lab involved using the servo library which led to my breakthrough with Dhru on why the pitches were included differently than the other libraries I had used.  Here’s the code below.

Screen Shot 2015-09-27 at 1.58.55 PM

And here is the video of fun with a servo!

With the projects, I find making things that I have seen in the real world the most gratifying. It is less creative, but knowing I can build things myself is for me the best step in realizing I’m learning valid skills. After programming the song in the labs, I decided I wanted to make a twisted jewelry box… A Big Box of Death that opened and played Chopin’s Funeral March.

Since I use the box normally for other things, I didn’t attach any of the parts for permanency. I simply used a flex sensor, a pull down resistor and the speaker. The first step in the process was building a circuit and checking the sensor’s range. With a 10 K ohm sensor the range was next to nothing. It turned out the resistor was too small. After doing some research online,  I switched to a 20K ohm resistor. It greatly increased the range – enough for the project to work, but I realized if I wanted to truly utilize the full range on another project, I would need to go with an even larger pull down resistor.

Most of the set up was similar to the other project, but the coding was where the fun came in. First I had to find sheet music for the song and program it in. Then make the arrays and loops to make it play when the box is open, but turn off when the box is closed.

Screen Shot 2015-09-29 at 8.59.59 PM

Screen Shot 2015-09-29 at 3.00.36 PM

I toyed with the idea of playing the song once and then stopping it. First I tried doing this with a boolean expression and carrying it out throughout the program. It worked, but then if you closed the box and reopened it, the song would no longer play. I could not find a way without building a second circuit and sensor to know when the box was opened or closed. If I used the same flex sensor reading, anything I did to stop the song from looping, would also stop the song from playing every time it was opened. Is there another way I’m not thinking of? Here is the Big Box of Death in action.

I decided against building a second circuit today since there’s already no space in the box for anything but the electronics as you can see above. But I am still curious if there is a way to do it without a second circuit.

This Big Box of Death was hardly profound, but it made me feel pretty good about understanding the code involved.