Project tutorial
Jam 'n' Bread

Jam 'n' Bread

Jam ‘n’ Bread aims to bring people back to the dinner table and make mealtime a fun and social event again.

  • 1,393 views
  • 0 comments
  • 4 respects

Components and supplies

Wood (the quality up to you)
×1
5 Megaohm Resistor
×4
Aluminum Foil
×1
Audio Kit
×1
Speakers
×1
Ardgen mega
Arduino Mega 2560 & Genuino Mega 2560
×1
Piezo Drum Sensor
×1
09590 01
LED (generic)
×4

About this project

Description

Jam ‘n’ Bread aims to bring people back to the dinner table and make mealtime a fun and social event again. Studies show that traditional family-style dinners are becoming less common in American households, despite their many benefits for family relationships. Even households that participate in regular group dinners, such as student co-ops, require a precise synchronization in timing between individuals to make them happen.

Inspired by the shared (if perhaps ephemeral) sense of togetherness that musicians experience when playing music together, Jam ‘n’ Bread introduces touch-sensitive instrumental sounds and lighting to tableware in order to encourage people to “play with their food,” take a break from their busy day, and enjoy a meal together.

Brainstorming

Sketches

Design Decisions

  1. We decided to design our own plates using acrylic and plywood because we wanted our plates to appear in the same collection, but yet we wanted each plate to have their own unique style. Each plate has a unique engraving and instrument to encourage people to come together at the dining table.

  2. The aesthetic of the plate is modeled after the design of a record. The arcs mirror the visual symbol for vibration or music.

  3. We also purposely displayed the wires to show off the hardware embedded within the plate.

  4. The plates are not wireless to encourage everyone to eat together in order for the plates to function.

Kitchen Research

Research

We visited a co-op to research cooking with a large environment of people. We found that while cooking in large groups, there are always a few people that aren't doing anything. They're basically in the way. We made a basic vegetable stir fry while listening to music in the background. Afterwards, we ate together. Through this experience, we realized that music could be a large part of the kitchen and dining together is difficult especially with the schedules of busy students.

Speaker Code

jamnbread.ino
Speaker Code

