My Cart

How to Turn On/Off the LED Bar of the Radiation Sensor Board Using Radiation Geiger Kit

Difficulty Level: Beginner -

1. Introduction

This tutorial allows the user to turn ON and OFF the LED bar of the Radiation Sensor Board with a pushbutton.

Ingredients:

    - 1 x Radiation Geiger Kit:
    • 1x Platform
    • 1x Geiger Counter - Radiation Sensor Board
    • 1x GPRS antenna
    • 3x Buttons
    • 3x 220Ω resistors
    • 1x LCD
    • 1x Potentiometer
    • 1x Breadboard
    • 1x External power supply
    • 1x Programming cable
    • Jumper Wires

Preparation Time: 30 minutes

Buy now
NOTE: Depending on the platform chosen to develop the project, the ingredients and the schematics shown in this tutorial can vary.

This project can be developed with Arduino or Intel Galileo. It is also compatible with Raspberry Pi using the Raspberry Pi to Arduino shields connection bridge.

For further information about the Geiger Counter - Radiation Sensor Board, consult the main tutorial.

Step 1: Connection

Connect the Geiger tube to the Radiation Sensor Board and then, connect the shield to the Arduino or to Raspberry Pi connection bridge. Connect the button with the resistor in the breadboard as you can see in the next diagram.

Connect two wires, red and black, to the two long rows on the side of the breadboard to provide access to the VCC supply (5V in Arduino and 3.3V in Raspberry Pi) and ground. Then, connect analog pin 0 to one leg of the pushbutton. That same leg of the button connects through a pull-down resistor to ground. The other leg of the button connects to the VCC. When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton, so the pin is connected to ground (through the pull-down resistor) and reads as LOW, or 0. When the button is closed (pressed), it makes a connection between its two legs, connecting the pin to VCC, so that the pin read as HIGH, or 1.

Step 2: The Code

Arduino:

Code:
/*  
 *  Geiger Counter - Radiation Sensor Board
 *  
 *  Copyright (C) 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 3 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 http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Marcos Martinez
 */

// include the library code:
#include <LiquidCrystal.h>

// 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 45
#define TH2 95
#define TH3 200
#define TH4 400
#define TH5 600

// Conversion factor - CPM to uSV/h
#define CONV_FACTOR 0.00812

// Variables
int ledArray [] = {
  10,11,12,13,9};
int geiger_input = 2;
long count = 0;
long countPerMinute = 0;
long timePrevious = 0;
long timePreviousMeassure = 0;
long time = 0;
long countPrevious = 0;
float radiationValue = 0.0;

int button = 14;
boolean buttonState = true;
boolean lastButtonState = false;

boolean state1 = true;
boolean state2 = false;

