Daniel ALICIragavbKitox
Created April 21, 2018

Dancing water speaker

You will be amazed to experiment the sound, the light and the water dance !

128
Dancing water speaker

Things used in this project

Hardware components

Capacitor 100 nF
Capacitor 100 nF
×1
Capacitor 100 µF
Capacitor 100 µF
×1
Resistor 100 ohm
Resistor 100 ohm
×1
Single Turn Potentiometer- 10k ohms
Single Turn Potentiometer- 10k ohms
×1
Texas Instruments lm386
×1
RGB Diffused Common Cathode
RGB Diffused Common Cathode
×1
pump jt-180
×1
LSM-S30K speaker
×1
Arduino UNO
Arduino UNO
×1
external batterie
×1
arduino shield grove
×1
arduino relay grove
×1

Software apps and online services

Arduino IDE
Arduino IDE
KiCad
KiCad

Hand tools and fabrication machines

S63 lpkf
Epoxy Fiber FR4

Story

Read more

Custom parts and enclosures

Complete PCB

This is the PCB, you just need to route the bottom part.
In the final version, my team and I have choosed to use the amplifier with a gain of 20

KiCad PCB file

Schematics

LM386 with 2O of gain

Fritzing Schema with breadBoard

As you can see, connecting only using a breadBoard is pretty difficult, if it's possible, it's better to create a PCB

Complete scheme

Thanks to that scheme you can use our program, in addition, you can use the LM386 amplifier.

KiCad schema file

Code

FFT.ino

C/C++
This code is used to sample and song, and check his frequences variations.
Sampling is made using FFT (Fast Fourier Transform).
#include "arduinoFFT.h"
 
#define SAMPLES 128             //Must be a power of 2     // 2^7
#define SAMPLING_FREQUENCY 1000 //Hz, must be less than 10000 due to ADC
 
arduinoFFT FFT = arduinoFFT();
 
unsigned int sampling_period_us;
unsigned long microseconds;
 
double vReal[SAMPLES];
double vImag[SAMPLES];

int ledPin = 13;      // select the pin for the LED
int ledPinGND = 8;      // select the pin for the LED
int ledPinG = 9;      // select the pin for the LED
int ledPinR = 10;      // select the pin for the LED
int ledPinB = 11;      // select the pin for the LED

float  tension = 0;

int pompe = 3;
 
void setup() {
    Serial.begin(115200);
 
    sampling_period_us = round(1000000*(1.0/SAMPLING_FREQUENCY));

    // declare the ledPin as an OUTPUT:
    pinMode(ledPin, OUTPUT);
  
    pinMode(ledPinR, OUTPUT);
    pinMode(ledPinG, OUTPUT);
    pinMode(ledPinB, OUTPUT);
    pinMode(ledPinGND, OUTPUT);

    pinMode(pompe, OUTPUT);
    
}
 
void loop() {

  digitalWrite(ledPinR, 0);
  digitalWrite(ledPinG, 0);
  digitalWrite(ledPinB, 0);
  digitalWrite(ledPinGND, 0);

  digitalWrite(pompe, 0);
   
    /*SAMPLING*/
    for(int i=0; i<SAMPLES; i++)
    {
        microseconds = micros();    //Overflows after around 70 minutes!
     
        vReal[i] = analogRead(0);
        vImag[i] = 0;
     
        while(micros() < (microseconds + sampling_period_us)){
        }
    }
 
    /*FFT*/
    FFT.Windowing(vReal, SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
    FFT.Compute(vReal, vImag, SAMPLES, FFT_FORWARD);
    FFT.ComplexToMagnitude(vReal, vImag, SAMPLES);
    double peak = FFT.MajorPeak(vReal, SAMPLES, SAMPLING_FREQUENCY);
 
    /*PRINT RESULTS*/
    //Serial.println(peak);     //Print out what frequency is the most dominant.
 
    for(int i=0; i<(SAMPLES/2); i++)
    {
        /*View all these three lines in serial terminal to see which frequencies has which amplitudes*/

                if (vReal[i] > 5)
                {
                  delay(100);         // delay in between reads for stability 
                digitalWrite(pompe, 1);
                  
                digitalWrite(ledPinR, 1);
                digitalWrite(ledPinG, 0);       // define a colors
                digitalWrite(ledPinB, 0);
              
                delay(500);        // delay to change to improve the water jet

                digitalWrite(ledPinR, 0);
                digitalWrite(ledPinG, 0);
                digitalWrite(ledPinB, 0);
                
                digitalWrite(pompe, 0);
                }
                if (vReal[i] > 15)
                {
                  delay(100);         // delay in between reads for stability
                digitalWrite(pompe, 1);
                  
                digitalWrite(ledPinR, 0);
                digitalWrite(ledPinG, 1);           // define a colors
                digitalWrite(ledPinB, 0);
                
                delay(300);         // delay to change to improve the water jet
                
                digitalWrite(ledPinR, 0);
                digitalWrite(ledPinG, 0);
                digitalWrite(ledPinB, 0);
                
                digitalWrite(pompe, 0);
                }
                
                if (vReal[i] > 20)
                {
                  delay(100);      // delay in between reads for stability 
                digitalWrite(pompe, 1);
              
                digitalWrite(ledPinR, 0);
                digitalWrite(ledPinG, 0);     // define a colors
                digitalWrite(ledPinB, 1);
              
                delay(150);        // delay to change to improve the water jet

                digitalWrite(ledPinR, 0);
                digitalWrite(ledPinG, 0);
                digitalWrite(ledPinB, 0);
                
                digitalWrite(pompe, 0);
                }
                
         
        //Serial.print((i * 1.0 * SAMPLING_FREQUENCY) / SAMPLES, 1);
        //Serial.print(" ");
        Serial.println(vReal[i], 1);    //View only this line in serial plotter to visualize the bins
    }
 
    //delay(1000);  //Repeat the process every second OR:
//    while(1);       //Run code once
}

Credits

Daniel ALICI
1 project • 0 followers
ragavb
1 project • 0 followers
Kitox
1 project • 0 followers

Comments