-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRFJammerDetector.ino
105 lines (86 loc) · 2.77 KB
/
RFJammerDetector.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* Simple Script to 'detect' jammers, really just looks at the average analog in values
* from a cheap 433mhz RX component and then decides if its been held 'low' ( like a remote has been pressed )
* for too many seconds.
*
* Wiring is relatively straight forward:
*
* Datapin of 433mhz RX -> analog 'inPin' ( default *analog* 2 )
* Green LED -> 'greenLED' ( default 2 )
* Red LED -> 'redLED' ( default 3)
* Vibration Motor -> 'buzzPin' ( default 11 )
*
*/
int numSamples = 300; // num samples to take every loop
int jamTimeMS = 300; // how long we need high samples before triggering
int highVal = 105; // what the 'high' value is ( default noise )
int lowVal = 50; // what the 'low' value is ( remote being pressed )
#define greenLED 2
#define redLED 3
int inPin = 2;
int buzzPin = 11;
int buzzAmount = 200;
long total = 0;
long inputVal = 0;
float val;
unsigned long jamTimer = 0;
unsigned long stableTimer = 0;
void setup() {
Serial.begin(115200);
Serial.println("*trumpets* Started Jam Detector!");
pinMode(greenLED,OUTPUT);
pinMode(redLED,OUTPUT);
digitalWrite(greenLED,HIGH);
}
void loop() {
for(int i = 0; i < numSamples; i++)
{
total += analogRead(inPin);
}
val = total / numSamples;
val = constrain(val, 0, 1023); //this constrains the variable value to between two numbers 0 and 1023, the max value on a analog input
val = map(val, 0, 1023, 0, 255); //the map statement tells the program to map out 0-100 to 0-255, 255 is the max on a analog output
if (val > highVal)
{
if (stableTimer == 0)
{
stableTimer = millis();
Serial.print(millis());
Serial.println(": Stable Timer Started");
}
else
{
if(millis() - stableTimer > 300)
{
if(jamTimer > 0)
{
digitalWrite(greenLED,HIGH);
digitalWrite(redLED,LOW);
analogWrite( buzzPin , 0 );
Serial.print(millis());Serial.println(": Jam Timer Ended");
}
jamTimer = 0;
}
}
}
if (val < lowVal)
{
stableTimer = millis();
if(jamTimer == 0)
{
Serial.print(millis());Serial.println(": Jam Timer Started");
jamTimer = millis();
}
else
{
if (millis() - jamTimer > jamTimeMS)
{
Serial.print(millis());Serial.println(": JAM Detected!");
digitalWrite(greenLED,LOW);
digitalWrite(redLED,HIGH);
analogWrite( buzzPin , buzzAmount );
}
}
}
total = 0;
delay(1);
}