Go Down

Topic: Sound sensor to servo (Read 1 time) previous topic - next topic

dicobraz

Hi all

This is my first post on here and first arduino encounter. I am as beginner as it gets!!!

With my project I am trying to achieve: read noise levels and convert them to servo motion.

At the moment I am at the first stage of building a sensor, i have an electret mic, with which i have built amplified circuit.
This is how it looks:



In arduino i get readings quite constant within 410-450
So i guess my amplifier isnt working so well

Any help would be appreciated
Thanks

spcomputing

Which OpAmp are you using?  I have a 6 month old that I needed a trigger for a Fisher Price with IR remote when she started up.  I have bread-boarded out an LM358N that works well.  I am guessing you have a LM386N...
http://www.spcomputing.com

dicobraz

I was going to have lm358, but when i went to maplin electronics shop, they havent had that in stock since 2011, so i got a ts358cd and tl072cn instead!

spcomputing

Try this sketch, it is sloppy but it might have some pieces that you can use.

Code: [Select]
// This sketch will send out a trigger signal for FP Baby Entertainment.
// this code is public domain, please enjoy!

int IRledPin =  11;    // LED connected to digital pin 11
const int ledPin =  13;      // the number of the LED pin
const int thresholdvalue=100;//The threshold to turn the led on
const int analogPin = 0;
// The setup() method runs once, when the sketch starts

void setup()   {               
  // initialize the IR digital pin as an output:
  pinMode(IRledPin, OUTPUT);     
  Serial.begin(9600);
}

void loop()                     
{
    int mn = 1024; // mn only decreases
    int mx = 0;    // mx only increases

    // Perform 10000 reads. Update mn and mx for each one.
    for (int i = 0; i < 10000; ++i) {
        int val = analogRead(analogPin);
        mn = min(mn, val);
        mx = max(mx, val);
    }
 
  int sensorValue = (mx-mn);
  if(sensorValue>thresholdvalue)
  SendCode();
  digitalWrite(ledPin,HIGH);//if the value read from A0 is larger than 400,then light the LED
  delay(250);
  digitalWrite(ledPin,LOW);
  Serial.println(sensorValue);
  Serial.print(millis());
  Serial.println();
}

// This procedure sends a 38KHz pulse to the IRledPin
// for a certain # of microseconds. We'll use this whenever we need to send codes
void pulseIR(long microsecs) {
  // we'll count down from the number of microseconds we are told to wait

  cli();  // this turns off any background interrupts

  while (microsecs > 0) {
    // 38 kHz is about 13 microseconds high and 13 microseconds low
   digitalWrite(IRledPin, HIGH);  // this takes about 3 microseconds to happen
   delayMicroseconds(10);         // hang out for 10 microseconds
   digitalWrite(IRledPin, LOW);   // this also takes about 3 microseconds
   delayMicroseconds(10);         // hang out for 10 microseconds

   // so 26 microseconds altogether
   microsecs -= 26;
  }

  sei();  // this turns them back on
}

void SendCode() {


  pulseIR(940);
  delayMicroseconds(900);
  pulseIR(940);
  delayMicroseconds(880);
  pulseIR(940);
  delayMicroseconds(880);
  pulseIR(940);

delay(10000);
// delay(1200000); // wait 20 minutes before commanding it again
}


Output is max-min and milliseconds
http://www.spcomputing.com

dicobraz

Thank you for sharing! I am going to have a go with this later today, will report back!

tkbyd

Always divide any such project... and questions arising (<^_^>) into it's parts...

In this case...

a) How to get a number inside the Arduino from a sound level
b) How to make a server go to a position, based on a number you have.

Go Up