$\require{color}$

# Laser Harp : Hackathon 2017

#### May 18th, 2017

For the second time, I served as a mentor for my high school/middle school’s annual Hackathon. Despite being extremely busy helping out with the incredible projects the students were building, I found time and was able to work with my friend Andrew to complete a Laser Harp. Here is a video demonstrating our harp

In this post, I will attempt to explain the basics of how this project was built. Hopefully this project inspires others and sparks some interest in both Electronic Instruments and Arduino as a whole.

### I. Electronics Materials

– Arduino Mega

– (8)   5V lasers

– (8)   photoresistors

– (8)   3k$\Omega$ resistors

We used the Arduino Mega because we needed 8 analog inputs and the Arduino Uno only has 6. We needed our lasers, of course, and the photoresistors and 3k resistors were be used to detect the breaking of the laser beam.

### II. Circuits

To sense how much light was hitting the photoresistor, we used a potential divider, shown below

To find the ideal value for the resistor, we first looked at the datasheet for the photoresistors. When dark, the resistance is around 10k$\Omega$, and when exposed to natural light, the resistance is approximately 1k$\Omega$. With $R_{pr}$ being the resistance of the photoresistor, the voltage across a potential divider is given as

$$V_o = V_i \cdot \frac{R_{pr}}{R_{pr} + R}$$

We wanted to maximize the difference between $V_o$ when the beam was shining and $V_o$ when the beam was broken.

$$V_{dark} – V_{light} = V_i \cdot \frac{R_{dark}}{R_{dark} + R}-V_i \cdot \frac{R_{light}}{R_{light} + R}$$

$$\approx V_i \cdot \frac{10000}{10000+ R}-V_i \cdot \frac{1000}{1000 + R}$$

Graphing this function as a function of R, we see that the largest difference occurs around $R=3000$. By using this value, we maximized the difference between our two readings, minimizing the chance that we would make an error.

### III. Code

Unfortunately, we didn’t take pictures while actually building, so we have to skip the construction step. It was pretty easy, though, as it’s pretty much just 4 pieces of wood screwed together in a rectangle. For the code, we used a program called Max/MSP. It’s a visual programming language that is extremely well documented and has very nice MIDI interfacing. MIDI, which stands for Musical Instrument Digital Interface, is the globally accepted protocol for electronic instruments (instruments that don’t actually have an acoustic chamber, essentially). We used the Arduino to read in analog data, and then used a serial port to relay that data into Max. Here is a look at the Max patch we wrote

It looks really complicated. Well, actually, it IS pretty complicated, but I’m going to ignore all the boring stuff, which eliminates some of the more complicated things. I’m going to focus mostly on two parts; the note generation section and the scale selector.

#### A. Scale Selector

Let’s go piece by piece here and analyze what is happening. The user selects a starting note (C is MIDI note 60, C# is 61,… B is 71), and a scale pattern. It sets the starting note as $n1$, the note of the first string on our harp. That’s the left side of the picture. On the right, we have the scale setter. It uses the pattern for the scale shape selected (a major scale is 2212221). As it cycles through, the router object connects the next note to the correct string, going up by one for each note. By adding the interval width to the previous note, we build the scale note by note. At the bottom we see the notes for C Major, the default scale.

#### B. Note Generator

This is the subpatch that actually takes an analog signal reading and decides what to do. It takes the analog value (the 1 with the blue triangle below it at the top of the image) and puts it into two if statements. If it goes above the threshold, it triggers the note, but it uses a onebang object, which only sends 1 “trigger” message at a time. Once the signal goes below the threshold (i.e you unblock the laser), the note off is sent, and the note on onebang is reopened. This prevents the user from sending tons and tons of notes when only plucking the “string” once. The pack objects just insert the correct note number into a message that is then sent to the MIDI output.

### IV. Conclusions

This project was pretty awesome. It worked on the first go, which is always nice. In addition, I got to work with a bunch of awesome students who were pretty interested in what we were cooking up with a bunch of lasers. Andrew and I were extremely proud of the harp, especially given that we only had 2 days to complete it.  As always, thanks for reading!