Go Down

Topic: audio (Read 1 time) previous topic - next topic


Hi Everyone, I need help 

So far, I've got the motor to move a certain angle
when the LED comes on.
When the motor is triggered I want the audio file to play from the pc.
(i will be connecting pc speakers to the arduino).

Basically, I need help on how to do the following steps:-

1. The Arduino checks for a signal from the sensor. if there is a signal, it sends a signal through USB to my laptop.
2.  The program written in Processing checks for signals from the Arduino on my USB port. If there is a signal, it plays the file.

Can anyone help? ;(


Well for a start please delete your othe thread on the same topic, cross posting is a no no round here.
You need to supply more information, what sensor? How is it connected?
What sort of motor, I assume it is a servo but you don't say.
What code have you tried? Can you post it.



Please stop cross-posting. Copying and pasting the same question just annoys people. Your posts will be seen. They are likely to be ignored if you spam the board.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics


Sorry, I thought those threads I copied and pasted will be usefull for him as they describe most of what he is trying to do. I erased it.


I wasn't addressing my comment to you arduinoadrian. Useful links are always appreciated.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics


Oh Ok. Sorry. Will post again.

Check this out.

In these threads you will find answers to most of the same questions. They were discussed here recently.



Apr 17, 2012, 01:04 pm Last Edit: Apr 17, 2012, 01:05 pm by oddthumb Reason: 1
:D thanks everyone (and i have deleted the other posts-- sorry!)

i'm using a LDR to turn the LED on without light
and the LED will trigger the Servo Motor to a certain degree of angle.

since i cannot find much information with what i originally wanted to do with the sound,

i've decided to get a Waveshield and SD/MMC card to play the sound from the library as the motor moves.

Hopefully it will work.. and arrive in time! :)


Apr 18, 2012, 12:31 pm Last Edit: Apr 18, 2012, 12:33 pm by oddthumb Reason: 1
As I have not enough time to wait for the waveshield
I tried to find another way of playing the music file.

But im getting an error ;<

This is the code I used:-

#include <Servo.h>
import ddf.minim.*;
import processing.serial.*;

#define MOTOR 4 //motor is plugged in to pin 4
#define SENSOR 7 //button is plugged in to pin 7
#define LED 13

int trigger = 1;//if button's not pressed, trigger = 0, else trigger = 1

Minim minim;
AudioPlayer player;

Servo myservo;

void setup()//initializing

minim = new Minim(this);
player = minim.loadFile("filename.mp3",2048);

port = new Serial(this, Serial.list()[MOTOR],9600);



pinMode(LED , OUTPUT);
pinMode(SENSOR , INPUT);
//setting button(7) as an INPUT

int move = 0;//movement of the motor in degrees(angle)

void loop()
trigger = digitalRead(SENSOR);
//checks if the button is pressed or not

if(trigger == 0)//if the sensor detects darkness
{//move the motor

digitalWrite(LED , HIGH);

delay(2000);//wait for 2 seconds

//moves the motor 30 degrees 0 to 30
//move += 1 increments the value of move by 1
for(move = 0; move < 30; move += 1)
myservo.write(move);//move the motor by the given value

delay(4);//waits for 4ms
}//end of for


delay(1000); //wait for 1 sec

//this for loop moves back the position of the motor from 30 degrees to 0
//move -= 1 decrements value of move by 1
for(move = 30; move >= 0; move -= 1)

}//end of if
digitalWrite(LED , LOW);


void stop()




The error msg says, import does not name a type???
I'm not sure what im doing wrong :S


Apr 18, 2012, 12:47 pm Last Edit: Apr 18, 2012, 12:52 pm by dxw00d Reason: 1
You appear to be trying to compile a cross between Processing code and Arduino code in the Arduino IDE.

Minim is a library for Processing.
Servo.h is a library for Arduino.


Apr 18, 2012, 01:01 pm Last Edit: Apr 18, 2012, 01:11 pm by oddthumb Reason: 1
;( will i have to use something like Firmata to do this????????????
(sorry im new to all of this @@)


You could do. I've never used Firmata, so I don't know if it will help you.


will i have to use something like Firmata to do this?

No. Absolutely, positively, no.

Firmata puts your Arduino in the role of a slave, entirely driven by Processing or some other Firmata-aware application. That is most certainly not what you seem to be trying to do. You seem to want the Arduino to be the master, controlling Processing.
The art of getting good answers lies in asking good questions.


Seems to me  you are really beginning with this. I will try to help.

You need to have one sketch (program) for Arduino and another for your computer in Processing (you have chosen Processing it could be another language). Two different sketches that will work together to do what you want. Processing and Arduino IDE are very similar; but still 2 different things.

in Processing you need to have a void draw() function for it to run in a loop, otherwise blank screen and no program running. You need to study Processing here:

I don't know what you are doing; but seems like a good starter project that will help you learn many good things. In order to give you more specific advise you need to study some Processing on your own first and come up with some sketch for you to understand what it is all about. You will find help here.

Go Up