This repository has been archived by the owner on Nov 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Geiger_counter.pde
180 lines (153 loc) · 4.23 KB
/
Geiger_counter.pde
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
* ------Geiger Tube board (Arduino Code) Example--------
*
* Explanation: This example shows how to get the signal from the Geiger Tube
* in Arduino, we use one of the Arduino interrupt pins (PIN2).
* We count the time (ms) between two pulses of the Geiger tube.
*
* Copyright (C) 2011 Libelium Comunicaciones Distribuidas S.L.
* http://www.libelium.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Version: 0.3
* Design: Marcos Yarza, David Gascon
* Implementation: Marcos Yarza
*/
/*
updated version by Joey Stanford
community code from Stfb included
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(3,4,5,6,7,8);
// Threshold values for the led bar
#define TH1 45
#define TH2 95
#define TH3 200
#define TH4 400
#define TH5 600
// Conversion factor - CPM to uSV/h
#define CONV_FACTOR 0.00812
// Natural average radiation in uSV/h
#define NATURAL_RADIATION 0.27
// Variables
int ledArray [] = {
10,11,12,13,9};
int geiger_input = 2;
long count = 0;
long countPerMinute = 0;
long timePrevious = 0;
long timePreviousMeassure = 0;
long time = 0;
long countPrevious = 0;
float radiationValue = 0.0;
// count one measure at least
int minCount = 0;
// Average radiation measure
float avg = 0;
// Natural radiation factor
int natFactor = 0;
void setup(){
pinMode(geiger_input, INPUT);
digitalWrite(geiger_input,HIGH);
for (int i=0;i<5;i++){
pinMode(ledArray[i],OUTPUT);
}
Serial.begin(19200);
//set up the LCD\'s number of columns and rows:
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Radiation Sensor");
lcd.setCursor(0,1);
lcd.print("Board - Arduino");
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Joey Stanford");
lcd.setCursor(0,1);
lcd.print("[email protected]");
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Starting Up...");
attachInterrupt(0,countPulse,FALLING);
}
void loop(){
if (millis()-timePreviousMeassure > 10000){
countPerMinute = 6*count;
radiationValue = countPerMinute * CONV_FACTOR;
timePreviousMeassure = millis();
// Serial.print("☢ ");
Serial.print(countPerMinute,DEC);
Serial.print(",");
Serial.print(radiationValue,4);
Serial.print(",");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("CPM=");
lcd.setCursor(4,0);
lcd.print(countPerMinute);
lcd.setCursor(0,1);
lcd.print(radiationValue,4);
lcd.setCursor(6,1);
lcd.print(" uSv");
//led var setting
if(countPerMinute <= TH1) ledVar(0);
if((countPerMinute <= TH2)&&(countPerMinute>TH1)) ledVar(1);
if((countPerMinute <= TH3)&&(countPerMinute>TH2)) ledVar(2);
if((countPerMinute <= TH4)&&(countPerMinute>TH3)) ledVar(3);
if((countPerMinute <= TH5)&&(countPerMinute>TH4)) ledVar(4);
if(countPerMinute>TH5) ledVar(5);
count = 0;
minCount++;
}
if(minCount==1){
avg = (avg + radiationValue)/2;
Serial.print(avg,4);
Serial.print(",");
lcd.setCursor(10, 0);
lcd.print(avg,4);
minCount = 0;
lcd.setCursor(11, 1);
lcd.print("X");
natFactor = avg / NATURAL_RADIATION;
Serial.println(natFactor, DEC);
lcd.print(natFactor,DEC);
}
}
void countPulse(){
detachInterrupt(0);
count++;
while(digitalRead(2)==0){
}
attachInterrupt(0,countPulse,FALLING);
}
void ledVar(int value){
if (value > 0){
for(int i=0;i<=value;i++){
digitalWrite(ledArray[i],HIGH);
}
for(int i=5;i>value;i--){
digitalWrite(ledArray[i],LOW);
}
}
else {
for(int i=5;i>=0;i--){
digitalWrite(ledArray[i],LOW);
}
}
}