Using Arduino to process data from Geiger–Müller counters

In the previous posts I've described a simple Geiger–Müller counter and various experiments with this device. Today I would like to present Arduino project to communicate with a Geiger-Muller counter, gather data and present it to the user. The device is based on Arduino Uno, Nokia 5110 LCD and homemade shield.

Currently it's possible to show two layouts: bar graph of the pulses in one minute interval and histogram of the gathered data. Both graphs are auto-ranging in Y axis. On the top of the pulse graph is visible also a numeric value of the last sample. The length of the histogram data is 4 minutes, the amount of bins is calculated automatically.

Below is visible layout with pulses per quant of time and histogram of them. You can clearly observe Gaussian distribution on the second image.

Hardware

I didn't want to place all of the connections and input PCB dimensions of a shield, so I've used as a base one of freely available shields and modified it to my needs - I've left the licence disclaimer unmodified. Unfortunately, I wrongly connected LCD, that's why the LCD looks like rotated 180 degrees. Anyway, it still works and I don't plan to make a new PCB to fix it.

I tried to make the code reusable in my other projects so the structure may look overcomplicated, but I think it's as it should be.

Software

Followed 3rd party librairies needs to be installed, to install them in Arduino IDE go to sketch -> Include Library -> Manage Libraries then type library name and proceed with installation.

  • Adafruit-GFX-Library
  • Adafruit-PCD8544-Nokia-5110-LCD-library
The main component is the GMCounter class that collects data in a circular buffer. I wanted to pass as an argument a size of the buffer, but also wanted to avoid using dynamic memory, finally I made this parameter an argument of template class, so now creating an object of this class looks like:
 static GMCounter<4 * 24> hourGMCounter;

This will create an object with this class with a buffer for 4*24 samples. I think, that it's quite cool.

There's a lot of commented out code in the main function, it was used to test parts of the program as it was developed. I didn't remove it because it still can be used if I will add new features.

Download.

The source code and Eagle files of the project is available on the GitHub, feel free to download and try it if you're interested in this area of physic.

In the near future, I'm planning to add data logging into a SD card and display data also in one hour interval.

LED colors vs history of mankind

Plenty of electronic devices (even those inexpensive from the Far East) have some kind of LEDs to indicate the state of the device. A good example may be a stand-by LED on the on-off switch of many TVs, another would be power-on LED on many laptop power supplies. Depends on a type of information, different color of LEDs are used.

Usually green color says that the device is in good state and don't need attention, it's the default color for power-on indicators. Yellow is used to indicate that there are some information or some events that the user may want to check, but they are not critical. Red color shows that something was wrong, that user should pay attention to the current state and maybe made some actions.

This is also a question of a good user interface, especially now, when everything tends to use white or blue LEDs - they are something fresh, something that wasn't available a decade ago. Yes, maybe they are cool, but they are also non-intuitive. That's a different story.

It may sound strange, but the selection of greed-yellow-red colors is not an accident, but is based on thousand of years of our human history. Green is intuitively connected with leafs, forest, bushes, trees - places to hide, that are much more secure than an open space. In open space, it's much easier to be observed by predators. Red is the color of fire - danger that kills and destroys, especially before human kind learned how to handle it. A lot of poisonous plants have red fruits too. Yellow is often a skin color of toxic animals that says "don't eat me, I'm toxic, you will die - I warned you". It's a color of information.

Even devices that cost tens of thousands of dollars have those LEDs that have a color selected just because thousands of years ago our ancestors were living like today monkeys and we still keep those references! That's amazing!

I think that if some day advanced alien race would get one of our electronic devices and reverse engineering it, they could understand what it is, why we use it and how it works. One thing that they wouldn't be able to understand would be why we choose those colors. That would be only possible if they would analyse our natural environment and our history.

It won't end, a lot of software applications also use those colors or have some widgets that simulate LEDs. In addition, sometimes there are also GUI widgets that simulates knobs, switches and other mechanical elements - maybe we live in an era that adds another level of this inheritance? What about floppy disc icon used as "Save as"? Who have a floppy disc, yet we still have this icon in many applications.

