• If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Stop wasting time looking for files and revisions. Connect your Gmail, DriveDropbox, and Slack accounts and in less than 2 minutes, Dokkio will automatically organize all your file attachments. Learn more and claim your free account.


Andrew Dupree - Lab 2

Page history last edited by Andrew Dupree 9 years, 3 months ago

Andrew J. Dupree

David Sirkin

EE47: Interactive Device Design


Lab 2: Frankenlight


1 A: The code must be modified to match the pinout of the Teensy. That is, the output pin must be changed from 13 to 11.


1 B: To change the rate of blinking, one should modify the amount of delay between the on state and off state. Decreasing the delay would cause the LED to blink faster, and vice versa.


1 C: One should add a resistor between the output pin and the LED (or somewhere else in the circuit) to limit the amount of current drawn to a safe level. I used a 220 Ω resistor to limit the current to some 22 mA.


2 A: The output pin must be changed from pin 11 to pin 9.


2 B:


void setup() {

// initialize the digitalpin as an output.

// Pin 13 has an LEDconnected on most Arduinoboards:

// Teensy 2.0 has theLED on pin 11

// Teensy++ 2.0 has theLED on pin 6

pinMode(9, OUTPUT);

pinMode(2, INPUT);



void loop() {

int reading = digitalRead(2);


if(reading == HIGH){

digitalWrite(9, LOW);

} else {

digitalWrite(9, HIGH);





3 A: Assuming the LED is still connected to pin9, nothing needs to be changed in thefade program.


3 B: To change the rate of fading, one should modify the fade Value incrementor. higher (absolute) value will cause the LED to fade in and out faster.


3 C: An LED, like most semiconductor devices has 3 zones in it's voltage/current curve - pre-turn on, linear, and saturation. Our input to the LED drives it throughout all of these regions, such that the devices seems to pause, suddenly turn on, and then cap out in brightness. To fix this, one would have to only drive the LED in linear mode (figure out the voltages which correspond to linear currents and only work in that range).




For the frankenlight, I decided to create a simple one-band visualizer. The output of the superbright LED corresponds to how loud the sound coming through the microphone (using a piezo transducer) is.


I tried to hack apart a few microphones, but without very good results. Cheap/old microphones seem to have a very low voltage output and not respond very linearly to audio.


The device works passing well but not terrifically. Really, a more high quality microphone is needed. The piezo has a lot of voltage output even at only ambient noise with small fluctuations for applied noise/vibrations.























Software corrections were made to account for the noisiness of the piezo and produce quality visualizations. Here is the code: 


int sensorPin = A0;

int ledPin = 9;

int sensorVal = 0;

int prevSensorVal = 0;


void setup() {

  // initialize the digital pin as an output.

  // Pin 13 has an LED connected on most Arduino boards:

  //   Teensy 2.0 has the LED on pin 11

  //   Teensy++ 2.0 has the LED on pin 6

  pinMode(ledPin, OUTPUT);




void loop() {


  int toLed = prevSensorVal;

  int margin = 4 ;

  int change = 100;


  sensorVal = analogRead(sensorPin)/4;


  if(sensorVal > prevSensorVal + margin){

    toLed = sensorVal + change;

  } else if(sensorVal < prevSensorVal - margin) {

    toLed = sensorVal - change;



  Serial.print("SenVal: ");



  Serial.print(" PrevSenVal: ");



  Serial.print(" toLed: ");



  prevSensorVal = sensorVal;


  analogWrite(ledPin, toLed);





I considered trying to implement a more complex visualizer using an array of LEDs and an FFT. While feasible, there is no FFT library for the Arduino/Atmega that does not require a fairly significant amount of setup and configuration. I also doubt the output would be high quality without a better microphone.


Finally, here is a schematic:

Comments (1)

Benjamin Tee said

at 11:40 pm on Jul 17, 2011

Great job! About 3C, i think you may have interpreted the question differently. What we are asking is that since the eye 'sees' intensity logarithmically, we need to have a kind of S-shape curve instead of a monotonically increasing intensity curve.

You don't have permission to comment on this page.