void setup(){

  pinMode(button, INPUT);
  digitalWrite(button, LOW);

  pinMode(geiger_input, INPUT);
  digitalWrite(geiger_input,HIGH);
  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(1000);

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

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

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

  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(){

  buttonState=digitalRead(button);
  delay(10);
  if (buttonState && !lastButtonState){
    state1=!state1;
    state2=!state2;

    if (state1) {  
    
      //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;     
    } 
    if (state2){ 
      
      //Turn OFF led var 
      digitalWrite(13,LOW);
      digitalWrite(12,LOW);
      digitalWrite(11,LOW);
      digitalWrite(10,LOW);
      digitalWrite(9,LOW);

    }
    lastButtonState=buttonState;
  } 
  else{
    lastButtonState=buttonState;
  }

  if (millis()-timePreviousMeassure > 10000){
    countPerMinute = 6*count;
    radiationValue = countPerMinute * CONV_FACTOR;
    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");

    if (state1) {  
      
      //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(){
  detachInterrupt(0);
  count++;
  while(digitalRead(2)==0){
  }
  attachInterrupt(0,countPulse,FALLING);
}

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


        

Raspberry Pi:

Code:
/*  
 *  Geiger Counter - Radiation Sensor Board
 *  
 *  Copyright (C) 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 3 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 http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Jorge Casanova, Luis MartĂ­n
 */

//Include arduPi library
#include "arduPi.h"

void countPulse();
void ledVar(int value);

// Threshold values for the led bar
#define TH1 45
#define TH2 95
#define TH3 200
#define TH4 400
#define TH5 600

// Conversion factor - CPM to uSV/h
#define CONV_FACTOR 0.00812

// Variables
int ledArray [] = {
  10,11,12,13,9};
int geiger_input = 2;
long count = 0;
long countPerMinute = 0;
long timePrevious = 0;
long timePreviousMeassure = 0;
long countPrevious = 0;
float radiationValue = 0.0;

boolean buttonState = true;
boolean lastButtonState = false;

boolean state1 = true;
boolean state2 = false;

void setup(){

  pinMode(geiger_input, INPUT);
  digitalWrite(geiger_input,HIGH);
  
  for (int i=0;i<5;i++){
    pinMode(ledArray[i],OUTPUT);
  }
  
  printf("Radiation Sensor Board - Raspberry\n");
  delay(1000);

  printf("Cooking Hacks - www.cooking-hacks.com\n");
  delay(1000);
   
  printf("Libelium - www.libelium.com\n");   
  delay(1000);
  printf("\n");  
   
  printf("CPM = %i\n",countPerMinute);
  printf("%f uSv/h\n",radiationValue);

  attachInterrupt(2,countPulse,FALLING);

}

void loop(){

  if (analogRead(0)>100) buttonState =true;
  else buttonState = false;
  delay(10);
  if (buttonState && !lastButtonState){
    state1=!state1;
    state2=!state2;

    if (state1) {  
    
      //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;     
    } 
    if (state2){ 
      
      //Turn OFF led var 
      digitalWrite(13,LOW);
      digitalWrite(12,LOW);
      digitalWrite(11,LOW);
      digitalWrite(10,LOW);
      digitalWrite(9,LOW);

    }
    lastButtonState=buttonState;
  } 
  else{
    lastButtonState=buttonState;
  }

  if (millis()-timePreviousMeassure > 10000){
    countPerMinute = 6*count;
    radiationValue = countPerMinute * CONV_FACTOR;
    timePreviousMeassure = millis();
    
	printf("CPM = %i\n",countPerMinute);
    printf("%f uSv/h\n",radiationValue);
    

    if (state1) {  
      
      //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(){
   count++;
}

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

int main (){
    setup();
    while(1){
        loop();
    }
    return (0);
}


        

Intel Galileo:

Code:
/*  
 *  Geiger Counter - Radiation Sensor Board
 *  
 *  Copyright (C) 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 3 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 http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Jorge Casanova, Luis MartĂ­n
 */
 
// include the library code:
#include <LiquidCrystal.h>

// 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 45
#define TH2 95
#define TH3 200
#define TH4 400
#define TH5 600

// Conversion factor - CPM to uSV/h
#define CONV_FACTOR 0.00812

// Variables
int ledArray [] = {
  10,11,12,13,9};
int geiger_input = 2;
long count = 0;
long countPerMinute = 0;
long timePrevious = 0;
long timePreviousMeassure = 0;
//long time = 0;
long countPrevious = 0;
float radiationValue = 0.0;

int button = 14;
boolean buttonState = true;
boolean lastButtonState = false;

boolean state1 = true;
boolean state2 = false;

void setup(){

  pinMode(button, INPUT);
  digitalWrite(button, LOW);

  pinMode(geiger_input, INPUT);
  digitalWrite(geiger_input,HIGH);
  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(1000);

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

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

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

  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(2,countPulse,FALLING);

}

void loop(){

  buttonState=digitalRead(button);
  delay(10);
  if (buttonState && !lastButtonState){
    state1=!state1;
    state2=!state2;

    if (state1) {  
    
      //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;     
    } 
    if (state2){ 
      
      //Turn OFF led var 
      digitalWrite(13,LOW);
      digitalWrite(12,LOW);
      digitalWrite(11,LOW);
      digitalWrite(10,LOW);
      digitalWrite(9,LOW);

    }
    lastButtonState=buttonState;
  } 
  else{
    lastButtonState=buttonState;
  }

  if (millis()-timePreviousMeassure > 10000){
    countPerMinute = 6*count;
    radiationValue = countPerMinute * CONV_FACTOR;
    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");

    if (state1) {  
      
      //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(){
      count = 0;
  timePreviousMeassure = millis();
  while (millis()-timePreviousMeassure < 10000)
  {
    if(digitalRead(geiger_input) == 0)
    {
      count++;
      while(digitalRead(geiger_input) == 0); // do nothing until pin goes back to HIGH
    }
  }
  
  
}

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