Arduino - Processing and triggering music files

Hi guys,

I have a project for my master’s in which I am making music out of plants.

the music samples are recorded before my final exhibition (they are not generated live). I made a table which on it there are four different plants. I want people to come, touch the plant and then the plant will use as a sensor and trigger the music that was composed for it.

I coded Arduino with Touch Sensitive library (I used this code) and now I want to connect it to Processing so every time you touch a wire its trigger am mp3 sound (4 wires = 4 music sounds = the music stops when you take your hands off the plant and starts when you put your hands again on the plant.

so, I found some videos about connecting Arduino to processing but all of them are talking about sensors and I need it to be for a wire. secondly, I am trying to find a could that triggers music (If > Then) and didn't find any.

I'm attaching the Arduino code, maybe it will help.

CapacitiveSensor_YM_GMAR.ino (1.1 KB)

Thanks a lot,

Y.

It might remove some of your problems if you did not have to use processing to play your music files.

You can buy very inexpensive MP3 player modules called "dfplayer mini" which connect directly to an Arduino. They take a micro SD card on which you can put your prerecorded music. The modules can drive a small mono speaker directly, and also have line-level stereo outputs if you need louder, better quality, stereo sound.

s-l400

You will get more help more quickly on this forum if you post your code following the instructions in the forum guide (sticky post at top of most forum sections). Many forum members read the forum on phones/tablets can can't easily open a .ino attachment.

The wire is your sensor.

What do you mean "find"?

As you said

So at that level of academic study you should be way beyond having to find code, you should be able to write it.

So post a diagram of your wire sensors attached to the Arduino.

Hi,

I never said my master was in computer science :slight_smile:

this is my diagram (without the speaker):

This is the code you were asked to post but didn't. We ask this because many menbers, myself included, use mobile devices and they can't read .ino files even though basically they are text. So you have to wait until some one is using a laptop before they can see the code.

/*
  Arduino Organ by pollux labs, 2020
  More projects and tutorials: https://polluxlabs.net
*/

// Import the CapacitiveSensor Library.
#include <CapacitiveSensor.h>

//Set sensor sensitivity
int sensitivity = 3000;

// Set the Send Pin & Receive Pin.
CapacitiveSensor   cs_2_4 = CapacitiveSensor(2, 4);
CapacitiveSensor   cs_2_5 = CapacitiveSensor(2, 5);
CapacitiveSensor   cs_2_6 = CapacitiveSensor(2, 6);
CapacitiveSensor   cs_2_7 = CapacitiveSensor(2, 7);
CapacitiveSensor   cs_2_8 = CapacitiveSensor(2, 8);

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

void loop()
{

  long sensor4 =  cs_2_4.capacitiveSensor(sensitivity);
  long sensor5 =  cs_2_5.capacitiveSensor(sensitivity);
  long sensor6 =  cs_2_6.capacitiveSensor(sensitivity);
  long sensor7 =  cs_2_7.capacitiveSensor(sensitivity);
  long sensor8 =  cs_2_8.capacitiveSensor(sensitivity);

  Serial.print(sensor4);
  Serial.print(",");
  Serial.print(sensor5);
  Serial.print(",");
  Serial.print(sensor6);
  Serial.print(",");
  Serial.print(sensor7);
  Serial.print(",");
  Serial.println(sensor8);

  delay(500);
}

You may want to read this before you proceed:-
how to get the best out of this forum

You never said anything, which is annoying. You don't just have to be doing a course in computer science, it could be electronic engineering, physics or even art. I am a retired University lecturer (Professor in U.S. speak) and that is what I would expect no matter what your core discipline.

Now what you need to do is to run this code and see what numbers you get from it. Then you can workout what is the best threshold value for each sensor. That is a value that above which you want to trigger the sound. Each sensor will then have its own trigger level. These readings will change depending on how damp the soil is.

So then you take that code and modify it so that you only print out the sensor's number when you see it above this threshold. Keeping things simply you can use just a repeating of statements for this, like this:-

if(sensor4 > threshold4) print(4);
if(sensor5> threshold5) print(5);
if(sensor6 > threshold6) print(6);
if(sensor7 > threshold7) print(7);
if(sensor8 > threshold8) print(8);

Of course you should define these threshold variables as long variable before the setup function.
Note this will look rubbish in the serial monitor because there is no gaps or anything so it is just a long string of numbers, but that is not important because you will be reading them in Processing. What you do there is just look at the single byte that arrives in the serial port, and, if that sample is not playing you start it off playing.

Have you got any processing code yet? If so please post it correctly.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.