蓋格計數器/輻射/Geiger counter
[蓋格計數器腳位]
[蓋格計數器腳位]
GND --> arduino GND
5V --> arduino 5V
VIN --> arduino pin2
[材料]
Arduino主板 x 1
科州Cajoe 蓋格計數器 RadiationD-v1.1 x 1
程式碼1 (數據顯示在電腦上)
#include <SPI.h>
#define LOG_PERIOD 30000 //Logging period in milliseconds, recommended value 15000-60000.
#define MAX_PERIOD 60000 //Maximum logging period without modifying this sketch
float counts; //variable for GM Tube events
float cpm; //variable for CPM
float multiplier; //variable for calculation CPM in this sketch
float previousMillis; //variable for time measurement
float usv ;
void tube_impulse(){ //subprocedure for capturing events from Geiger Kit
counts++;
}
void setup(){
counts = 0;
cpm = 0;
Serial.begin(9600);
attachInterrupt(0, tube_impulse, FALLING);
Serial.println("Human exposure to natural background radiation (global average) = 0.274µSv/h");
}
void loop(){
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > LOG_PERIOD){
multiplier = MAX_PERIOD / (currentMillis - previousMillis); //calculating multiplier, depend on your log period
cpm = counts * multiplier;
usv = cpm / 151; // 151CPM=1uSv/h for M4011 GM Tube。
Serial.println("Radiation= " + String(cpm) + " CPM(counts per minute) = " + String(usv) + " µSv/h (微西弗/小時)");
previousMillis = currentMillis;
counts = 0;
}
}
程式碼2 (透過wifi上傳至ThingSpeak)
#include <SoftwareSerial.h>
SoftwareSerial esp8266(10,11);
#include <SPI.h>
#define LOG_PERIOD 30000 //Logging period in milliseconds, recommended value 15000-60000.
#define MAX_PERIOD 60000 //Maximum logging period without modifying this sketch
float counts; //variable for GM Tube events
float cpm; //variable for CPM
float multiplier; //variable for calculation CPM in this sketch
float previousMillis; //variable for time measurement
float usv ;
String apiKey = "";
String ssid = "";
String password = "";
boolean DEBUG = true;
void tube_impulse(){ //subprocedure for capturing events from Geiger Kit
counts++;
}
void showResponse(int waitTime){
long t=millis();
char c;
while (t+waitTime>millis()){
if (esp8266.available()){
c=esp8266.read();
if (DEBUG) Serial.print(c);
}
}
}
boolean thingSpeakWrite(float value1){
String cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += "184.106.153.149";
cmd += "\",80";
esp8266.println(cmd);
if (DEBUG) Serial.println(cmd);
if(esp8266.find("Error")){
if (DEBUG) Serial.println("AT+CIPSTART error");
return false;
}
String getStr = "GET /update?api_key=";
getStr +="&field1=";
getStr += String(value1);
getStr += "\r\n\r\n";
cmd = "AT+CIPSEND=";
cmd += String(getStr.length());
esp8266.println(cmd);
if (DEBUG) Serial.println(cmd);
delay(100);
if(esp8266.find(">")){
esp8266.print(getStr);
if (DEBUG) Serial.print(getStr);
}
else{
esp8266.println("AT+CIPCLOSE");
if (DEBUG) Serial.println("AT+CIPCLOSE");
return false;
}
return true;
}
void setup() {
DEBUG=true;
Serial.begin(9600);
Serial.println("Arduino...OK");
counts = 0;
cpm = 0;
attachInterrupt(0, tube_impulse, FALLING); //define external interrupts
esp8266.begin(115200);
esp8266.write("AT+UART_DEF=9600,8,1,0,0\r\n");
delay(1500);
esp8266.begin(9600);
Serial.println("ESP8266...OK");
esp8266.println("AT+CWMODE=1");
showResponse(1000);
esp8266.println("AT+CWJAP=\""+ssid+"\",\""+password+"\"");
showResponse(10000);
if (DEBUG) Serial.println("Setup completed");
}
void loop() {
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > LOG_PERIOD){
multiplier = MAX_PERIOD / (currentMillis - previousMillis); //calculating multiplier, depend on your log period
cpm = counts * multiplier;
usv = cpm / 151; // 151CPM=1uSv/h for M4011 GM Tube。
Serial.println("Radiation= " + String(cpm) + " CPM(counts per minute) = " + String(usv) + " µSv/h (微西弗/小時)");
thingSpeakWrite(usv);
previousMillis = currentMillis;
counts = 0;
}
}
參考網站:
日本地區輻射1:http://safecast.org/tilemap/
日本地區輻射2:http://jciv.iidj.net/map/
行政院原子能委員會,輻射劑量比較圖:https://www.aec.gov.tw/index--5_40_873.html