Things used in this project

Hardware components:
Maple Mini
Arduino compatible - see www.stm32duino.com
×1
Piezo
×1
TIP102
Power NPN darlington transistor
×1
Resistor 1M
1 Megaohm resistor
×1
Resistor 1k
1 kiloohm resistor
×1
Wires
Some wires to wire it up all together
×1
Software apps and online services:
Ide web
Arduino IDE
Needs some hacking thought - see www.stm32duino.com

Schematics

Schematic - knock controlled LED strip
Knockledstrip schem

Code

Knock detectorC/C++
This program detects knocks on piezo (pin 11) and turns on/off the LED strip via TIP102 on pin 3.
/* *************************************

Project name: LED strip control by knock
Author: Tekk (Peter Javorsky)
Date: 24/9/2015
Contact: tekk.sk (at) gmail.com

**************************************** */

int ledStripPin = 3;  // this controls the TIP102 and turns on/off the LED strip
int knockSensor = 11; // this is where your piezo is connected, don't forget the 1 Megaohm resistor in parralell
int statePin = LOW;
int THRESHOLD = 27; // needs to be adjusted according to your piezo type!

void setup() 
{
 pinMode(ledStripPin, OUTPUT); 
 Serial.begin(9600);
 delay(100);  // wait for A/D converter and/or piezo to stabilize
}

void loop() 
{
  delay(1);  // don't remove this delay - Sample size: 1ms
  
  if (analogRead(knockSensor) >= THRESHOLD) 
  {
    statePin = !statePin;
    digitalWrite(ledStripPin, statePin);
    Serial.println("Knock!");
    delay(50);  // wait a while for piezo to stabilize
  }
  
}
Double-knock activated (version 2)C/C++
/* *************************************

Project name: LED strip control by knock
Author: Tekk (Peter Javorsky)
Date: 24/9/2015
Contact: tekk.sk (at) gmail.com

**************************************** */

int ledStripPin = 3;  // this controls the TIP102 and turns on/off the LED strip
int knockSensor = 11; // this is where your piezo is connected, don't forget the 1 Megaohm resistor in parralell
int statePin = LOW;
int THRESHOLD = 27; // needs to be adjusted according to your piezo type!

void setup() 
{
 pinMode(ledStripPin, OUTPUT); 
 Serial.begin(9600);
 delay(100);  // wait for A/D converter and/or piezo to stabilize
}

void loop() 
{
  delay(1);  // don't remove this delay - Sample size: 1ms
  
  if (analogRead(knockSensor) >= THRESHOLD) 
  {
    if (!statePin)
    {
      unsigned long t = millis() + 350;
      delay(50); // debounce only
      
      while (millis() < t)
      {
        delay(1);  // don't remove this delay - Sample size: 1ms
        
        if (analogRead(knockSensor) >= THRESHOLD) 
        {
          statePin = !statePin;
          digitalWrite(ledStripPin, statePin);
          Serial.print("Double ");
          delay(50);  // wait a while for piezo to stabilize
          break;
        }
      }
    }
    else
    {
      statePin = !statePin;
    }
    
    digitalWrite(ledStripPin, statePin);
    Serial.println("Knock!");
    delay(50);  // wait a while for piezo to stabilize
  }
  
}

Credits

Javorsky
Peter Javorsky
3 projects • 7 followers
.NET C# Linux Arduino Embedded RPi
Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaBlog