Proximity Sensor experiment

Rather than wiring up the given diagrams for sensors from the book, I made a circuit using something I hadn’t used before. I made a simple circuit which plays tones based on a value measured from a proximity sensor.

Here is the video:

Here is the fritzing diagram:

proximity_mbk

Here is the code:

/* 
 * Proximity instrument
 * This is totally not anything like a theramin.
 * Author: Matthew Kellogg
 * Date: October 22, 2014
 */
int ledPin = 5;    // LED connected to digital pin 9

void setup()  { 
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
} 

static const int thresh = 160;

void loop()  {
  int val = analogRead(0);
  if (val > thresh){
    analogWrite(ledPin, map(val, 30, 950, 0, 255));
    tone(11, map(val, thresh, 950, 60, 4400));
  } else { 
    analogWrite(ledPin, 0);
    noTone(11);
  }
}


Comments are closed.