/* * ------Geiger Tube board (Arduino Code) Example-------- * * Explanation: This example shows how to get the signal from the Geiger Tube * in Arduino, we use one of the Arduino interrupt pins (PIN2). * We count the time (ms) between two pulses of the Geiger tube. * * Copyright (C) 2011 Libelium Comunicaciones Distribuidas S.L. * http://www.libelium.com * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Version: 0.1 * Design: Marcos Yarza, David Gascon * Implementation: Marcos Yarza */ // Threshold values for the led bar #define TH1 75 #define TH2 150 #define TH3 400 #define TH4 600 #define TH5 900 // Variables int ledArray [] = {9,13,12,11,10}; int geiger_input = 2; int count = 0; long timePrevious = 0; long timePreviousMeassure = 0; long time = 0; int countPrevious = 0; float radiationValue = 0.0; void setup(){ pinMode(geiger_input, INPUT); for (int i=0;i<5;i++){ pinMode(ledArray[i],OUTPUT); } Serial.begin(19200); attachInterrupt(0,countPulse,FALLING); } void loop(){ // do nothing } void countPulse(){ if(timePrevious != millis()){ count++; time = millis()-timePrevious; timePrevious = millis(); if (millis()-timePreviousMeassure > 10000){ radiationValue = 6.0*count/360.0; timePreviousMeassure = millis(); Serial.print("cpm = "); Serial.print(6*count,DEC); Serial.print(" - "); Serial.print("uSv/h = "); Serial.println(radiationValue,4); count = 0; } // led var setting if(time <= TH1) ledVar(5); if((time <= TH2)&&(time>TH1)) ledVar(4); if((time <= TH3)&&(time>TH2)) ledVar(3); if((time <= TH4)&&(time>TH3)) ledVar(2); if((time <= TH5)&&(time>TH4)) ledVar(1); if(time>TH5) ledVar(0); } } void ledVar(int value){ if (value > 0){ for(int i=0;i<=value;i++){ digitalWrite(ledArray[i],HIGH); } for(int i=5;i>value;i--){ digitalWrite(ledArray[i],LOW); } } else { for(int i=5;i>=0;i--){ digitalWrite(ledArray[i],LOW); } } }