-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeiger-Counter-Arduino.ino
More file actions
50 lines (42 loc) · 1.36 KB
/
Geiger-Counter-Arduino.ino
File metadata and controls
50 lines (42 loc) · 1.36 KB
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
#include <Time.h>
#include <TimeLib.h>
// Connect the GND pin on Arduino to the GND pin on the Geiger counter.
// Connect the 5V pin on Arduino to the 5V pin on the Geiger counter.
// Connect the VIN pin on the Geiger counter to the D2 pin on Arduino.
unsigned long counts; // variable for GM Tube events
unsigned long previousMillis; // variable for measuring time
#define LOG_PERIOD 1000 // count rate
#define usv_multiplier 0.1 // For the J305β tube
#define cpm_multiplier 2.3456 // For the J305β tube
void impulse() {
counts++;
}
void setup()
{
counts = 0;
Serial.begin(9600);
pinMode(2, INPUT);
attachInterrupt(digitalPinToInterrupt(2), impulse, FALLING); // define external interrupts
}
void loop()
{
String usv, cpm;
unsigned long currentMillis = millis();
if (currentMillis - previousMillis > LOG_PERIOD)
{
previousMillis = currentMillis;
if(counts != 0)
{
// Log the time
time_t t = now();
String time = String((minute(t) * 60) + (second(t)));
// Print in μSv/hr
usv = String(counts * usv_multiplier);
Serial.println("usv " + time + " " + usv);
// Print in CPM
cpm = String(counts * cpm_multiplier);
Serial.println("cpm " + time + " " + cpm);
}
counts = 0;
}
}