Week 5-Phototransistor

Phototransistors and Tone Output in Arduino

Themis García
Physical Computing — ITP
3 min readOct 8, 2019

--

In this assignment, I use 4 phototransistors to create a small photo-piano. when light is blocked each phototransistor would emit a tone through the speaker. An LED turns on in each action to have a better visualization.

Process

For this assignment, I want to create a music box inspired by work inLab 5: Tone Output Using An Arduino -A Musical Instrument. Instead of using pressure sensors, I decided to use 4 phototransistors. Although the Lab is already coded for this exercise, I decided to have my own approach to the coding process. This made my code less efficient but helps me to internalize and understand what it is happening little by little.

Building the circuit

Phototransistor Circuit from learn.parallax.com

At first, I started looking at the logic of a phototransistors circuit. I found an example of this using this diagram: How the Phototransistor Circuit Works from learn.parallax.com.

To be able to use easily a 5 volt power source, I used a Mega Arduino.

After having the analog reading from the phototransistor, I continued to add an LED and a speaker that it is triggered when the threshold of the phototransistor gets it. Although I basically reproduce the other three series of phototransistors and LEDs, I encounter different problems reading the Phototransistor and LEDs. I had to go back a few times to the circuit and code to understand where was the problem.

This diagram shows an example of the circuit with 1 LED, 1 phototransistor and the speaker.

Iterations

At the beginning of the process, I was aspiring to have a polyphonic piano. I didn’t figure out how to do that at a beginner's level so I decided to work in a monophonic little piano. Also, I try to use mapping to have more variations of note per phototransistor. For this iteration, the user has to use the variation light to trigger different a range of sounds. Although I accomplish this variation, I went back to the version that I have now, because I want to trigger the sounds with the shadows (not light) and also I wasn't interested in the sounds made with the mapping.

Problems
I tried to make a polyphonic instrument but I wasn't able to accomplish that. I think that make simple polyphonic instruments in Arduino is too complicated that the level that I am now. For now, to be able to complete this interaction with a polyphonic outcome, I would need more speakers connected to the Arduino.

Future work
Improve the code as shown in the A Musical Instrument Lab: using just a for loop and the pitches.h file.

Video

--

--

Themis García
Physical Computing — ITP

Product UX Designer, Accessibility Researcher, Artist | PR-born & raised | She, Her, Ella| themisgarcia.com