Online geiger counter using Arduino and Cacti

I have always had an above average interest in radioactivity.  It’s a subject with political, sociological and scientific aspects. I have been mostly interested in the scientific part, but I also closely follow any news and other developments. With the earthquake in Japan and the following nuclear disaster the discussion about nuclear energy has  been fired up after being quite silent for years. In the Netherlands there was talk about building a new reactor next to the existing plant in Borssele. Well, I guess it will be a bit harder now to get support for this plan…

To be honest, watching the developments with the damaged reactors in Japan got me thinking again. Is nuclear energy a proper way of generating electricity? Sure,  for the immediate surroundings it is very clean. There are virtually no CO2 emissions and with proper shielding and maintenance you’ll need some pretty advanced equipment to measure any radioactivity coming from a reactor. Still, uranium mining is not very nice for the environment and there is no clear solution for storage of waste. And, if a reactor malfunctions there is the possibility of widespread contamination as currently seen in Japan. So, while I am not against nuclear energy my support for it has weakened somewhat.

Anyway, enough rambling, how to monitor radiation with your computer!

Update 18/4: Guess I am not the only one doing some monitoring: http://radgoes.blogspot.com

 

Geiger counter setup

I earlier built a geiger counter using the following circuit: http://letsmakerobots.com/node/18220 It’s an easy circuit because apart from high voltage capacitors and diodes most parts are fairly standard. The circuit has a 555 pulse shaper that converts the pulses from the tube into nice 0-5V signals. It’s also adjustable, not completely in the way I wanted, but by using the variable resistor and tapping into the end or the middle of the high voltage cascade I can get various voltages for different tubes. Most tubes will run at 400-500 volts.

I acquired tubes by buying an old German FH40T counter. It didn’t work properly anymore so I disassembled it for the parts, mainly the three tubes that come with it. The €40 it cost me is a nice deal even if you only get the tubes which can cost up to €23 separately. It comes with 2 low range (1R/hr)  tubes and one high range tube (50R/hr). The high range tube is of course less interesting but still a working tube for testing purposes. The sensitive tubes have the part number FH76V. Actually, according to the CDV-700 Club on Yahoo they are repackaged LND713 tubes. Specifications can be found here.

To connect the tubes to the circuit I had to get +500V out of it. At the end of the cascade the voltage was too high so I tapped into the middle of the high voltage cascade and with R5 and a high voltage adapter for my DMM I adjusted the supply to the correct voltage. To measure HV properly with your DMM you can build a HV probe cheaply using the following circuit.

By the way, watch out with high voltages. Even if the circuit is off, capacitors will retain charge, so discharge capacitors by shorting them before working on the circuit!

The circuit didn’t trigger the 555 properly so I made some modifications. I soldered a 50K potmeter over R12 to adjust the voltage of the pulsed fed into the 555. If everything is working, each pulse will be shaped and converted into nice pulses of 0V since the circuit inverts the signal from the tube. This seems to be a best practice for supplying pulses to a microcontroller because it provides a test signal, if there are no pulses the signal will be 5V, proving that the counter is actually on.

Arduino and Linux interfacing

If everything is working OK you can connect it to the Arduino. Since the circuit runs on 5V I was able to power it from the 5V supply of the Arduino itself.  Counts from pin 3 of the 555 are connected to pin 3 of  the Arduino, interrupt 1. The Arduino runs the following program:

long count = 0;
long timer = 0;

void setup() {
Serial.begin(9600);
attachInterrupt(1, counter, FALLING);

}

void loop() {
 lcd.setCursor(0,0);
 if (millis() - timer > 5000){
 Serial.println(count);    
 timer = millis();
 }

}

void counter()
{
 count++;
}

This simple program increments a counter each time the interrupt is triggered. Each 5 seconds it  prints this counter to the virtual serial port of the Arduino. If you monitor the serial port you should see the counter being printed each 5 seconds.

Note: this is a simple program, the long value count will overflow after 2147483647 counts. This number will be reached more quickly when measured radiation is higher. It shouldn’t be a big problem,  it will overflow after 510 years with my current measured background radiation.

Another note: To prevent the Arduino from resetting when the serial port is read, put a 10 microfarad capacator between the RESET and GND pins on the Arduino.

To log the value on my Linux server the following script waits for output from the serial port (will be autodetected when Arduino is connected) and logs the count with a timestamp, This script is run permanently by starting it with /usr/local/bin/getcountserial&

Script at /usr/local/bin/getcountserial

#!/bin/bash
while true
do
read LINE < /dev/ttyUSB0
echo $(date) >> /var/log/gmcount.log
echo $LINE >> /var/log/gmcount.log
done

To make interfacing with Cacti easy, I made another script that reads out the last line of the script:

Script at /usr/local/bin/getcount

#!/bin/bash
value=$(tail -1 /var/log/gmcount.log)
echo $value

This script is coupled to SNMP by adding the following line to /etc/snmp/snmpd.conf:

extend .1.3.6.1.4.1.2021.2000.4 gmc /usr/local/bin/getcounts

When this OID is read by snmpwalk, you will get the following output (rest of output snipped) :

UCD-SNMP-MIB::ucdavis.2000.4.4.1.2.3.103.109.99.1 = STRING: "32129"

Again, as in my Cacti temperature monitoring setup, use the most unique OID to get the value.

If the counts are properly registered, the rest is quite simple. Create a graph of a single OID, an instruction can be found here. There is a small change. The graph assumes data is per second, while the counts are measured over 5 minutes and need to be expressed in CPM, counts per minute. To get proper values I did the following: I duplicated the Generic OID template and named it CPM – Counts per Minute. I created a CDEF to convert the values from counts per second to CPM. I then coupled this CDEF to all the graph elements in the graph template.  I also added a comment to roughly convert CPM to microSieverts per hour.

You can find the live graph here: http://ruthenium.dyndns.org/graphs/graph_61.html

Final note: This is a crude setup and after completing it discovered it needs some tuning. It can be made more robust by getting the Arduino put out the actual measured CPM instead of the counts. That way the server still gets proper values even when it is restarted. When the Arduino is reset the counter will be reset to zero and Cacti will record a nice “radiation spike”  because it will see a large difference between the last recorded count and the zero value.