1

I am running this code on an Arduino. Using the Arduino, is there a way to pass the audio to my PC speakers?

//This imports the audio class
#include <PCM.h>

//This is the sound being played
const unsigned char sound1[] PROGMEM = {129, 127, 126, 127, 128, 128, 128, 12};

//constant variables
const int knockSensor = A0;
const int threshold1 = 10;

//This create a variable
int sensorReading = 0;

void setup() {
    Serial.begin(9600);
}

void loop() {
    sensorReading = analogRead(knockSensor);
    if (sensorReading >= threshold1) {
        Serial.println(threshold1);
        startPlayback(sound1, sizeof(sound1));
    }

    delay(200);
}
Kevin Workman
  • 41,537
  • 9
  • 68
  • 107
user1048682
  • 119
  • 4
  • 11

1 Answers1

2

Assuming that the Arduino board isn't physically connected to your PC, you should send the value Arduino is reading to PC, via Serial. A program running at the PC would get this values via seria port and could, then, use the Operating System to play that data as sound. If you're on Linux that would be really easy, by writting data to /dev/audio

Alex
  • 633
  • 1
  • 10
  • 29
  • Hi Alex, I'm out windows 7. The board is connected via serial port but how would I send audio through the serial port. – user1048682 Mar 08 '12 at 23:44
  • 1
    You can't send real audio signal via serial port. But you can send the data you're reading, so the computer software would be able to gather this data to create audio data that the computer could understand. Then you would be able to play that data. A simple solution would be to use this data to create a WAV file and then use the windows function SndPlaySound (Check the WIN32 API documentation) to play the file. – Alex Mar 09 '12 at 10:30