PCOMP MIDTERM MEETS HALLOWEEN / by Maya Pruitt

Perfectly timed with Halloween, it was only fitting that our Physical Computing midterm would be something interactive with this theme. For this project I worked with Khensu-Ra Love El (check out his blog here).

Rather than a likely spooky scary approach, we decided to do something fun and make a Halloween Disco Ball! This post documents the process.

When coming up with ideas we talked about different sensors we wanted to try, as well as how we wanted people to interact with our project. I really wanted to use a photocell resistor in this project, which is a sensor that measures light. I loved the idea of creating two states with our project, how would exist by day versus night?

My main idea was to have the photoresistor set to a threshold to know when it is dark in a room. Darkness would trigger different party lights. Khensu-ra also liked the idea of adding music, which I was definitely on board with. This became a really great way to include serial communication to Javascript since we were motivated to use actual mp3 files, not just robotic tones on the Arduino. Specifically, I had to have this thing play Thriller!

We decided to create two states, one in light and one in darkness - an ode to Halloween as a celebration of creatures of the night. Initially we thought of doing a Jack-o-lantern looking enclosure. We imagined that in the light state, the lantern would flicker like a candle and in darkness it would light up in different colors. Kind of a fusion of the images below:

Jack-o-27-Lantern-300x2661.jpg
disco-ball-8292-p.jpg

Creating the flickering candle effect seemed like a good place to start. Referencing this code, the Arduino and LEDs create a convincing candle light effect, especially when placed behind a translucent material (a sheet of paper in the video below).

flicker_candleEffect.gif

To create the trigger of light to dark, we decided to use a photocell resistor, which measures light. Even though it’s tiny, it’s quite sensitive. On the breadboard, I added more LEDs and figured out a threshold for the photocell. If the photocell is above a certain threshold value: enter candle state, if the value is below the threshold: enter part state.

partylights.gif

After creating these two initial states, we met with our Professor David Rios to figure out how to play music beyond Arduino tones. This proved to be a good opportunity to try serial communication. p5.js could read incoming photocell value readings and play music accordingly. We decided that turning the lights out in a room would also trigger the music playing.

It took us quite a bit of logic to figure out how to write the code for this. We needed our discoball to be aware of its state. It needed to recognize that it was both below the darkness threshold as well as know if it had already begun playing music.

function gotData() {
  photoVal = serial.read();
  if (photoVal < threshold && isDark == false) {
    song.play();
    isDark = true;
  }
  if (photoVal > threshold && isDark == true) {
    song.pause();
    isDark = false;
  }
}

Function gotData() reads the incoming photocell value from the Arduino and plays music when conditions of the if statements are met.

The result is a pretty sensitive system:

To make the lights more responsive and interesting, I wanted them to pulse to the beat of the music. I thought this would add more drama to our disco ball. I explored audio frequency visualization first in p5.js (see code for that here). The next step was to add serial communication again, but now going the other way, to have p5.js send instructions to Arduino (serial out). The beauty of this is that the code for my ICM beat visualization remains the same, p5 can use FFT to parse through the music, it then sends out a bunch of serial.write() commands that the Arduino then reads to light the LEDs accordingly. Below is a video of this first test with a single LED mapped to the bass of the song.

Then I added two more LED to indicate bass, midvalue, and treble! [video]