Hy Guys,
can anyone help in the coding of arduino microcontroller.
How to get the time delay angle between 2 microphone
Is it possible to get the signal from ordinary microphones or some amplifier or filter cicuit is necessary to get the signal to get the time difference?
The aim is to get the angle by getting time delay between 2 microphones and to display that angle on a LCD screen.
Just to be clear I did use an AI chatbot to generate this
Chat GPT
Here is what it replied:
Yes, it is possible to get the time delay angle between two microphones, but you will need to use a circuit to amplify and filter the signal from the microphones. The circuit will depend on the type of microphones you are using and the environment in which you are measuring the time delay.
Here's a general overview of the steps you can take to measure the time delay angle between two microphones using an Arduino Uno:
- Set up the circuit: You will need to connect two microphones to the Arduino Uno using an amplifier circuit. You can find a variety of circuits online that will work with different types of microphones. Make sure to use shielded cables to reduce interference.
- Measure the time delay: Use the microphones to capture audio signals and measure the time delay between the signals. You can use the
pulseIn()
function in Arduino to measure the duration of the pulse between the two signals. The time delay can be calculated as the difference between the pulse durations. - Calculate the angle: Once you have the time delay between the two signals, you can use some trigonometry to calculate the angle between the two microphones. The formula for calculating the angle is
angle = atan2(distance, time_delay)
wheredistance
is the distance between the two microphones andtime_delay
is the time delay between the two signals. - Display the angle: You can display the angle on an LCD screen connected to the Arduino Uno using the
LiquidCrystal
library.
Here's an example code for measuring the time delay angle between two microphones:
#include <LiquidCrystal.h>
const int mic1 = A0; // Microphone 1 input pin
const int mic2 = A1; // Microphone 2 input pin
const int amp_gain = 100; // Amplifier gain
const int lcd_rs = 2; // LCD RS pin
const int lcd_en = 3; // LCD enable pin
const int lcd_d4 = 4; // LCD data pin 4
const int lcd_d5 = 5; // LCD data pin 5
const int lcd_d6 = 6; // LCD data pin 6
const int lcd_d7 = 7; // LCD data pin 7
const int lcd_cols = 16; // LCD columns
const int lcd_rows = 2; // LCD rows
LiquidCrystal lcd(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7);
void setup() {
pinMode(mic1, INPUT);
pinMode(mic2, INPUT);
lcd.begin(lcd_cols, lcd_rows);
}
void loop() {
float distance = 10; // Distance between microphones in cm
float speed_of_sound = 343.2; // Speed of sound in m/s
int mic1_duration = pulseIn(mic1, HIGH);
int mic2_duration = pulseIn(mic2, HIGH);
float time_delay = abs(mic2_duration - mic1_duration) / 1000.0; // Time delay in ms
float angle = atan2(distance, time_delay / 1000.0) * 180.0 / PI; // Angle in degrees
lcd.clear();
lcd.print("Angle: ");
lcd.print(angle);
lcd.print(" deg");
delay(1000);
}
This code assumes that you have already set up the amplifier circuit for the microphones. The code uses the pulseIn()
function to measure the duration of the pulse between the two microphone signals and then calculates the time delay and angle between the microphones. The angle is displayed on an LCD screen connected to the Arduino Uno.
The response seems accurate, but I do not have the setup to test the code.
Hope this helps
Z
Please explain how that measures the difference in arrival times at the two microphones.
Hy Guys,
can anyone help in the coding of arduino microcontroller.
How to get the time delay angle between 2 microphone
Is it possible to get the signal from ordinary microphones or some amplifier or filter cicuit is necessary to get the signal to get the time difference?
The aim is to get the angle by getting time delay between 2 microphones and to display that angle on a LCD screen.
Can we get time difference using microcontroller counters or will need to use the external timers and counters.
Duplicate post
suggested search phrase:
sound localization arduino
I have merged your cross-posts @TAHAHASSAN.
Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.
Repeated cross-posting can result in a suspension from the forum.
In the future, please only create one topic for each distinct subject matter. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.
Thanks in advance for your cooperation.
We have to assume a lot of things with his post. Let's assume that the inputs go low when the signal is sent and go high when the microphones receive it. Otherwise your guess is as good as mine and his code is there to help him get started. Maybe after he tries it or comes up with some more ideas we can help him more.
Z
It depends on the nature of the sound. In the absence of reflections there are some sounds you can localise easily - such as a gunshot, or the sounds used by emergency vehicles (which are designed to let you do that)
In an acoustically reflective environment, even BATS (who are the REAL experts) can get confused.
Other sounds can be very hard to locate.
And got a useless result. What is the point?
Did anyone else want to help with the little information that was given? I'll answer that one ... NO. So without my cheating using Chat GTP this person wouldn't have anything to go on and would feel that we were all ignoring him and would just likely give up. But now look at all the support we are providing. Anyway, He's probably long gone, as he hasn't replied, and this post is now toxic in nature with the negative replies just because I admitted that I used a chatbot to process exactly what he gave us. lol. The experiment I tried is obviously a sore spot for all those who normally ignore these types of posts.
Z
The person still has nothing to go on, because your post contributed chatGPT misinformation.
Please answer the question in post #3.
I'm putting you on my permanent ignore list.
true, but he could ask a question, and I would likely respond with a better answer. I like wasting my time on nothing, too.
See post #8 for the answer to post #3
The correct answer to the question is: it can't.
Regardless of assumptions.
@DaveEvans
The simplest option I can think of involves using three HC-SR04 sensors. The first HC-SR04 (TX1) will stay intact, by removing the transmit speaker element on the second and third sensors (RX1, RX2) and placing the receive-only HC-SR04's (RX1, RX2) 10 cm apart from each other (per the code above) we can achieve the goal. Now all three sensors must be triggered simultaneously. When the Echo pin is activated, all three sensors will receive the signal from only the transmitting HC-SR04 . However, only the transmitting sensor with the transmitter element intact will measure the distance to the first object that reflects the signal. The second and third sensors will only register the time when they received the signal from the transmitting (TX1) HC-SR04. allowing the pulseIn() function to accurately measure the distance from TX1 to RX1 and RX2 by using the time sound takes to travel the distance.
Z
Yes the objective is likely to detect the impulsive noise like gunshots or clap of hands.
little noises can be ignored.
But to measure the time difference between 2 microphones is the key.
Can we directly get the signal from the mics or ADC or amplifiers will be necessary to first implify and then arduino can read the signal and can the arduino directly can measure time diff using its own timer
The usual approach is to digitize the two or more microphone waveforms simultaneously, using two or more ADCs, then perform cross-correlation calculations on the data streams to determine the time offset.
I tried getting the signals using the function generator with a certain time delay to be used as the input.
DIdnt connect with the microcontroller till yet.
Can the signals be directly used as an input with the microcontroller?
What signals?
What microcontroller?