Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Ruslan Olkhovsky
Published © MIT

DIY Geiger Counter with SensorOcean

An easy way of building a connected Geiger Counter, collecting and publishing its measurements with the SensorOcean platform.

BeginnerFull instructions provided4 hours4,674
DIY Geiger Counter with SensorOcean

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
NodeMCU
×1
nRF24L01
×2
Geiger Counter Kit
×1

Software apps and online services

SensorOcean
MySensors

Story

Read more

Schematics

Arduino Nano + nRF24L01 + Geiger board

ESP8266 + nRF24L01

Code

Arduino Geiger Counter Sketch

Arduino
/*
 * Geiger Counter connected with
 * MySensors RF network (mysensors.org) and
 * SensorOcean controller (www.sensorocean.com)
 *
 * Created by Ruslan Olkhovsky <ruslanolkhovsky@gmail.com>
 *
 * This source code is free software. You can redistribute it and/or
 * modify it under the terms of the MIT License.
 */

// Enable debug prints to serial monitor
#define MY_DEBUG

// Enable and select radio type attached
#define MY_RADIO_RF24
#define MY_RF24_CHANNEL 64

// Define Node ID
#define MY_NODE_ID 1

// Sensor
#define GEIGER_CHILD_ID 1

#include <MySensors.h>
#include <TimeLib.h>

MyMessage msg_geiger(GEIGER_CHILD_ID, V_CUSTOM);

#define GEIGER_PIN  3

bool gotTime = false;
uint32_t WAIT_TIME = 10000; // Sleep time between reads (in milliseconds)

#include <SPI.h>
#define LOG_PERIOD 60000  //Logging period in milliseconds, recommended 15000-60000.
#define MAX_PERIOD 60000  //Maximum logging period

// Conversion Factor used for conversion from CPM to uSv/h units (J305 tube)
#define CONV_FACTOR 0.008120370

unsigned long counts;     //variable for GM Tube events
unsigned long cpm;        //variable for CPM
float uSvh;               //variable for uSv/h

unsigned int multiplier;  //variable for calculation CPM in this sketch
unsigned long previousMillis;  //variable for time measurement

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


void setup()
{
  // Setup locally attached sensors
  counts = 0;
  cpm = 0;
  multiplier = MAX_PERIOD / LOG_PERIOD;       //calculating multiplier, depend on your log period
  Serial.begin(115200);
  pinMode(GEIGER_PIN, INPUT);
  attachInterrupt(0, tube_impulse, FALLING);  //define external interrupts
  Serial.println("Start counter");

  //Sync time with the server
  requestTime();
  #ifdef MY_DEBUG
    Serial.println(F("Requesting time"));
  #endif
}


void presentation()
{
  Serial.print("Node: ");
  Serial.println(getNodeId());

  // Present locally attached sensors here
  sendSketchInfo("Geiger Counter", "0.1");
  present(GEIGER_CHILD_ID, S_CUSTOM, "Geiger (uSv/h)");

}


void loop()
{
  // if we don't have time , request it from controller
  if (gotTime == false) {
    requestTime();
    #ifdef MY_DEBUG
      Serial.println(F("Requesting time"));
    #endif
  }

  #ifdef MY_DEBUG
    time_t t = now();
    char buf[50];
    sprintf(buf, "%4d-%02d-%02d %02d:%02d:%02d ", year(t), month(t), day(t), hour(t), minute(t), second(t));
    Serial.print(buf);
    Serial.print(" ");
  #endif

  // Geiger counter
  unsigned long currentMillis = millis();
  if(currentMillis - previousMillis > LOG_PERIOD){
    previousMillis = currentMillis;
    cpm = counts * multiplier;
    uSvh = cpm * CONV_FACTOR;

    Serial.print("Counts: ");
    Serial.print(counts);
    Serial.print("   CPM: ");
    Serial.print(cpm);
    Serial.print("   uSv/h: ");
    Serial.println(uSvh);

    counts = 0;

    // Send message with the uSvh value to the MySensors gateway
    send(msg_geiger.set(uSvh, V_CUSTOM));
  }

  // delay until next measurement (msec)
  wait(WAIT_TIME);
}

// callback from MySensors controller
void receive(const MyMessage &message) {
  #ifdef MY_DEBUG
    Serial.print("Message received: ");
    Serial.println(message.type);
  #endif
}

// Time callback from MySensors controller
void receiveTime(unsigned long newTime)
{
  setTime(newTime);
  gotTime = true;
  #ifdef MY_DEBUG
    char buf[50];
    sprintf(buf, "%4d-%02d-%02d %02d:%02d:%02d ", year(newTime), month(newTime), day(newTime), hour(newTime), minute(newTime), second(newTime));
    Serial.println(buf);
  #endif
}

ESP8266 gateway with WiFiManager from SensorOcean

Credits

Ruslan Olkhovsky
2 projects • 6 followers
In the last few years, my passion has taken me to IoT and blockchain where I’ve been able to coordinate teams develop some innovative apps.
Contact

Comments

Please log in or sign up to comment.