-1

I am doing mice behavioral training. I have an arduino-controlled box for that. The sounds are play using Mp3 player controlled b the arduino. However, the mp3 player is not good enough for my needs.

I need two clear sounds of 10 msec duration and freqiencies of 5000Hrz and 1000Hrz. (I prefer pure sine waves but can compromise on triangle or, for now, even square). The problem is that the mp3 is not fast enough and the volume is too low for 10 msec durations. When I tried to build gain circuit it became too noisy.

I tried to use the Tone function but it is again not good for 10 msec sounds. espacially in the jigj frequency/

I created the wavefiles in Matlab. The PC plays the file in the right volume with no nose. However, I don't know how to make the arduino play the files from the computer.

Is there a relative simple way to do it, without bying extra hardware? If now, is there ANY way of doing it?

or another option, Is there a way for the arduino to play files from a wave generator? (I have these in my lab)

Thanks!

2
  • what was wrong with tone()? for me it makes nice high beeps
    – Juraj
    Mar 21 '19 at 9:21
  • When I play 10000Hrz sound with 10msec duration I hear only click. I dont hear the sound. It is important since in the experiment I am conducting, The mice must hear and discriminate between the 5000Hrz, to 10000Hrz frequencies. The Mp3 was fine for 200 msec duration bur not for 10 msec. The computer is doing a very good job but I need the Arduino to control it..
    – user135172
    Mar 21 '19 at 9:30
1

Two options:

  1. Write software for the PC to react to serial commands sent by the Arduino, or
  2. Use a more powerful Arduino-like board with a DAC and do wavetable synthesis.

The Arduino Due and many of the other smaller ARM-based boards (like M0 boards) are a good candidate for option 2 because they are faster than a traditional Arduino and have a built-in DAC. However, a proper I2S CODEC chip attached to a powerful MCU would be the preferred method for high-quality playback.

Note that your amplification system is of critical importance. It's common for many cheap amplifiers to limit higher frequencies. You need an amplifier with a good flat response over and above the maximum frequency you want to reproduce. Just slapping together any old "gain" circuit is probably not going to be good enough. Most op-amp based solutions have a ratio (Gain Bandwidth Product) that reduces the bandwidth as the gain increases.

1
  • Yes, I might order a more powerful module.. Thanks!
    – user135172
    May 19 '19 at 7:39
1

This code will create a steady 20 KHz output. Adjust the duration to reflect the period of your frequencies.

byte triggerOut = 19;

unsigned long currentMicros;
unsigned long nextMicros;
unsigned long duration = 25UL; // flip every 50uS = 20KHz pulse
unsigned long elapsedMicros;

void setup() {
  pinMode (triggerOut, OUTPUT);
}
void loop() { 
  while (1) {
    currentMicros = micros();
    elapsedMicros = currentMicros - nextMicros;
    if (elapsedMicros >= duration) {
      nextMicros = nextMicros + duration;
      PINC = PINC | 0b00111111; // toggle D19 output by writing it input port.
    }
  }
}

Add some lines to start the output after a button push, and count the number of cycles to only output the time duration you want. 10,000 KHz = 0.1mS period, 10ms/0.1ms = 100 cycles.

Divide the 0 to 5V output down to 1V, and drive a computer self powered speaker to create the noise you want.

1
  • I will try that. Thanks!
    – user135172
    May 19 '19 at 7:39

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .