Volume Control using arduino

Hey everyone! :slight_smile:

I'm relatively new to arduino. Im creating an installation that will have sound. I'm placing "pin-wheels" on site, and i'm hoping to use the rpm to control the volume of the sound? Sort of creating a blindscape which represents the wind through sound :slight_smile:

Does anyone have any idea of how I could do this? I've been advised to use Max MSP to read the data then run it through Max 5 runtime, then scale the values, then send it to the sound volume...but the part i'm struggling with THE MOST (apart for using Max MSP in general! :P) is how to send the data back to the arduino to then control the volume on the speakers?

Any help will be very much appreciated :slight_smile:

Thanks -

here's what I'd do :

1 - use MaxMSP to control the volume of the audio flux (i.e. the audio is generated in the PC...)
2 - use the Arduino to send the rpm measurement over the Serial Line to MaxMSP
3 - Adjust the volume inside Max

other solution, i'm less fond of :

1 - use the Arduino to measure the RPM
2 - use a digital potentiometer over serial or puls command to adjust the volume at the input of an amplifier

Thanks ! :slight_smile:

I'm actually wanting the value of the rpm to CONSTANTLY change the volume of the sound. Is there a way I can do this?
Would it be easier to attempt to do this using firefly?

Cheers -

You could use one of the Arduino's PWM outputs, filter it using a low pass and then using a MOSFET draining to ground (with a resistor before it in the path) vary the volume. I don't know much of the implementation details not having used transistors much but it feels like the simplest way.

I'm actually wanting the value of the rpm to CONSTANTLY change the volume of the sound.

So why would not any of the previous solutions do that?

They show one iteration of a loop that you repeat constantly.

Grumpy_Mike:

I'm actually wanting the value of the rpm to CONSTANTLY change the volume of the sound.

So why would not any of the previous solutions do that?

because the volume is not meant to be constantly playing in a loop - its meant to be changing real time! not sure if im being very clear of what i'm trying to do! :stuck_out_tongue:

So I made an optical tachometer to read the rpm and hooked that up to the speakers.

This is the code I am using - is there anything wrong with it?

int ledPin = 13; // IR LED connected to digital pin 13
int statusPin = 12; // LED connected to digital pin 12

volatile byte rpmcount;
volatile int status;

unsigned int rpm;

unsigned long timeold;

int bikePlaying = 0;

byte volume = 255;

void setup()
{
Serial.begin(9600);
attachInterrupt(0, rpm_fun, RISING);
Serial.write('v'); //Serial message for volume
Serial.write(volume); //Set volume at lowest value

rpmcount = 0;
rpm = 0;
timeold = 0;
}

void loop()
{
if (rpmcount >= 1) {
//Update RPM every 1 count, increase this for better RPM resolution,
//decrease for faster update

rpm = 30*1000/(millis() - timeold)*rpmcount;
timeold = millis();
rpmcount = 0;
Serial.println(rpm,DEC);

if((rpm >= 80) && (bikePlaying == 0)){ //if a certain RPM is reached
Serial.write('t'); //Play Track 2 stored on MP3 Trigger
Serial.write(2);

bikePlaying = 1;

while (volume != 1) {
fadeIn(); //Fade volume in from min to max.
}

delay(3000);
}

if ((rpm <= 40) && (bikePlaying == 1)) { //If RPM falls below 40 and MP3 was playing

while (volume < 255) {
fadeOut(); //Fade out,
}

if (volume = 255) { //Then Stop.

Serial.write('O'); //Serial message for "stop"
bikePlaying = 0; //playing is off....
delay(3000);

}
}
}
}

void rpm_fun()
{
rpmcount++;
//Each rotation, this interrupt function is run twice
}

void fadeOut() {
volume += (240/100);
delay(40);
Serial.write('v');
Serial.write(volume);
}

void fadeIn() {
volume -= (240/100);
delay(40);
Serial.write('v');
Serial.write(volume);
}

At a quick glance, you're using = instead of == in one of your if statements.

Also, go learn what a loop is.

because the volume is not meant to be constantly playing in a loop - its meant to be changing real time! not sure if im being very clear of what i'm trying to do

You are not being clear at all. When we talk of a loop in computing it means something that is done over and over. So the control of the audio is done over and over each time with the current input value. This IS continuous control.

I think you are confusing a loop in a computer program with an audio loop, those keeps on repeating the same sound with no change from one iteration of the loop to the next. A computer loop is the only way to get continuous control.

If you want people to look at your code on this forum then go back and modify that post. Select just the code part and hit the # icon, then save.