-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemi_sensor.ino
40 lines (37 loc) · 907 Bytes
/
emi_sensor.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
/*
* Arduino EMI Sensor
* By Steven de Salas
*
* A simple sensor that detects electromagnetic inteference.
* It works because Arduino analog pins are very sensitive when using
* a 'floating ground' (ie when antenna is not connected to main ground).
*
* DIAGRAM:
*
* (Antenna)
* Y
* | +--------+
* | |* *|9 --O-| (Red LED)
* | |* *|8 --O-| (Red LED)
* | |* *|7 --O-| (Yellow LED)
* |- A3|* *|6 --O-| (Green LED)
* |* *| |
* |* *|GND --|
* +--------+
*/
int antenna = A0;
int leds[] = { 2, 3, 4, 5 };
int thresholds[] = { 256, 512, 768, 950 };
void setup() {
for (byte i = 0; i < 4; i++) {
pinMode(leds[i], OUTPUT);
}
pinMode(antenna, INPUT);
}
void loop() {
int emi = analogRead(antenna);
for (byte i = 0; i < 4; i++) {
digitalWrite(leds[i], emi > thresholds[i] ? 1 : 0);
}
delay(10);
}