Go Down

Topic: play sound files with arduino (Read 1 time) previous topic - next topic

krrlijn

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!

kuuk

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_

tomek


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

krrlijn

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!

woo_oow

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

aalex

Use Pure Data.

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

Alexandre Quessy

krrlijn

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!

CasNet

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.

Go Up