1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20int shockSensorPin = 2;
21int greenLedPin = 3;
22int redLedPin = 4;
23
24bool shockSensorSate = 0;
25
26void setup() {
27pinMode(shockSensorPin,INPUT);
28pinMode(greenLedPin,OUTPUT);
29pinMode(redLedPin,OUTPUT);
30
31shockSensorSate = digitalRead(shockSensorPin);
32}
33
34void loop() {
35
36 if (shockSensorSate == 1){
37 digitalWrite(greenLedPin,LOW);
38 for ( int i=0; i < 10;i++){
39 digitalWrite(redLedPin,HIGH);
40 delay(150);
41 digitalWrite(redLedPin,LOW);
42 delay(150);
43 if ( i == 9){
44 shockSensorSate = 0;
45 }
46 }
47 }
48 else {
49 shockSensorSate = digitalRead(shockSensorPin);
50 digitalWrite(greenLedPin,HIGH);
51 }
52
53
54
55
56}
57
Anonymous user
3 years ago
Hi. Great project, but i have question how to made led light instant about 3sec after shock sensor react?