-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNanoLieDetector.ino
132 lines (96 loc) · 2.41 KB
/
NanoLieDetector.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
Nano Lie Detector
Roni Bandini
Buenos Aires, Argentina 8/2020
Twitter/Instagram @RoniBandini
Connections
GSR1 1 -> A1, 300K Resisor, GND
GSR 2 -> 5V
Heart rate monitor A0, 5v and GND
Vu-meter 3 and GND, 6 and GND
Buzzer D5 and GND
*/
#define USE_ARDUINO_INTERRUPTS true
#include <PulseSensorPlayground.h>
// Pins
const int PulseWire = 0;
int vumeterPin1 = 3;
int vumeterPin2 = 6;
int buzzerPin = 5;
int potPin = 2;
const int galvanicPin = 1;
const int LED13 = 13;
int Threshold = 510;
int galvanicVal =0;
int galvanicVumeter=0;
int galvanicCompensation=100;
int counter=0;
PulseSensorPlayground pulseSensor;
void setup() {
int myV=0;
// move needles to top
while (myV<20)
{
analogWrite(vumeterPin1, myV);
analogWrite(vumeterPin2, myV);
Serial.println(myV);
delay(50);
myV=myV+1;
}
analogWrite(vumeterPin1, 0);
analogWrite(vumeterPin2, 0);
tone(buzzerPin, 100);
delay(100);
noTone(buzzerPin);
Serial.begin(9600);
Serial.println("Nano Lie Detector started - Roni Bandini");
pulseSensor.analogInput(PulseWire);
pulseSensor.blinkOnPulse(LED13);
Serial.println("Threesold");
Serial.println(Threshold);
pulseSensor.setThreshold(Threshold);
if (pulseSensor.begin()) {
Serial.println("PulseSensor Object ready");
}
}
void loop() {
int myBPM = pulseSensor.getBeatsPerMinute();
if (pulseSensor.sawStartOfBeat()) {
// update galvanic 1/3
if (counter==3){
galvanicVal = analogRead(galvanicPin);
galvanicVal=galvanicVal-galvanicCompensation;
counter=1;
}
else
{
counter++;
}
if (myBPM<180){
Serial.println("♥");
analogWrite(vumeterPin1, 12);
Serial.print("Galvanic: ");
Serial.println(galvanicVal);
if (galvanicVal>0)
{
// map value to fit vu-meter scale
galvanicVumeter=map(galvanicVal,0,1024,0,20);
}
else
{
galvanicVumeter=0;
}
Serial.print("Galvanic vu-meter: ");
Serial.println(galvanicVumeter);
analogWrite(vumeterPin2, galvanicVumeter);
if (galvanicVal>800){
tone(buzzerPin, 50);
delay(10);
noTone(buzzerPin);
}
}
}
delay(20);
// return needle for beat movement
analogWrite(vumeterPin1, 2);
}