Arduino/Cacti Geiger counter update

My online geiger counter which I described earlier has been offline for some time. During that time I experimented with a standalone Arduino with the goal of making a dedicated board for the setup. I have now completed the board shown in the picture below.

In the picture you can see the HV generator on the top of the board, on the lower left the Arduino standalone parts along with a MAX232 as a level converter for easy serial hookup and on the right two tubes connected in parallel, a SI-29BG (beta and gamma) and a SI-12B for added alpha sensivity. Also shown are the USB>Serial adapter and a separate USB connector to provide 5V to the board.

I have had it running for some weeks with a Russian SI-29BG hard beta and gamma tube. These are nice, very sturdy tubes to experiment with. They easily detect natural background radiation and K-40 from a bag of Potassium Chloride.As I already explained I have connected two tubes in parallel. There wasn’t that much variation in background radiation, (see below) even after heavy rainfall so I am now going to watch whether alpha sensivity makes any difference.

Also, the SI-12B is kind of useless on its own, it is not very sensitive to beta and gamma but is able to detect alpha quite well due to its mica window.

Scripting

I have also changed my scripting on both Linux and Arduino to make everything easier to test and make it fail gracefully when the counter stops functioning for some reason. It also now works in Cacti with a GAUGE type of data, not a counter. This prevents spikes when the counter is reset or temporarily disconnected or offline. The script is as follows:

#!/bin/bash
# serial gmcounter update & log script
LOGFILE=/var/log/gmcount.log

function getcounts {
# display last 5 minute counts
# check if log was updated within 6 minutes
if [ `find $LOGFILE -mmin -6` ]
then
# print last 5 minute count
tail -n 1 $LOGFILE | awk {' print $5'}
else
echo "Error - logfile too old"
fi
}

function log {
# read counts from serial and write to logfile
read LINE < /dev/ttyUSB0
echo $(date) >> $LOGFILE
echo $LINE >> $LOGFILE
}

# check arguments and display or log data
if [ "$1" = "" ]
then
echo 'Use "getcounts" to display counts or "log" to log counts'
fi

if [ "$1" = "getcounts" ]
then
getcounts
fi

if [ "$1" = "log" ]
then
log
fi

I have put everything in one script and created functions to log the counts overĀ  the last 5 minutes or display the last logged 5 minute count. If the logfile wasn’t updated properly it will return an error, causing Cacti to not record a value and show the error in its logfile. The script is connected to SNMP as described in my original article.

The Arduino script is as follows:

unsigned long counts = 0;
unsigned long fivemcount = 0;
long timer = 0;
long fivemtimer = 0;

void setup() {
Serial.begin(9600);
Serial.println("serial gm counter v1.0 starting...");
attachInterrupt(1, counter, FALLING);

}

void loop(){

if (millis() - fivemtimer > 300000){
 fivemcount = counts;
 counts = 0;
 fivemtimer = millis();
}
 if (millis() - timer > 10000){
 Serial.print("counts, cur: ");
 Serial.print(counts);
 Serial.print(" total: ");
 if (fivemcount == 0){
 Serial.println("n/a");
 }
 else {
 Serial.println(fivemcount);
 }
 timer = millis();
 }

}

void counter()
{
 counts++;
 tone(8,5000,1);
}

Basically, it counts the pulses, outputs the last five minute count every 10 seconds using the serial port and clears the counter after 5 minutes preventing any overflows of the unsigned long value (very unlikely). It also gives a very short tone with each interrupt which results in a little clicking sound. The random clicking helps me get to sleep quicker ;).

BTW, the current graph can be found here.

 

 

 

 


Comments are closed.