Help with creating a more refined sound localizing rover

I'm working on a small rover, which has arduino uno(although i have other micro-controller that can be used). I have 2 max4466 microphone sensors installed at the front, one at left and one at right. In brief, the rover navigates to a nearest and largest sound source(is it correct)? by constantly checking for the analog values by the microphone. for example, if the left microphone gives a higher value than the right one, the rover turns a bit to the left.
This method, however, has flaws as i have observed-

  1. the rover takes too much time
  2. constantly checking and changing directions causes the motors to be jittery.
  3. it can't really distinguish whether the sound source is at the back or front( I have 2 extra microphones and i wonder whether adding them to the back can help in this)
    pls help. it will be appreciated.

Hi,
How about you post your code and a schematic.

Can you post some images of your project?
So we can see your component layout.

Post link to spec/data of the microphone modules.

Please do this in a new post, do not go back and add it to your original post.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

How should the microphone ignore sounds that the rover makes, and respond only to external sounds?

Please add engineering facts like code and a hand drawn schematics. Data for motors and drivers might be interesting.

The code :

int mic1 = A2;
int mic2 = A1;
int motor1= 2;
int motor2= 3;
int motor3= 4;
int motor4= 5;
int baseline = 337;
int amp1=0;
int amp2=0;
int difference=0;
int enA = 9;
int enB = 10;
int start;
int end;
const int echoPin= 7;
const int trigPin= 6;
long duration;
int distance;
void setup(){
  Serial.begin(9600);
  pinMode(motor1, OUTPUT);
  pinMode(motor2, OUTPUT);
  pinMode(motor3, OUTPUT);
  pinMode(motor4, OUTPUT);
  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  
}
void loop(){
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance = duration * 0.034 / 2;
  start=0;
  start= millis();
  end = start;
  int reading1 = analogRead(mic1);
  amp1= abs(reading1-baseline);//determine the peak
  int reading2 = analogRead(mic2);
  amp2= abs(reading2-baseline);//determine the peak
  difference= amp1-amp2;//peak intensity difference
  
  Serial.print("mic1: ");
  Serial.print(amp1);
  Serial.print(" mic2: ");
  Serial.print(amp2);
  Serial.print(" difference: ");
  Serial.print(difference); 
  Serial.print(" distance:");
  Serial.print(distance); 
  
  Serial.print("\n");
    if(difference>9 && amp1+amp2>250){//steers right based on the sound
      analogWrite(enA,90);
  analogWrite(enB,90);
      roboright();

      
    }
    else if(difference<-9 && amp1+amp2>250){//steers left based on the sound
      analogWrite(enA,90);
  analogWrite(enB,90);
      roboleft();

      
    }// jatin sachdev
    else if(difference>=-5 && difference<=5 && amp1+amp2>250 ){// drives towards the source of the sound
    //  while(start-end<0.5){
      analogWrite(enA,180);
  analogWrite(enB,180);
      roboforward(); //}
      /*stop();
      drivetosource();*/
      
  
    }
    if(distance<4){// makes the car recognise when it has reached the sound of source
      stop();
    }
    
 
 
}
/*void drivetosource(){
  analogWrite(enA, 100);
  analogWrite(enB, 100);
  while (amp1<335 || amp2<335){
   if(amp1<337 || amp2<337 && difference<5 && difference>-5 && amp1+amp2>300){
   roboforward();}  
   else if(difference>5){
    roboright();
  }
   else if(difference<-5 ){
    roboleft(); 
  
  }
  
  else if(amp1>335 && amp2>335){
    stop();
  }}
}*/
void roboright(){
  digitalWrite(motor1,LOW);
  digitalWrite(motor2,HIGH);
  digitalWrite(motor3,LOW);
  digitalWrite(motor4,HIGH );
  
}
void roboleft(){
  digitalWrite(motor1,HIGH);
  digitalWrite(motor2,LOW);
  digitalWrite(motor3,HIGH);
  digitalWrite(motor4,LOW);
}
void stop(){
  digitalWrite(motor1,LOW);
  digitalWrite(motor2,LOW);
  digitalWrite(motor3,LOW);
  digitalWrite(motor4,LOW);
}
void roboforward(){
  digitalWrite(motor1,LOW);
  digitalWrite(motor2,HIGH);
  digitalWrite(motor3,HIGH);
  digitalWrite(motor4,LOW);
  
}
void robobackward(){
  digitalWrite(motor1,HIGH);
  digitalWrite(motor2,LOW);
  digitalWrite(motor3,LOW);
  digitalWrite(motor4,HIGH);
}
void locatesource(){
  //do nothing
}

p.s the commented out code are the different variations i was trying
I have infact made a prototype tutorial for it on arduino project hub, also, witht the diagram, the details of microphones etc at this link
https://projecthub.arduino.cc/arunav1/sound-tracking-rover-13f9b6
And jremington, i have the microphones pointing towards the front of the rover, and i use a speaker emitting a fixed frequency(440-470 hz)as a sound source in my case , and it tracks to it. I m sure that the motor noise is neglible compared to it, or may be is it?

infact the link on the project hub is also the exact details for my rover.There is also the video of a run of the rover, which will be helpful for your reference.

Hi,
That is not the complete code, where are the first 11 lines in your code that are in the hub code.

Tom.. :smiley: :+1: :coffee: :australia:

oh im sorry, my bad, i did not copy the whole code. really sorry

I have edited it now

I just saw your old post about phase difference. Is it possible with the electronic i currently have ? and is it suitable for this rover?

It would be a good idea to carefully test that.

u can also see the vid in the tutorial as to what i mean

ANY UPDATE on the problem?

Pls update as soon as possible

any update?

That calls for more time then I'm prepared to spend. Please extract the requested facts and post them here. Don't expect helpers to go on a safari.

2 Likes

ok
microphones- max4466 microphone(adafruit clone,works same, with adjustable gain)
motor- hobby 12 v dc motors(geared)
motor driver- L298n dual bridge motor driver
power cell- LIPO 9v
schematic- motor wiring to l298n:


Video of a run of the rover :https://youtu.be/IDtmLwNg0hc
L298n pairing with uno:
L298N | Arduino Uno (digital)
IN1 -> 2
IN2 -> 3
IN3 -> 4
IN4 -> 5
max4466- vcc of both connected to a single pin on arduino, gnd of each connected to gnd of arduino, and output to a0, a1 respectively.
microphone image:

This is all the info, plus the code i sent earlier in a post

I did not mean it...

Thanks. Know that the sound from the spekar bounces back from walls and other hard material.
I guess You're indoors. What about trying it outdoors with a good distance to sound reflecting objects?
One strategy might be stopping all motors, make good sound readings and drive for a longer time, 5, 10 seconds. Then stop, check sound direction, go..

I do not see any comments that you have balanced the gain of both devices so they give identical output for a single sound right in front of your rover.