Arduino code for Geiger counter. Uploads CPM values to radmon.org every minute

More
2 years 6 months ago - 2 years 6 months ago #6149 by rootsolutions
Hello Friends!
I Share this:
Arduino code for Geiger counter. Uploads CPM values to radmon.org every minute
Download from https://github.com/rjelbert/geiger_counter

Thank you.
Best regards!
from Argentina

/*
* Geiger counter Kit could get on: https://www.aliexpress.com search: geiger counter kit
*
* WHAT IS CPM?
* CPM (or counts per minute) is events quantity from Geiger Tube you get during one minute. Usually it used to
* calculate a radiation level. Different GM Tubes has different quantity of CPM for background. Some tubes can produce
* about 10-50 CPM for normal background, other GM Tube models produce 50-100 CPM or 0-5 CPM for same radiation level.
* Please refer your GM Tube datasheet for more information. Just for reference here, J305 and SBM-20 can generate
* about 10-50 CPM for normal background.
*
* HOW TO CONNECT GEIGER KIT?
* The kit 3 wires that should be connected to Arduino UNO board: 5V, GND and INT. PullUp resistor is included on
* kit PCB. Connect INT wire to Digital Pin#2 (INT0), 5V to 5V, GND to GND. Then connect the Arduino with
* USB cable to the computer and upload this sketch.
*
* Author:JiangJie Zhang * If you have any questions, please connect This email address is being protected from spambots. You need JavaScript enabled to view it.
*
* License: MIT License
*
* Please use freely with attribution. Thank you!
*/

// to upload data to radmon.org use the following http get:
// https://radmon.org/radmon.php?function=submit&user=your_user&password=your_passwd&value=6&unit=CPM

// 1.14µSv.h - Shelter population
// 5.7µSv.h - Evacuation of population
// 11.4µSv.h - Issue Iodine tablets
// 0.114µSv.h - Max daily dose == 1mSv.year

// wiring:
// Arduino pin 2 - geiger counter input (VIN on geiger board)
// Arduino pin 3 - reset PoE ethernet board - use jumper lead
// Arduino pin 4 - Activity LED, active high

#include <SPI.h>
#include <Ethernet.h>

byte mac = { 0x2E, 0x3D, 0x4E, 0x5F, 0x6E, 0x7D };
char server = "radmon.org"; // name address for server (using DNS)

EthernetClient client;

#define LOG_PERIOD 60000 //Logging period in milliseconds, recommended value 15000-60000.
#define MAX_PERIOD 60000 //Maximum logging period without modifying this sketch
#define CONV_FACTOR 0.00812037 //See: https://www.pascalchour.fr/ressources/cgm/cgm_en.html
#define SS 10 //W5500 CS
#define RST 3 //W5500 RST - RJ add a jumper to change the reset of the board!
#define SLED 4 // system status LED

unsigned long volatile counts; //variable for GM Tube events
unsigned long cpm; //variable for CPM
unsigned int multiplier; //variable for calculation CPM in this sketch
unsigned long previousMillis; //variable for time measurement
float usvh; // variable for uSv per hour calculated figure
unsigned long ccount; // counter for the characters returned from the web service
byte okflag; // state machine to check for "OK" response from radmon.org in body not header

void tube_impulse(){ //subprocedure for capturing events from Geiger Kit
counts++;
}

void setup(){ //setup subprocedure
delay(5000); // delay boot
counts = 0;
cpm = 0;
multiplier = MAX_PERIOD / LOG_PERIOD; //calculating multiplier, depend on your log period
Serial.begin(9600);
delay(1000);
//while(!Serial){} // needed for Leonardo board
Serial.println("Booting...");
attachInterrupt(digitalPinToInterrupt(2), tube_impulse, FALLING); //define external interrupts
pinMode(SLED, OUTPUT); // the overall status LED for the outside of the case - reflects a sucessful upload
digitalWrite(SLED, HIGH); // turn LED on like a power led (it will blink off)

// bring up ethernet:
pinMode(SS, OUTPUT);
pinMode(RST, OUTPUT);
digitalWrite(SS, HIGH);
digitalWrite(RST,HIGH);
delay(200);
digitalWrite(RST,LOW); //Reset this module
delay(200);
digitalWrite(RST,HIGH);
delay(200);
digitalWrite(SS, LOW);
// end of copied sequence - no idea if this is needed with the modern Ethernet driver!

Ethernet.init(10); // Most Arduino shields use pin 10
delay(1000);

Serial.println("Initialize Ethernet...");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP."); }
delay(1000);

//Ethernet.maintain(); // renew lease

if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found."); }

if (Ethernet.hardwareStatus() == EthernetW5500) {
Serial.println("W5500 Ethernet controller detected."); }

if (Ethernet.linkStatus() == LinkON) {
Serial.println("Ethernet cable is connected."); }

// print your local IP address:
Serial.print("IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
if (thisByte < 3) { Serial.print("."); }
}
Serial.println();
}

