Tap Module Sensor

Tap Module

  • $3.85


Tap Sensor Module Code


/* SETUP

Tap-Module     Arduino
S       -      D10
        -      5V
-       -      GND
*/
 
int knockPin = 10; // Use Pin 10 as our Input
int knockVal = HIGH; // This is where we record our shock measurement
boolean bAlarm = false;

unsigned long lastKnockTime; // Record the time that we measured a shock


int knockAlarmTime = 500; // Number of milli seconds to keep the knock alarm high


void setup ()
{
  Serial.begin(9600);  
  pinMode (knockPin, INPUT) ; // input from the KY-031
}
void loop ()
{
  knockVal = digitalRead (knockPin) ; // read KY-031 Value
  
  if (knockVal == LOW) // If we see a knock
  {
  
    lastKnockTime = millis(); // record the time of the shock
    // The following is so you don't scroll on the output screen
    if (!bAlarm){
      Serial.println("KNOCK, KNOCK");
      bAlarm = true;
    }
  }
  else
  {
    if( (millis()-lastKnockTime) > knockAlarmTime  &&  bAlarm){
      Serial.println("no knocks");
      bAlarm = false;
    }
  }
}

We Also Recommend


where to buy Tap Sensors in toronto

Tap Sensor toronto

buy Tap Sensor toronto