Indice articoli

 *  ------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
*/

// include the library code:
#include

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(3,4,5,6,7,8);


// Threshold values for the led bar
#define TH1 50
#define TH2 150
#define TH3 300
#define TH4 600
#define TH5 900

// Variables
int ledArray [] = {9,13,12,11,10};
int geiger_input = 2;
int count = 0;
int countPerMinute = 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);

//set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Radiation Sensor");
lcd.setCursor(0,1);
lcd.print("Board - Arduino");
delay(4000);

lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Cooking Hacks");
delay(4000);

lcd.clear();
lcd.setCursor(0,1);
lcd.print("www.cooking-hacks.com");
delay(1000);
for (int i=0;i<5;i++){
delay(500);
lcd.scrollDisplayLeft();
}
delay(1000);

lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" - Libelium -");
lcd.setCursor(0,1);
lcd.print("www.libelium.com");
delay(4000);

lcd.clear();
lcd.setCursor(0, 0);
lcd.print("CPM=");
lcd.setCursor(4,0);
lcd.print(6*count);
lcd.setCursor(0,1);
lcd.print(radiationValue);

attachInterrupt(0,countPulse,FALLING);

}

void loop(){
if (millis()-timePreviousMeassure > 10000){
countPerMinute = 6*count;
radiationValue = countPerMinute/360.0;
timePreviousMeassure = millis();
Serial.print("cpm = ");
Serial.print(countPerMinute,DEC);
Serial.print(" - ");
Serial.print("uSv/h = ");
Serial.println(radiationValue,4);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("CPM=");
lcd.setCursor(4,0);
lcd.print(countPerMinute);
lcd.setCursor(0,1);
lcd.print(radiationValue,4);
lcd.setCursor(6,1);
lcd.print(" uSv/h");

//led var setting
if(countPerMinute <= TH1) ledVar(0);
if((countPerMinute <= TH2)&&(countPerMinute>TH1)) ledVar(1);
if((countPerMinute <= TH3)&&(countPerMinute>TH2)) ledVar(2);
if((countPerMinute <= TH4)&&(countPerMinute>TH3)) ledVar(3);
if((countPerMinute <= TH5)&&(countPerMinute>TH4)) ledVar(4);
if(countPerMinute>TH5) ledVar(5);

count = 0;

}

}

void countPulse(){
if(timePrevious != millis()){
count++;
time = millis()-timePrevious;
timePrevious = millis();
}
}

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);
}
}
}