void loop(){ //main cycle
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > LOG_PERIOD){
previousMillis = currentMillis;
cpm = counts * multiplier;
counts = 0; // reset counter just as timing for next cycle has already started!
if (cpm > 50000) { cpm = 0; } // trap to stop runaway readings getting uploaded.
usvh = cpm * CONV_FACTOR;
Serial.print("CPM: ");
Serial.println(cpm);
Serial.print("uSv/h: ");
Serial.println(usvh);
Serial.print('\n'); // Carriage Return

// convert cpm into a string ready to transmit
String v = String(cpm);

// send the reading to the web service

Serial.println("Connecting...");
if (client.connect(server, 80)) {
Serial.println("Connected!");

// UPDATE YOUR RADMON.ORG USERNAME AND PASSWORD HERE:
client.print("GET /radmon.php?function=submit&user=YOUR_USERNAME&password=YOUR_PASSWORD&value=");

client.print(v);
client.println("&unit=CPM HTTP/1.1");
client.println("Host: radmon.org");
client.println("User-Agent: testing-my-arduino-ethernet-geiger-counter-board");
client.println("Connection: close");
client.println();
// wait for a response and print it to serial
delay(2000);
ccount = 0; // character count
okflag = 0; // reset OK detect state machine state
while (client.available()) {
char c = client.read();

if (ccount > 15 && okflag == 0 && c == 'O') { okflag = 1; } else {
if (ccount > 15 && okflag == 1) {
if (c == 'K') { okflag = 2; } else { okflag = 0; }}}
ccount+=1;
}
if (okflag == 2) {
Serial.println("Accepted!");
digitalWrite(SLED, LOW); // turn LED off for 1 second to show everything is working!
delay(2000);
digitalWrite(SLED, HIGH); // turn LED back on
}
Serial.println();
client.stop();
} else {
Serial.println("Not able to connect. Will try again next cycle!");
client.stop();
}
}

}

 
Last edit: 2 years 6 months ago by rootsolutions.
The following user(s) said Thank You: mw0uzo

Please Log in or Create an account to join the conversation.

More
2 years 6 months ago #6150 by diegok
Hola, como estas, una pregunta esta todo bien en tu contador geiger? porque tenes valores muy altos de CPM, yo estoy cerca de Montevideo y tengo valores de background normales
saludos

Please Log in or Create an account to join the conversation.

More
2 years 6 months ago #6151 by rootsolutions
mirate este video que armamos con cevicas, en mar del plata tambien hay picos, a ver si la gente se anima a comprar una placa geiger y aunque sea la instalan en windows, asi tenemos mediciones en todo el pais



Si viste!
es la zona y las cosas que estan pasando,
lo tengo dentro de mi casa al lado de una ventana.

Please Log in or Create an account to join the conversation.

More
2 years 6 months ago #6152 by manuelgomez1
Bienvenidos, nuevos usuarios del cono sur!
Los picos en su contador son casi seguro un problema en la construcción del contador, quizás en la calibración al momento de censar los pulsos con otra placa y enviarlos a Radmon (me ocurrió ese mismo problema al momento de construir el mio, ya que el elevado ruido y voltaje confundían al ESP y contaba 200 de fondo cuando el conteo real era de 20). En especial si el tubo es un SBM-20 o similar; 8500 pulsos en un tubo de ese tipo son casi 50 microsievert (fuera del reactor de Chernobyl hay 15 µSv).
Al contrario de lo que mencionas en el video, si existen monitores ambientales de este tipo en Argentina, somos un país nuclear, es normativo hacerlo. La información de los mismos no se publica, pero un pico de 50 µSv haría saltar muchas alarmas...
Ademas, a la distancia que estas del tren como una fuente teórica de la contaminación, es imposible que te llegue semejante cantidad (y el maquinista habría muerto).

Please Log in or Create an account to join the conversation.

More
2 years 6 months ago #6154 by diegok
Probaste de irte con el geiger a otra zona? porque podria haber algo en tu casa o cerca, me parece raro, yo lleve una vez el geiger a caba y no habia nada fuera de lo normal,

Please Log in or Create an account to join the conversation.

More
2 years 6 months ago #6158 by rjelbert
Hi - that's the code I wrote :-) Glad it is useful. Best to check back on github every so often because I'm likely to make minor changes. It's not the neatest code but works. See: github.com/rjelbert/geiger_counter

Please Log in or Create an account to join the conversation.

Moderators: Gamma-Man
Time to create page: 0.226 seconds
Powered by Kunena Forum
Everything's free. Please support us by considering a donation. Log in first!
Solar powered Raspberry Pi 4 server stats: CPU 33% Memory 14% Swap 17% CPU temp=49.1'C Uptime 9 Days