-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPiezoTapInputCount.ino
38 lines (32 loc) · 1 KB
/
PiezoTapInputCount.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* This script reads input from piezo panels, filters to the predefined range, counts the number of inputs
* Please make sure the analog input signal is adjusted/mapped to the range 0-5V
* Version 1.0.0
*
* By:
* Jash Bharat Mota
* http://www.jashmota.esy.es
*/
// these constants won't change:
const int knockSensor = A1; // the piezo is connected to analog pin 0
// these variables will change:
int sensorReading = 0; // variable to store the value read from the sensor pin
int count = 0;
void setup() {
Serial.begin(9600); // use the serial port
}
void loop() {
// read the sensor and store it in the variable sensorReading:
sensorReading = analogRead(knockSensor);
//Range filteration and count
lowerRange = 500;
higherRange = 1023;
if(sensorReading > lowerRange && sensorReading <= higherRange)
{
count++;
}
delay(500); // delay to avoid overloading the serial port buffer
Serial.print("Voltage: ");
Serial.println(sensorReading);
}