Ting!

Transformez votre plante verte en xylophone !
Des capteurs piezo, sensibles aux chocs, sont fixés sur les feuilles d’une plante en pot. Lorsque l’utilisateur les frotte ou les heurte, le signal déclenche une note d’une hauteur différente. Ce son peut provenir d’un programme Processing (bibliothèque Minim), d’un piezo utilisé en buzzer, d’un haut parleur 8 ohm branché à Arduino…
Application: application industrielle (détection de vibration), création de contrôleurs musicaux…

Materiel: des capteurs piezo.

Une variante peut être envisagée avec cette propriété: http://arduino.cc/playground/Main/CapacitiveSensor?from=Main.CapSense

 

Sébastien Coget & Vigouroux Orianne

 

 

Schéma

Schéma PiezoBoom

Webographie

Code

Arduino

// these constants won’t change:
const int knockSensor1 = A0; // the piezo is connected to analog pin 0
const int knockSensor2 = A1; // the piezo is connected to analog pin 1
const int knockSensor3 = A2; // the piezo is connected to analog pin 2
const int knockSensor4 = A3; // the piezo is connected to analog pin 3
const int threshold = 1000;  // threshold value to decide when the detected sound is a knock or not
// these variables will change:
int sensorReading1 = 0;      // variable to store the value read from the sensor pin 1
int sensorReading2 = 0;      // variable to store the value read from the sensor pin 1
int sensorReading3 = 0;      // variable to store the value read from the sensor pin 1
int sensorReading4 = 0;      // variable to store the value read from the sensor pin 1

void setup() {
Serial.begin(9600);       // use the serial port
//playPart(melody1,noteLength1,8);
}

void loop() {
// read the sensor and store it in the variable sensorReading:
sensorReading1 = analogRead(knockSensor1);
sensorReading2 = analogRead(knockSensor2);
sensorReading3 = analogRead(knockSensor3);
sensorReading4 = analogRead(knockSensor4);

// if the sensor 1 reading is greater than the threshold:
if (sensorReading1 >= threshold) {
Serial.println(« 1″);
delay(1000);
}

// if the sensor 2 reading is greater than the threshold:
if (sensorReading2 >= threshold) {
Serial.println(« 2″);
delay(1000);

}

// if the sensor 3 reading is greater than the threshold:
if (sensorReading3 >= threshold) {
Serial.println(« 3″);
delay(1000);
}

// if the sensor 4 reading is greater than the threshold:
if (sensorReading4 >= threshold) {
Serial.println(« 4″);
delay(1000);
}

// delay to avoid overloading the serial port buffer
}

Processing

import cc.arduino.*;

import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;

import processing.serial.*;
Serial myPort; // On créé une instance de la classe Serial
short LF = 10; // « Fin de ligne »

int switchValue; // Une variable pour stocker la valeur du switch
int piezoVal; // Une variable pour stocker la valeur du potentiomètre

Minim minim;
AudioSample sound1;
AudioSample sound2;
AudioSample sound3;
AudioSample sound4;

int threshold = 900;  // threshold value to decide when the detected sound is a knock or not

// these variables will change:
int sensorReading1 = 0;      // variable to store the value read from the sensor pin 1
int sensorReading2 = 0;      // variable to store the value read from the sensor pin 1
int sensorReading3 = 0;      // variable to store the value read from the sensor pin 1
int sensorReading4 = 0;      // variable to store the value read from the sensor pin 1

void setup() {
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600);
//Serial.begin(9600);       // use the serial port
size(512, 200);
minim = new Minim(this);

// load BD.wav from the data folder
sound1 = minim.loadSample( « sound1.mp3″,512);
sound2 = minim.loadSample( « sound2.mp3″,512);
sound3 = minim.loadSample( « sound3.mp3″,512);
sound4 = minim.loadSample( « sound4.mp3″,512);

// On initialise la communication série, à la même vitesse qu’Arduino
//playPart(melody1,noteLength1,8);
}

void serialEvent(Serial p){
String message = myPort.readStringUntil(LF); // On lit le message reçu, jusqu’au saut de ligne
if (message != null)
{
print(message);

//Message reçu du switch
if (message.charAt(0) == ‘1’)
{
sound1.trigger();

}
if (message.charAt(0) == ‘2’)
{
sound2.trigger();
}
if (message.charAt(0) == ‘3’)
{
sound3.trigger();
}
if (message.charAt(0) == ‘4’)
{
sound4.trigger();
}
}
}

void draw() {
background(0);
}

void stop(){
// always close Minim audio classes when you are done with them
sound1.close();
sound2.close();
sound3.close();
sound4.close();
minim.stop();

super.stop();
}