Friday, February 02, 2007

microphone setup on breadboard


reference : Physical Computing - Dan O'Sullivan and Tom Igoe
Sound Input on a Microcontroller (p.356)
audio amplifier : LM386
capacitor : 220 microparads, 10 microparads, 4.7 microparads
resistor : 1kohm, 10kohm, 100kohm

microphone Arduiono code
int microPhone = 0;
int AmpVar = 0;
int micValue =0;

void setup() {
Serial.begin(9600);
}

void loop() {
micVal = analogRead(microPhone);
if (micVal>=512){
AmpVar = micVal-512;
}
else {
AmpVar = 512-micVal;
}
micValue = AmpVar; // read the analog input
//Serial.println(AmpVar);
resetVal = digitalRead(resetSwitch);

if (micValue >= THRESHOLD) { // check if the input is HIGH (button released)
micCurrentState = 1;
}
else {
micCurrentState = 0;
}
//if(micCurrentState != micPreviousState){
if(micCurrentState == 1){
micCounter = micCounter + 1;
//Serial.println("micCounter = ");
//Serial.println(micCounter);
}
//}
//micPreviousState = micCurrentState;

if (micCounter > 0) {
digitalWrite(candleLEDs, LOW);
delay(100);
}

}

0 Comments:

Post a Comment

<< Home