-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArduino-2v1.ino
More file actions
38 lines (33 loc) · 932 Bytes
/
Arduino-2v1.ino
File metadata and controls
38 lines (33 loc) · 932 Bytes
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
// Watch video here: https://www.youtube.com/watch?v=235BLk7vk00
/* Vibration sensor connected to Arduino pins as follows:
Arduino Vibration Sensor
D9 DOut
GND GND
+5V VCC
D13 Indication LED
*/
int ledPin = 13;
int EP =9;
void setup(){
pinMode(ledPin, OUTPUT);
pinMode(EP, INPUT); //set EP input for measurment
Serial.begin(9600); //init serial 9600
// Serial.println("----------------------Vibration demo------------------------");
}
void loop(){
long measurement =TP_init();
delay(50);
// Serial.print("measurment = ");
Serial.println(measurement);
if (measurement > 1000){
digitalWrite(ledPin, HIGH);
}
else{
digitalWrite(ledPin, LOW);
}
}
long TP_init(){
delay(10);
long measurement=pulseIn (EP, HIGH); //wait for the pin to get HIGH and returns measurement
return measurement;
}