Description:
I created a table which helps me focus on my work and prevents me from playing with my phone. When I lift the phone off the table it starts buzing. I wanted to make it unique to the phone by using the phone weight, so that the system could not be fooled by any other device, but I was not able to get that data accurately, so instead I used the photo sensor.
Components:
1 Arduino
1 110 ohm resistor
1 Photo sensor
1 cardboard assembly
1 speaker
Code:
/* Theremin
* --------
*
*
* Created 24 October 2006
* copyleft 2006 Tod E. Kurt <tod@todbot.com
* http://todbot.com/
*/
int potPin = 0; // select the input pin for the potentiometer
int speakerPin = 7;
int val = 0;
void setup() {
pinMode(speakerPin, OUTPUT);
Serial.begin(9600);
Serial.println("ready");
}
void loop() {
digitalWrite(speakerPin, LOW);
val = analogRead(potPin); // read value from the sensor
val = val*2; // process the value a little
//val = val/2; // process the value a little
Serial.println(val);
if(val>500)
{
for( int i=0; i<50; i++ )// play it for 50 cycles
{
digitalWrite(speakerPin, HIGH);
delayMicroseconds(val);
digitalWrite(speakerPin, LOW);
delayMicroseconds(val);
}
}
else
{
digitalWrite(speakerPin, LOW);
}
}
- Login to post comments