HC-05 Bluetooth module problem with ADC and DAC

Hello,
We are currently trying to take in audio using a microphone. We are using Analogread to read the values and turn it into an int value(incomingAudio). We are then converting the int value to an 8 bit value using (incomingAudio+1)/4 - 1.We deal with the negative values by setting them to 0.We set the bluetooth to the pins using SoftwareSerial EEBlue(10, 11); // RX | TX.We are then sending it via the master bluetooth hc-05 module using EEBlue.write(incomingAudio);

The baud rate of the serial and bluetooth are different
Serial.begin(9600);
EEBlue.begin(38400);

For the slave bluetooth we read the data using int data = EEBlue.read();
We then output it to PORT D using PORTD = data;
We set port D using
for (byte i=0;i<8;i++){
pinMode(i,OUTPUT);//set digital pins 0-7 as outputs (DAC)
}

We do not hear the audio change when you touch the microphone or when any noise comes near it. We just hear a constant sound that does not change. Anybody that can please help?

Websites used:

Slave_12.ino (764 Bytes)

Master_11.ino (828 Bytes)

IMG_7165.PNG

IMG_7166.PNG

I know this is your first post, but you should learn how to use the code tags to post your code within your post. Like this:

Master Code:

#include <SoftwareSerial.h>
SoftwareSerial EEBlue(10, 11); // RX | TX
int incomingAudio = 0;
void setup()
{
  Serial.begin(9600);
  EEBlue.begin(38400);  //Baud Rate for command Mode. 
  Serial.println("Enter AT commands!");
}
 
void loop()
{
  incomingAudio = analogRead(A0);//read voltage at A0
  incomingAudio = (incomingAudio+1)/4 - 1;//scale from 10 bit (0-1023) to 8 bit (0-255)
  if (incomingAudio<0){//deal with negative numbers
    incomingAudio = 0;
  }
  EEBlue.write(incomingAudio);
  Serial.println(incomingAudio);
  delay(1000);
  // Keep reading from HC-05 and send to Arduino Serial Monitor
  
  /*if (EEBlue.available())
    Serial.write(EEBlue.read());

  // Keep reading from Arduino Serial Monitor and send to HC-05
  if (Serial.available())
    EEBlue.write(Serial.read());*/
}

Slave Code:

#include <SoftwareSerial.h>
SoftwareSerial EEBlue(10, 11); // RX | TX
int data = 0;

void setup()
{
  Serial.begin(9600);
  EEBlue.begin(38400);  //Baud Rate for command Mode. 
  //Serial.println("Enter AT commands!");

  //set digital pins 0-7 as outputs
   for (byte i=0;i<8;i++){
    pinMode(i,OUTPUT);//set digital pins 0-7 as outputs (DAC)
  }
}
 
void loop()
{
 while(EEBlue.available()){
  delay(10);
  data = EEBlue.read();
  Serial.println(data);
  PORTD = data;
 }
  // Keep reading from HC-05 and send to Arduino Serial Monitor
  
  /*if (EEBlue.available())
    Serial.write(EEBlue.read());

  // Keep reading from Arduino Serial Monitor and send to HC-05
  if (Serial.available())
    EEBlue.write(Serial.read());*/
}

KarenEscareno:
We deal with the negative values by setting them to 0.

The ADC will never output a negative value - why do you need to run this check? You could initialize as incomingAudio as “unsigned int” if you wanted to be sure there is no overflow, but with your maximum ADC output being 1023, I think overflow is never going to happen lol.

KarenEscareno:
We do not hear the audio change when you touch the microphone or when any noise comes near it. We just hear a constant sound that does not change. Anybody that can please help?

Can you verify that you have connectivity between the bluetooth modules? You may need to pair, bind, and link them first.

Now that I read your “master” code, I notice that you’re using a baud of 38400. That is the baud for AT-mode, which you DO NOT want to be in. Try 9600 or 115200.

Also, can you tell us how you configured the bluetooth modules and tell us what settings you're using?

Hi,
Can you tell us exactly what you are aiming to do?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

Please learn more about audio signals, ADC and DAC. Negative input voltages can damage the Arduino, did you take provisions? What's the amplitude of your audio signal?

Your current master sketch will sample the input signal at less than 1k samples/second, what does not allow to sample audio frequencies above 300Hz and without low pass filters results in aliasing - perhaps part of the noise produced by the DAC?