BTW, it's also interesting that e.g. traditional caliper works only because our eye and mind has great ability to misalignment among two line segments, however, we suck in different areas of image recognition (e.g. checking perpendicularity). An alien could analyze a caliper, but without knowledge of the biology of a human eye and human brain activity, it could be only possible to make assumptions why we are using calipers and not some other ways to measure distances.

3.3V to 30V DC/DC converter using SN6505A

Recently I'v got my samples of SN6505A, it's a really nice IC, so I decided to make a simple DC/DC converter to get familiar with it. What I like in this chip is that it can operate on input voltage as low as 2,5V - that makes it great for battery devices. It's also nice, that it's a very minimalist design - on primary side all what is needed is decoupling capacitor. One disadvantage is that it doesn't have a feedback loop.

To increase efficiency, SN6505A can operate with more developed versions of transformers, but I used the simplest configuration - one coil on each side. The circuit is presented below. The chip as well as other components is mounted on the bottom side of the PCB.

Current consumption is 330mA at 3V3, this could be probably easily reduced by using different transformator.

Unfortunately I din't have neither suitable transformer nor appropriate coil to wind it. I made my own transformator from a solenoid coil as a secondary side, and 10 loops of 0,7mm wire as a primary side. The inductances are respectively 2u5H and 11m5H. Maybe it's not the most beautiful transformer and EMI will be terrible, but for this simple project it works ok.

Summarizing, that's a nice chip and probably I will use it in some of my projects in the future.

How to check how many elements an array has?

In C it's possible to omit typing array size if it's fields are provided immediately, so the compiler can easily calculate the size by itself. This is presented below, note empty [] parenthesis.

    char* sampleArray[] = {
        "Hello world!",
        "How are you?",
        "You like coffe?"
    };

We can also specify the size directly:

    char* sampleArray[2] = {
        "Hello world!",
        "How are you?",
        "You like coffe?"
    };

Or use the best way:

    const int SampleArraySize = 2;

    char* sampleArray[SampleArraySize] = {
        "Hello world!",
        "How are you?",
        "You like coffe?"
    };

In the first two examples we don't have a variable that would tell us how many elements the array has. Sure, we may hardcode it, but it's not a good idea from a maintainability point of view.

We may calculate the size of above array by using a simple trick:

int sampleArrayLength = sizeof(sampleArray) / sizeof(sampleArray[0]);

Note that it will work with all built in types and if the size or even the type of an array will be changed in the future, this line will still be correct.

Below you may see a simple use case.

#include <stdio.h>


int main()
{
    char* sampleArray[] = {
        "Hello world!",
        "How are you?",
        "You like coffe?"
    };

    int sampleArrayLength = sizeof(sampleArray) / sizeof(sampleArray[0]);

    printf("someStrings array has %d  elments counting from one.\n", sampleArrayLength);

    for(int i = 0U; i < sampleArrayLength; i++)
    {
        printf("#%d element: %s\n", i, sampleArray[i]);
        
    }
    
    return 0;
}
sh-4.3$ main                                                                                                                                                                                                                                            
someStrings array has 3  elments counting from one.                                                                                                                                                                                                     
#0 element: Hello world!                                                                                                                                                                                                                                
#1 element: How are you?                                                                                                                                                                                                                                
#2 element: You like coffe?

Unfortunately, it will not work for arrays passed as pointers - for them, we need to pass size of an array as an additional argument.

How to check how many elements an enum has?

While C language doesn't offer build in method to check how many elements an enum has, it's still possible to obtain this information by using a simple trick.

The idea is to add a dummy element at the very end, since numeric enums values are 0, 1, 2, 3, 4, 5, ..., the numeric value of last element will be also the amount of elements that this enum has.

#include <stdio.h>

typedef enum Fruit {
    FRUIT_APPLE,
    FRUIT_ORANGE,
    FRUIT_BLACKBERRY,
    /* place new elements below */
    
    /* guard */
    FRUIT_LAST_ELEMENT
} Fruit;

