I am doing a project in which I take audio input from a microphone through an Arduino and transfer it to another through two HC 05 Bluetooth modules connected in master-slave mode.
Even if I reduce the noise picked by the microphone, the noise being included from Bluetooth transfer and Arduinos are interfering so I can't get an acceptable waveform similar to the one I send from the other end.
I am using a baud rate of 38400 for transfer and serial plotter to plot the waveform. What should I do to reduce the noise?
My next idea is to sample the data in parts, store the average value and then transfer it to plot in serial plotter in the receiving end.
Transmitting arduino code
#define MIC A0
static int sig=0;
void setup() {
// put your setup code here, to run once:
Serial.begin(38400);
}
void loop() {
// put your main code here, to run repeatedly:
sig= analogRead(MIC);
Serial.write(sig);
}
Receiving Arduino code
static int sig=0;
void setup() {
// put your setup code here, to run once:
Serial.begin(38400);
}
void loop() {
// put your main code here, to run repeatedly:
sig=Serial.read();
Serial.println(sig);
}
ElectronicsGeek:
What should I do to reduce the noise?
Possibly use a bluetooth with a different protocol, or do whatever you want to do with the signal in the transmitting Arduino, and then sent plain vanilla digital data to the second.
Please read the how to use... notes and post your code in the proper manner.
ElectronicsGeek:
Are you referring to the serial.write() and serial.read() commands? So the Bluetooth will transfer the reading regardless of them?
On the receiver end, you have:
void loop() {
// put your main code here, to run repeatedly:
sig=Serial.read();
Serial.println(sig);
}
which will read data, regardless of whether or not there is anything to read, from the Serial instance, and immediately send it back.
Why is it necessary to tell the sender what you got? It KNOWS what it sent. Why are you sending three times as much data (or more) as you got?
If the Serial.println() is NOT intended for the PC, why is it there?
What IS the Serial.println() statement there for? Where IS it supposed to send the data?
Getting "audio" data from a microphone, using analogRead() is NOT going to result in something that will sound remotely recognizable when you try to convert it back to something you can hear.
which will read data, regardless of whether or not there is anything to read, from the Serial instance, and immediately send it back.
2)Why is it necessary to tell the sender what you got? It KNOWS what it sent. Why are you sending three times as much data (or more) as you got?
If the Serial.println() is NOT intended for the PC, why is it there?
What IS the Serial.println() statement there for? Where IS it supposed to send the data?
Getting "audio" data from a microphone, using analogRead() is NOT going to result in something that will sound remotely recognizable when you try to convert it back to something you can hear.
I saw an example of master slave HC-05 modules, where Serial.read() and Serial.write() were used to transfer data. Is it wrong to used this? How else am I supposed to transfer data?
In my first try I used while(serial.available()>0) but it gave me only the positive part of the signal.
Since the transfer baud rate of the HC05 is 38400 so I used that. It gave better result than 9600. Do you suggest I change it back to 9600?
3)Serial.println is for the serial plotter.
I realised that and looked for any other function or library but could not find so I stocked to this. Is there any function that lets me get the 'audio' input?
I would also add the fact that I gave the mic a sine wave from an Google play store application and gave a sinosodial waveform as input at 480Hz and got an acceptable sinosodial plot in serial plotter. (Of course without using the Bluetooth, because it gave me too much noise) But it only gave a waveform at 480-488Hz, which I understand is a high frequency.
I saw an example of master slave HC-05 modules, where Serial.read() and Serial.write() were used to transfer data. Is it wrong to used this?
No. But it is pointless to send back what you received, unless the point is for the sender to do something if what you got was not what was sent.
What it looks like is that you are using the Serial Monitor app to debug your code. That will interfere with what you really want to be sending and receiving.
In my first try I used while(serial.available()>0) but it gave me only the positive part of the signal.
I have no idea what "the positive part of the signal means". You can only (safely) input positive voltages into the Arduino.
Since the transfer baud rate of the HC05 is 38400 so I used that. It gave better result than 9600. Do you suggest I change it back to 9600?
No. I don't think it makes sense to, at any speed, send three (or more) bytes for every one you receive. YMMV.
3)Serial.println is for the serial plotter.
Which is an app that runs on the PC, so you ARE trying to use Serial to talk to the PC at the same time you use it to talk to the bluetooth device. Doomed be you.
Is there any function that lets me get the 'audio' input?