Warning: Embedding code files within the project story has been deprecated. To edit this file or add more files, go to the "Software" tab. To remove this file from the story, click on it to trigger the context menu, then click the trash can button (this won't delete it from the "Software" tab).

/*

 Example: Control a WTV020-SD-16P module to play voices from an Arduino board

 */



#include <Wtv020sd16p.h>





#define DRUM_THRESHOLD 40

int resetPin = 2;  // The pin number of the reset pin.

int clockPin = 3;  // ThMe pin number of the clock pin.

int dataPin = 4;  // The Mpin number of the data spin.

int busyPin = 5;  // The pin number of the busy pin.



int piano1Pin = 31;

int piano2Pin = 33;

int piano3Pin = 35;

int piano4Pin = 37;





int piezo1 = A0;

int piezo2 = A1;

int piezo3 = A2;



boolean piano = false;

boolean guitar = false;

boolean drum = false;



boolean piano1Tap = false;

boolean piano2Tap = false;

boolean piano3Tap = false;

boolean piano4Tap = false;



int drum1Pin = 39;

int drum2Pin = 41;

int drum3Pin = 43;

int drum4Pin = 45;

boolean drum1Tap = false;

boolean drum2Tap = false;

boolean drum3Tap = false;

boolean drum4Tap = false;



int guitar1Pin = 47;

int guitar2Pin = 49;

int guitar3Pin = 51;

int guitar4Pin = 53;

boolean guitar1Tap = false;

boolean guitar2Tap = false;

boolean guitar3Tap = false;

boolean guitar4Tap = false;





/*

Create an instance of the Wtv020sd16p class.

 1st parameter: Reset pin number.

 2nd parameter: Clock pin number.

 3rd parameter: Data pin number.

 4th parameter: Busy pin number.

 */

Wtv020sd16p wtv020sd16p(resetPin,clockPin,dataPin,busyPin);



void setup() {

//  pinMode(piano1Pin, INPUT);

//  pinMode(piano2Pin, INPUT);

//  pinMode(piano3Pin, INPUT);

//  pinMode(piano4Pin, INPUT);

//  

//  pinMode(drum1Pin, INPUT);

//  pinMode(drum2Pin, INPUT);

//  pinMode(drum3Pin, INPUT);

//  pinMode(drum4Pin, INPUT);

//  

//  pinMode(guitar1Pin, INPUT);

//  pinMode(guitar2Pin, INPUT);

//  pinMode(guitar3Pin, INPUT);

//  pinMode(guitar4Pin, INPUT);



  pinMode(piezo1, INPUT);

  pinMode(piezo2, INPUT);

  pinMode(piezo3, INPUT);

  pinMode(guitar3Pin, INPUT);



  

  //Initializes the module.

  wtv020sd16p.reset();

  

  Serial.begin(9600);

}



void loop() {

//  int piano1 = digitalRead(piano1Pin);

//  int piano2 = digitalRead(piano2Pin);

//  int piano3 = digitalRead(piano3Pin);

//  int piano4 = digitalRead(piano4Pin);

//  

//  int drum1 = digitalRead(drum1Pin);

//  int drum2 = digitalRead(drum2Pin);

//  int drum3 = digitalRead(drum3Pin);

//  int drum4 = digitalRead(drum4Pin);

//  

//  int guitar1 = digitalRead(guitar1Pin);

//  int guitar2 = digitalRead(guitar2Pin);

//  int guitar3 = digitalRead(guitar3Pin);

//  int guitar4 = digitalRead(guitar4Pin);

//  

  //Serial.println("Running Main Loop");

  

  int drum1_sensor =analogRead(piezo1);

  int drum2_sensor = analogRead(piezo2);

  int drum3_sensor = analogRead(piezo3);

  

  

    //wtv020sd16p.asyncPlayVoice(1);

   //delay(5000);

  

//  if (drum1_sensor > DRUM_THRESHOLD) {

//    //Serial.println("In here");

//    if (!piano) {

//      piano = true;

//      int random_number = random(0, 2);

//      wtv020sd16p.asyncPlayVoice(random_number);

//    }

//  } else {

//    piano = false;

//  }

      

  

  if (drum2_sensor > DRUM_THRESHOLD ) {

    Serial.println("In here");

      int random_number = random(3, 6);

      wtv020sd16p.asyncPlayVoice(0);

      drum = true; 

      //delay(5000); 

      //last_played =

  } 

  

  

  

//   

//   

    Serial.println(drum2_sensor);

// //   Serial.println(drum1_sensor);

  

  

// if (piano1) {

//    if (!piano1Tap) {

//      wtv020sd16p.asyncPlayVoice(0);

//      piano1Tap = true;

//      return;

//    }

//  } else {

//    piano1Tap = false;

//  }

//  

//  if (piano2) {

//    if (!piano2Tap) {

//      wtv020sd16p.asyncPlayVoice(1);

//      piano2Tap = true;

//      return;

//    }

//  } else {

//    piano2Tap = false;

//  }

//  

//  if (piano3) {

//    if (!piano3Tap) {

//      wtv020sd16p.asyncPlayVoice(2);

//      piano3Tap = true;

//      return;

//    }

//  } else {

//    piano3Tap = false;

//  }

//  

//  if (piano4) {

//    if (!piano4Tap) {

//      wtv020sd16p.asyncPlayVoice(3);

//      piano4Tap = true;

//      return;

//    }

//  } else {

//    piano4Tap = false;

//  }

//  

//  if (drum1) {

//    if (!drum1Tap) {

//      wtv020sd16p.asyncPlayVoice(4);

//      drum1Tap = true;

//      return;

//    }

//  } else {

//    drum1Tap = false;

//  }

//  

//  if (drum2) {

//    if (!drum1Tap) {

//      wtv020sd16p.asyncPlayVoice(5);

//      drum1Tap = true;

//      return;

//    }

//  } else {

//    drum1Tap = false;

//  }

//  

//  if (drum3) {

//    if (!drum3Tap) {

//      wtv020sd16p.asyncPlayVoice(6);

//      drum3Tap = true;

//      return;

//    }

//  } else {

//    drum3Tap = false;

//  }

//  

//  if (drum4) {

//    if (!drum4Tap) {

//      wtv020sd16p.asyncPlayVoice(7);

//      drum4Tap = true;

//      return;

//    }

//  } else {

//    drum4Tap = false;

//  }

//  

//  if (guitar1) {

//    if (!guitar1Tap) {

//      wtv020sd16p.asyncPlayVoice(8);

//      guitar1Tap = true;

//      return;

//    }

//  } else {

//    guitar1Tap = false;

//  }

//  

//  if (guitar2) {

//    if (!guitar2Tap) {

//      wtv020sd16p.asyncPlayVoice(9);

//      guitar2Tap = true;

//      return;

//    }

//  } else {

//    guitar2Tap = false;

//  }

//  

//  if (guitar3) {

//    if (!guitar3Tap) {

//      wtv020sd16p.asyncPlayVoice(10);

//      guitar3Tap = true;

//      return;

//    }

//  } else {

//    guitar3Tap = false;

//  }

//

//  if (guitar4) {

//    if (!guitar4Tap) {

//      wtv020sd16p.asyncPlayVoice(11);

//      guitar4Tap = true;

//      return;

//    }

//  } else {

//    guitar4Tap = false;

//  }

}

Capacitor Sensor Code

sensorcode.ino
Capacitor Sensor Code

Warning: Embedding code files within the project story has been deprecated. To edit this file or add more files, go to the "Software" tab. To remove this file from the story, click on it to trigger the context menu, then click the trash can button (this won't delete it from the "Software" tab).

#include <CapacitiveSensor.h>

#define LED 10

#define LED2 11

#define LED3 12

#define LED4 13



#define PIEZO1 A0





#define TESTLED 12

#define CAP_THRESHOLD 300

#define DRUM_THRESHOLD 8



boolean pressed1 = false;

boolean pressed2 = false;

boolean pressed3 = false;

boolean pressed4 = false;





/*

 * CapitiveSense Library Demo Sketch

 * Paul Badger 2003

 * Uses a high value resistor e.g. 10M between send pin and receive pin

 * Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values.

 * Receive pin is the sensor pin - try different amounts of foil/metal on this pin

 */





CapacitiveSensor   cs_0_1 = CapacitiveSensor(2,3);        // 10M resistor between pins 0 & 1, pin 2 is sensor pin, add a wire and or foil if desired

CapacitiveSensor   cs_0_2 = CapacitiveSensor(4,5);        // 10M resistor between pins 0 & 2, pin 6 is sensor pin, add a wire and or foil

CapacitiveSensor   cs_0_3 = CapacitiveSensor(6,7);        // 10M resistor between pins 0 & 3, pin 3 is sensor pin, add a wire and or foil

CapacitiveSensor   cs_0_4 = CapacitiveSensor(8,9);        // 10M resistor between pins 4 & 10, pin 10 is sensor pin, add a wire and or foil



//Previous value for cap1

long previous1 = 0;

long previous2 = 0;

long previous3 = 0;

long previous4 = 0;



 

void setup()                    

{

   pinMode(LED,OUTPUT);

   pinMode(LED2, OUTPUT);

   pinMode(LED3,OUTPUT);

   pinMode(LED4, OUTPUT);

   pinMode(TESTLED, OUTPUT);

   

   pinMode(PIEZO1, INPUT);

   

   digitalWrite(TESTLED, HIGH);

   

   digitalWrite(LED, LOW);

   digitalWrite(LED2, LOW);

   digitalWrite(LED3, LOW);

   digitalWrite(LED4, LOW);

 

 

   cs_0_1.set_CS_AutocaL_Millis(0xFFFFFFFF);

   cs_0_2.set_CS_AutocaL_Millis(0xFFFFFFFF);

   cs_0_3.set_CS_AutocaL_Millis(0xFFFFFFFF);

   cs_0_4.set_CS_AutocaL_Millis(0xFFFFFFFF);    // turn off autocalibrate on channel 1 - just as an example

    Serial.begin(9600);

}



void turnOn(int led) {

  switch(led) {

    case 0:  {

       digitalWrite(LED, HIGH);

       break; 

    }

  

    case 1:  {

       digitalWrite(LED2, HIGH);

       break; 

    }

    

    case 2:  {

       digitalWrite(LED3, HIGH);

       break; 

    }

    

    case 3:  {

       digitalWrite(LED4, HIGH);

       break; 

    }

  }

  

  delay(100);

  cs_0_1.reset_CS_AutoCal();

  cs_0_2.reset_CS_AutoCal();

  cs_0_3.reset_CS_AutoCal();

  cs_0_4.reset_CS_AutoCal();

  

}



void loop()                    

{

  

    int drum = analogRead(PIEZO1);

    

    long start = millis();

    long total1 =  cs_0_1.capacitiveSensor(10);

    long total2 =  cs_0_2.capacitiveSensor(10);

    long total3 =  cs_0_3.capacitiveSensor(30);

    long total4 =  cs_0_4.capacitiveSensor(30);

 

    long maxi = 0;

    

    long diff1 = total1 - previous1;

    long diff2 = total2 - previous2;

    long diff3 = total3 - previous3;

    long diff4 = total4 - previous4;

 

    long difference[4] = {diff1,diff2,diff3,diff4};

   

    int max_index = 0;

    for (int i=0; i<4;i++){

      maxi = max(maxi,difference[i]);

      if (maxi == difference[i]) {

        max_index = i;        

      }

    }

    

    

  

    if (drum > DRUM_THRESHOLD) {

     if (maxi > CAP_THRESHOLD) {

        turnOn(max_index);

     //   Serial.println("max:" + String(maxi));   

      }  

    }

    digitalWrite(LED,LOW);

    digitalWrite(LED2,LOW);

    digitalWrite(LED3,LOW);

    digitalWrite(LED4,LOW);

 

    

    //Serial.print(millis() - start);        // check on performance in milliseconds

    //Serial.print("\t");                    // tab character for debug windown spacing

     

     if (diff1 > CAP_THRESHOLD) {

       

       Serial.println("Cap1:" + String(diff1));      // print sensor output 1

       Serial.print("\t");

     }

//    Serial.println("Cap2:" + String(diff2));                  // print sensor output 2

//    Serial.print("\t");

//    Serial.print(diff3);                // print sensor output 3

//    Serial.print("\t");

//    Serial.println(diff4);

//    Serial.println("max:" + String(maxi));

//    Serial.println("PIezo:" + String(drum));

     previous1 = total1;

     previous2 = total2;

     previous3 = total3;

     previous4 = total4;

    

     //delay(10);                             // arbitrary delay to limit data to serial port 

}

Capacitive Sensor + Piezo Drum Sensor

Laser Cut File

The Final Product

Jam 'n' Bread Demo

Assembly Demo

Process

  1. Get all items in bill of materials. 

  2. Download the STL files and laser cut the wood.

  3. Assemble wood (follow GIF).

  4. For circuitry, poke the LED lights into the hole slits.

  5. Put aluminum foil on the bottom and then connect long wires leading to them (which can later be hooked onto the microprocessor).

  6. Wire the LED lights. Make sure all wiring goes through the neatly made hole slit. It is advised to also use electrical tape to organize wires together and to label them. For example, group all the ground LEDS together and mark them accordingly. 

  7. Depending on how many musical plates you want, hook these wires to (x) amount of microprocessors. If for example you have a Mega like we did, then one was sufficient for everything - sensing the touches and playing the sound.

  8. Download the code (sound and sensor) and upload to the microprocessor. If you're only using one, combine the code and change up the IO pins.

  9. Create the circuitry as shown in the schematic.  

  10. Jam and eat beets.

Construction

Assembly Sequence (without wiring)

The Wiring

Arduino Sound Schematic

Presentation Slides

Presentation Slides

Insights & Ideas

  • Completely reinvent how we approached and tackled the problem.  There are two ways about of going at this. First is we keep the capacitive sensing as our method of picking up touch. To make this more accurate for our next implementation, we would get rid of the "pretty wires" that may have caused one capacitance touch to influence all the others, use wire shielding, and ensure that all foil eventually reached Earth ground through a 100pf capacitance for additional stability. Second way is to drop the capacitive sensors and adopt new approaches. One in mind was using Piezo pick-up sensors and distribute them evenly. Then, use changes in frequency or time that each sensor data picks up in order to isolate and locate a position.
  • Perhaps add a temporal element to our design. Allow the use of recording and playback. So for example on Thanksgiving day the plates will play music created from last Thanksgiving a year ago.
  • An on/off switch is probably necessary. Also, a kids mode would be great. The idea would be that a parent can lock a plate from playing until the kid finishes eating all of his or her food.
  • Improve sound of the speakers by getting better speakers and having an enclosure around it.
  • Limit the hassle of wires by using PCB or using wireless communication to talk to a master node that plays the music.
  • Change the interaction of the plates with the music. Instead of generating all the music from the plates, have music playing in the background and allow the plates to alter the ambient noise. This way you can control the music so that at the very worst it still sounds melodious.

Code

jamnbread.inoPlain text
jamnbread.ino
/*

 Example: Control a WTV020-SD-16P module to play voices from an Arduino board

 */



#include <Wtv020sd16p.h>





#define DRUM_THRESHOLD 40

int resetPin = 2;  // The pin number of the reset pin.

int clockPin = 3;  // ThMe pin number of the clock pin.

int dataPin = 4;  // The Mpin number of the data spin.

int busyPin = 5;  // The pin number of the busy pin.



int piano1Pin = 31;

int piano2Pin = 33;

int piano3Pin = 35;

int piano4Pin = 37;





int piezo1 = A0;

int piezo2 = A1;

int piezo3 = A2;



boolean piano = false;

boolean guitar = false;

boolean drum = false;



boolean piano1Tap = false;

boolean piano2Tap = false;

boolean piano3Tap = false;

boolean piano4Tap = false;



int drum1Pin = 39;

int drum2Pin = 41;

int drum3Pin = 43;

int drum4Pin = 45;

boolean drum1Tap = false;

boolean drum2Tap = false;

boolean drum3Tap = false;

boolean drum4Tap = false;



int guitar1Pin = 47;

int guitar2Pin = 49;

int guitar3Pin = 51;

int guitar4Pin = 53;

boolean guitar1Tap = false;

boolean guitar2Tap = false;

boolean guitar3Tap = false;

boolean guitar4Tap = false;





/*

Create an instance of the Wtv020sd16p class.

 1st parameter: Reset pin number.

 2nd parameter: Clock pin number.

 3rd parameter: Data pin number.

 4th parameter: Busy pin number.

 */

Wtv020sd16p wtv020sd16p(resetPin,clockPin,dataPin,busyPin);



void setup() {

//  pinMode(piano1Pin, INPUT);

//  pinMode(piano2Pin, INPUT);

//  pinMode(piano3Pin, INPUT);

//  pinMode(piano4Pin, INPUT);

//  

//  pinMode(drum1Pin, INPUT);

//  pinMode(drum2Pin, INPUT);

//  pinMode(drum3Pin, INPUT);

//  pinMode(drum4Pin, INPUT);

//  

//  pinMode(guitar1Pin, INPUT);

//  pinMode(guitar2Pin, INPUT);

//  pinMode(guitar3Pin, INPUT);

//  pinMode(guitar4Pin, INPUT);



  pinMode(piezo1, INPUT);

  pinMode(piezo2, INPUT);

  pinMode(piezo3, INPUT);

  pinMode(guitar3Pin, INPUT);



  

  //Initializes the module.

  wtv020sd16p.reset();

  

  Serial.begin(9600);

}



void loop() {

//  int piano1 = digitalRead(piano1Pin);

//  int piano2 = digitalRead(piano2Pin);

//  int piano3 = digitalRead(piano3Pin);

//  int piano4 = digitalRead(piano4Pin);

//  

//  int drum1 = digitalRead(drum1Pin);

//  int drum2 = digitalRead(drum2Pin);

//  int drum3 = digitalRead(drum3Pin);

//  int drum4 = digitalRead(drum4Pin);

//  

//  int guitar1 = digitalRead(guitar1Pin);

//  int guitar2 = digitalRead(guitar2Pin);

//  int guitar3 = digitalRead(guitar3Pin);

//  int guitar4 = digitalRead(guitar4Pin);

//  

  //Serial.println("Running Main Loop");

  

  int drum1_sensor =analogRead(piezo1);

  int drum2_sensor = analogRead(piezo2);

  int drum3_sensor = analogRead(piezo3);

  

  

    //wtv020sd16p.asyncPlayVoice(1);

   //delay(5000);

  

//  if (drum1_sensor > DRUM_THRESHOLD) {

//    //Serial.println("In here");

//    if (!piano) {

//      piano = true;

//      int random_number = random(0, 2);

//      wtv020sd16p.asyncPlayVoice(random_number);

//    }

//  } else {

//    piano = false;

//  }

      

  

  if (drum2_sensor > DRUM_THRESHOLD ) {

    Serial.println("In here");

      int random_number = random(3, 6);

      wtv020sd16p.asyncPlayVoice(0);

      drum = true; 

      //delay(5000); 

      //last_played =

  } 

  

  

  

//   

//   

    Serial.println(drum2_sensor);

// //   Serial.println(drum1_sensor);

  

  

// if (piano1) {

//    if (!piano1Tap) {

//      wtv020sd16p.asyncPlayVoice(0);

//      piano1Tap = true;

//      return;

//    }

//  } else {

//    piano1Tap = false;

//  }

//  

//  if (piano2) {

//    if (!piano2Tap) {

//      wtv020sd16p.asyncPlayVoice(1);

//      piano2Tap = true;

//      return;

//    }

//  } else {

//    piano2Tap = false;

//  }

//  

//  if (piano3) {

//    if (!piano3Tap) {

//      wtv020sd16p.asyncPlayVoice(2);

//      piano3Tap = true;

//      return;

//    }

//  } else {

//    piano3Tap = false;

//  }

//  

//  if (piano4) {

//    if (!piano4Tap) {

//      wtv020sd16p.asyncPlayVoice(3);

//      piano4Tap = true;

//      return;

//    }

//  } else {

//    piano4Tap = false;

//  }

//  

//  if (drum1) {

//    if (!drum1Tap) {

//      wtv020sd16p.asyncPlayVoice(4);

//      drum1Tap = true;

//      return;

//    }

//  } else {

//    drum1Tap = false;

//  }

//  

//  if (drum2) {

//    if (!drum1Tap) {

//      wtv020sd16p.asyncPlayVoice(5);

//      drum1Tap = true;

//      return;

//    }

//  } else {

//    drum1Tap = false;

//  }

//  

//  if (drum3) {

//    if (!drum3Tap) {

//      wtv020sd16p.asyncPlayVoice(6);

//      drum3Tap = true;

//      return;

//    }

//  } else {

//    drum3Tap = false;

//  }

//  

//  if (drum4) {

//    if (!drum4Tap) {

//      wtv020sd16p.asyncPlayVoice(7);

//      drum4Tap = true;

//      return;

//    }

//  } else {

//    drum4Tap = false;

//  }

//  

//  if (guitar1) {

//    if (!guitar1Tap) {

//      wtv020sd16p.asyncPlayVoice(8);

//      guitar1Tap = true;

//      return;

//    }

//  } else {

//    guitar1Tap = false;

//  }

//  

//  if (guitar2) {

//    if (!guitar2Tap) {

//      wtv020sd16p.asyncPlayVoice(9);

//      guitar2Tap = true;

//      return;

//    }

//  } else {

//    guitar2Tap = false;

//  }

//  

//  if (guitar3) {

//    if (!guitar3Tap) {

//      wtv020sd16p.asyncPlayVoice(10);

//      guitar3Tap = true;

//      return;

//    }

//  } else {

//    guitar3Tap = false;

//  }

//

//  if (guitar4) {

//    if (!guitar4Tap) {

//      wtv020sd16p.asyncPlayVoice(11);

//      guitar4Tap = true;

//      return;

//    }

//  } else {

//    guitar4Tap = false;

//  }

}
sensorcode.inoC/C++
sensorcode.ino
#include <CapacitiveSensor.h>

#define LED 10

#define LED2 11

#define LED3 12

#define LED4 13



#define PIEZO1 A0





#define TESTLED 12

#define CAP_THRESHOLD 300

#define DRUM_THRESHOLD 8



boolean pressed1 = false;

boolean pressed2 = false;

boolean pressed3 = false;

boolean pressed4 = false;





/*

 * CapitiveSense Library Demo Sketch

 * Paul Badger 2003

 * Uses a high value resistor e.g. 10M between send pin and receive pin

 * Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values.

 * Receive pin is the sensor pin - try different amounts of foil/metal on this pin

 */





CapacitiveSensor   cs_0_1 = CapacitiveSensor(2,3);        // 10M resistor between pins 0 & 1, pin 2 is sensor pin, add a wire and or foil if desired

CapacitiveSensor   cs_0_2 = CapacitiveSensor(4,5);        // 10M resistor between pins 0 & 2, pin 6 is sensor pin, add a wire and or foil

CapacitiveSensor   cs_0_3 = CapacitiveSensor(6,7);        // 10M resistor between pins 0 & 3, pin 3 is sensor pin, add a wire and or foil

CapacitiveSensor   cs_0_4 = CapacitiveSensor(8,9);        // 10M resistor between pins 4 & 10, pin 10 is sensor pin, add a wire and or foil



//Previous value for cap1

long previous1 = 0;

long previous2 = 0;

long previous3 = 0;

long previous4 = 0;



 

void setup()                    

{

   pinMode(LED,OUTPUT);

   pinMode(LED2, OUTPUT);

   pinMode(LED3,OUTPUT);

   pinMode(LED4, OUTPUT);

   pinMode(TESTLED, OUTPUT);

   

   pinMode(PIEZO1, INPUT);

   

   digitalWrite(TESTLED, HIGH);

   

   digitalWrite(LED, LOW);

   digitalWrite(LED2, LOW);

   digitalWrite(LED3, LOW);

   digitalWrite(LED4, LOW);

 

 

   cs_0_1.set_CS_AutocaL_Millis(0xFFFFFFFF);

   cs_0_2.set_CS_AutocaL_Millis(0xFFFFFFFF);

   cs_0_3.set_CS_AutocaL_Millis(0xFFFFFFFF);

   cs_0_4.set_CS_AutocaL_Millis(0xFFFFFFFF);    // turn off autocalibrate on channel 1 - just as an example

    Serial.begin(9600);

}



void turnOn(int led) {

  switch(led) {

    case 0:  {

       digitalWrite(LED, HIGH);

       break; 

    }

  

    case 1:  {

       digitalWrite(LED2, HIGH);

       break; 

    }

    

    case 2:  {

       digitalWrite(LED3, HIGH);

       break; 

    }

    

    case 3:  {

       digitalWrite(LED4, HIGH);

       break; 

    }

  }

  

  delay(100);

  cs_0_1.reset_CS_AutoCal();

  cs_0_2.reset_CS_AutoCal();

  cs_0_3.reset_CS_AutoCal();

  cs_0_4.reset_CS_AutoCal();

  

}



void loop()                    

{

  

    int drum = analogRead(PIEZO1);

    

    long start = millis();

    long total1 =  cs_0_1.capacitiveSensor(10);

    long total2 =  cs_0_2.capacitiveSensor(10);

    long total3 =  cs_0_3.capacitiveSensor(30);

    long total4 =  cs_0_4.capacitiveSensor(30);

 

    long maxi = 0;

    

    long diff1 = total1 - previous1;

    long diff2 = total2 - previous2;

    long diff3 = total3 - previous3;

    long diff4 = total4 - previous4;

 

    long difference[4] = {diff1,diff2,diff3,diff4};

   

    int max_index = 0;

    for (int i=0; i<4;i++){

      maxi = max(maxi,difference[i]);

      if (maxi == difference[i]) {

        max_index = i;        

      }

    }

    

    

  

    if (drum > DRUM_THRESHOLD) {

     if (maxi > CAP_THRESHOLD) {

        turnOn(max_index);

     //   Serial.println("max:" + String(maxi));   

      }  

    }

    digitalWrite(LED,LOW);

    digitalWrite(LED2,LOW);

    digitalWrite(LED3,LOW);

    digitalWrite(LED4,LOW);

 

    

    //Serial.print(millis() - start);        // check on performance in milliseconds

    //Serial.print("\t");                    // tab character for debug windown spacing

     

     if (diff1 > CAP_THRESHOLD) {

       

       Serial.println("Cap1:" + String(diff1));      // print sensor output 1

       Serial.print("\t");

     }

//    Serial.println("Cap2:" + String(diff2));                  // print sensor output 2

//    Serial.print("\t");

//    Serial.print(diff3);                // print sensor output 3

//    Serial.print("\t");

//    Serial.println(diff4);

//    Serial.println("max:" + String(maxi));

//    Serial.println("PIezo:" + String(drum));

     previous1 = total1;

     previous2 = total2;

     previous3 = total3;

     previous4 = total4;

    

     //delay(10);                             // arbitrary delay to limit data to serial port 

}

Schematics

Circuitsio

Comments

Similar projects you might like

MEGA BREAD - 4X4 KeyPad

Project in progress by Pigeon-Kicker

  • 2,127 views
  • 1 comment
  • 4 respects

MEGA BREAD - Hank the HexaPod-Updated 5-31-17

Project in progress by Pigeon-Kicker

  • 1,682 views
  • 1 comment
  • 13 respects

Mega Bread - Atari Joystick Linking for Robotics Control

Project in progress by Pigeon-Kicker

  • 1,618 views
  • 3 comments
  • 10 respects

MEGA BREAD - Stereo Power Audio Amplifiers

Project in progress by Pigeon-Kicker

  • 1,244 views
  • 0 comments
  • 6 respects

Mega Bread - Hello World

Project in progress by Pigeon-Kicker

  • 1,308 views
  • 0 comments
  • 4 respects

Electronic Check-In

Project tutorial by Gergely Imreh

  • 5,520 views
  • 9 comments
  • 30 respects
Add projectSign up / Login