int main()
{
    int fruitEnumLength = (FRUIT_LAST_ELEMENT - 1);
    printf("Fruit enum has %d elments counting from zero.\n", fruitEnumLength);

    return 0;
}
sh-4.3$ gcc -o main *.c                                                                                                                                                                                                                                 
sh-4.3$ main                                                                                                                                                                                                                                            
Fruit enum has 2 elments counting from zero.  

This technique may be useful for sanitizing input data or for writing tests.

Hacking home weather station transmitter

Recently I've found this piece of electronic on the dumpster, it was looking interesting - compact case with battery holder, LCD display, temperature and humidity sensor. It has also radio transmitter, but I'm not interested in it since I don't have the receiver station. I decided to bring it back to life.

It seems that was previously immersed in water - whole PCB was covered in white stains, in addition radio transmitter was covered in wax, that made removing of its components much harder. At first multimeter hasn't shown shortcut of battery electrodes, but the device was drawing a lot of current, roughly 1A. I decided to clean it first using trisodium phosphate solution, then rework all of the joints with a lot of flux and clean it again. This fixed the problem of shortcut and the device started to work.

Unfortunately, while temperature readings were correlated with the environment, they were much too high. The temperature sensor is just a termistor, for those who want to see signals on its pins, below is a screen, as visible - current doesn't flow through this element all the time, only, when a measurement is made. This will probably save some battery life. Nice.

It's interesting that we may deduce how the measurement is done by the IC. It probably has a small capacitor loaded to Vcc, during the measurement, the capacitor is being connected to the sensor and discharged by it, the chip measures time to discharge the capacitor to 1V.

I don't know, why the measurements were incorrect, maybe the IC or the thermostat was damaged by the humidity, maybe [this is cheap Chinese consumer electronic] manufacturer run out of the correct thermistors and replaced them with new ones with different curve, or maybe those were cheaper than originals. I don't know. I decided to try to hack the curve of a thermostat by using serial and parallel resistors.

The problem is that I don't have thermal chamber, so I can't easily draw thermistor curve before and after the fix. I could improvise, but for such gadget I don't care. I've removed thermistor from the PCB, and soldered on its place electrodes, then I placed the thermistor on a breadboard, and tried different values of resistors. The room temperature was between 21-25°C - I could modify it by opening a window - maybe not the best way, but it works. My whole room had become a temperature chamber :)

Finally, I've added two resistors, as visible below. It works for room temperature, but for outdoor use it's still not good. Anyway, I will leave it as it is, at least for the moment.

I've also removed all components related to radio transmitter - no reason to waste battery. Electrolytic capacitors were replaced too. Worth to note is that they were rated for 105°C - were they genuine? I don't know :)

Making your own PCB cleaner mixture

Commercial PCB washing solutions are relatively expensive, much cheaper and still powerful one can be prepared at home. It's based on trisodium phosphate, highly alkaline substance able to reduce oxides and react with grass forming soaps. Soaps in chemical meaning, not something we buy at store.

A sample PCB smashed into two pieces - on the left original state, on the right washed up.

DIY water based PCB solvent: before and after

Ingredients

The procedure is simple - a PCB is just placed into the solution and shaken from time to time to speed up the cleaning. Heating is not needed.

I'm using a cheap ultrasonic washing machine - I still don't know if it's working or if it's just a placebo and a bit of a noise, but it seems that at least it mix the water. I've placed the mixture into a glass and then placed it into the water in the washing machine. This is less efficient, but device is easier to clean after use.

DIY water based PCB solvent: ingredients

Note: trisodium phosphate is highly alkaline - it's visible on below below on below universal indicator. Use protective glasses and gloves.

In case of skin contact, wash the solution wash it with a lot of water. In case of a skin contact with the powdered substance whip it by using a rug and then wash it.

DIY water based PCB solvent: universal indicator

Trisodium phosphate was widely used till 70's, it's an inexpensive and effective cleaning agent, but is not environmental friendly.