Boom-Bach, Nightlights and Stress

Tom: I enlarged and bolded the font to – hopefully – make this an easier read on your eyes. If this is still an unpleasant experience let me know and I’ll continue adjusting. Thanks!

Now that I’m a little bit more comfortable with the Arduino, I thought it would be fun to try to use my sensors for fun applications. The first one I came up with was a photocell that I used to turn into a nightlight. I wired my photocell to my analog input, put a 10 kilo-ohm resistor at the junction point, and connected an LED to a digital input. When first trying to figure out the code, I was using if statements but then I realized I just had to go back to what we’d learned earlier with digitalWrite and the process became a lot simpler. Here is a video of the nightlight at work and the code that made it work.

The second application was birthed of the love-o-meter in the lab. I don’t know about you but watching that debate last week got my blood boiling. I figured I’d take the love-o-meter and make it a stress-o-meter for the next debate: if I wasn’t really squeezing the FSR then I could keep watching the debate (as would be indicated by the green light). However, if I was starting to get too pissed off at Trump and was squeezing the FSR too hard, it would probably be better for me to change the channel.

Last but not least, I wanted to play around with melody and the Arduino. One of my favorite songs to play on my bass is the Bach’s Cello Suite # 1: Prelude in G Minor. I really wanted to hear how it would sound coming from a microcontroller so I pulled up the sheet music and input the first eight bars into the code. To me hearing it come from an Arduino as opposed to a cello is akin to that infamous transition in 2001: A Space Odyssey when the ape throws his bone-cum-instrument into the air only to have it “land” as a futuristic space vessel. There is one thing I am still struggling to figure out though: how to control the volume on the 8ohm speaker. I think the people around me on the floor don’t like Bach as much as I do.

#include “pitches.h”

int melody[] = {
NOTE_G3, NOTE_D4, NOTE_B4, NOTE_A4, NOTE_B4, NOTE_D4, NOTE_B4, NOTE_D4,
NOTE_G3, NOTE_D4, NOTE_B4, NOTE_A4, NOTE_B4, NOTE_D4, NOTE_B4, NOTE_D4,
NOTE_G3, NOTE_E4, NOTE_C5, NOTE_B4, NOTE_C5, NOTE_E4, NOTE_C5, NOTE_E4,
NOTE_G3, NOTE_E4, NOTE_C5, NOTE_B4, NOTE_C5, NOTE_E4, NOTE_C5, NOTE_E4,
NOTE_G3, NOTE_FS4, NOTE_C5, NOTE_B4, NOTE_C5, NOTE_FS4, NOTE_C5, NOTE_FS4,
NOTE_G3, NOTE_FS4, NOTE_C5, NOTE_B4, NOTE_C5, NOTE_FS4, NOTE_C5, NOTE_FS4,
NOTE_G3, NOTE_G4, NOTE_B4, NOTE_A4, NOTE_B4, NOTE_G4, NOTE_B4, NOTE_G4,
NOTE_G3, NOTE_G4, NOTE_B4, NOTE_A4, NOTE_B4, NOTE_G4, NOTE_B4, NOTE_FS4,
NOTE_G3, NOTE_E4, NOTE_B4, NOTE_A4, NOTE_B4, NOTE_G4, NOTE_FS4, NOTE_G4,
NOTE_E4, NOTE_G4, NOTE_FS4, NOTE_G4, NOTE_B3, NOTE_D4, NOTE_CS4, NOTE_B3,
NOTE_CS4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_A4, NOTE_G4,
NOTE_CS4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_A4, NOTE_G4
};
int noteDurations[] = {
16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16,
};

void setup() {
for (int thisNote = 0; thisNote < 96; thisNote++) {
int noteDuration = 1000 / noteDurations [thisNote];
tone(8, melody[thisNote], noteDuration);

delay(noteDuration + 96);
}
}
void loop() {
}

Leave a Reply

Your email address will not be published. Required fields are marked *