Pages: [1]   Go Down
Author Topic: play sound files with arduino  (Read 884 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, I have just bought an Arduino board, so I'm just starting to find things out.

I have made a circuit in which I can measure different voltages. According to these different voltages I would like a specific sound file to be played, whenever the correct voltage is measured. (eg.  if voltage = x then play sound file 1, if voltage = y then play sound file 2, etc).
Do I need to interface with another program (like Flash, Max MSP) to be able to do this? Or can I do it in the Arduino environment?

Thanks!
Logged

berlin
Offline Offline
Sr. Member
****
Karma: 0
Posts: 293
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi,

if you want to play a sound file like an mp3 you need to interface with another program.
arduino can't play soundfiles on its own. i would suggest having a look into the flash examples. also use google to finde more examples.

you can still, create simple sounds using pulsed output and attaching a speaker to your arduino board. these sounds are rather beeps than voices.


hope that helped,
kuk_
Logged

malmö / berlin
Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
fhp>--vs--<k3
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


hej,

if you want to have a more or less hardware solution you could go for a industrie mp3 player,  which you can controll true the tx at the arduino (printbyte, etc). there is a guy in stockholm salling this stuff (jesper hansen, yampp), but i guess you could find this things also some where else, ...

if you want to i could send you a tutorial by Marcus Hannerstig (from k3).

regards
tomek
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks for the responses!
a hardware mp3 player is not really what i'm looking for, so i guess i'll have to try to find a solution in flash. does anyone have any ideas about where i can find a forum with flash code examples? i'm really not into this kind of programming..

thanks!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 37
shrz
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
if you want to i could send you a tutorial by Marcus Hannerstig (from k3).
 
regards
tomek

hello,
im very interrested in that.
could i read it as well?

chers
woo
Logged

Montréal, Québec, Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Alexandre Quessy
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Use Pure Data.

It is free and very easy. Use SimpleMessageSystem with readansyf~ or something.

Logged

Alexandre Quessy

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi , i have tried to write a program in processing that reads the analog input values from the arduino (I have used the Sonia library in processing for sound playing). Something is wrong, and I don't understand what.

***Arduino code:***


#include <SimpleMessageSystem.h>
  int b;
  int c;
void setup()
{
  Serial.begin(9600);
  
}

void loop()
{
  b = analogRead(1)
  if (b>10){
    if (b<150){
      c=1;
    }else if (b<300){
      c=2;
    }else if (b<450){
      c=3;
    }else if (b<600){
      c=4;
    }else if (b<750){
      c=5;
    }else{
      c=6;
    }
    serialWrite('A');
    serialWrite(c);
    serialWrite('B');
  }

}

void readpins(){
       b = analogRead(1);
}

  


***Processing code:***


import pitaru.sonia_v2_9.*;
import processing.serial.*;

Serial port;
String portname = "tty.usbserial-151";  
int baudrate = 9600;
int value, valueOld;
Sample sound1, sound2, sound3, sound4, sound5, sound6;
String buf="";
  
void setup() {
  Sonia.start(this);
  size(800,600);
  port = new Serial(this, portname, baudrate);
  println(port);
  fill(50);
  noStroke();
  framerate(110);
  sound1=new Sample("geluid1.wav");
  sound2=new Sample("geluid2.wav");
  sound3=new Sample("geluid3.wav");
  sound4=new Sample("geluid4.wav");
  sound5=new Sample("geluid5.wav");
  sound6=new Sample("geluid6.wav");
  valueOld = 0;
}
void serialEvent(int serial){
  // if serial event is not a line break
  if(serial!='A') {        
    // add event to buffer
    if (serial>=0){
      buf += char(serial);
    }          
  }
  else {  
  value = (buf); // we inverse the value by subtracting it from the maximum    //}
    buf="";

  }
  // println("LDR: "+value1);

}

void draw(){
  if (value!=valueOld){
      valueOld = value;
    if (value==1){
      sound1.play();
     }
    if (value==2){
      sound2.play();
    }
    if (value==3){
      sound3.play();
    }
    if (value==4){
      sound4.play();
    }
    if (value==5){
      sound5.play();
    }
    if (value==6){
       sound6.play();
    }
  }
}


I hope someone can help me out! thanks a lot!
Logged

California
Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Do I need to interface with another program (like Flash, Max MSP) to be able to do this? Or can I do it in the Arduino environment?
Here's an interesting site for code that plays sound on a PIC. This could probably be modified for use in the Arduino.
Logged

Pages: [1]   Go Up
Jump to: