For this step I'll assume that you already have Arduino IDE installed. (if not, you can check out http://arduino.cc/en/Guide/Windows on a tutorial on how to do just that.



Upload the code below to the Arduino board, mount the LCD screen.



Note: We're using an "eBay LCD keypad shield" with pinout defined as lcd(8, 9, 4, 5, 6, 7).

If you're using another LCD, you might need to adjust the LCD connection pin numbers in the code.



This is the code we used:



#include <LiquidCrystal.h> // includes necessary library

int INPIN = 2; // input pulses on pin 2

int buttonPin = A0; // input button on pin A0

LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // connections to LCD

int OUTPIN = 3; // output pulses on pin 3

volatile long int numint = 0; // counter for input pulses

int safevalue =500; // initial value of number of pulses considered safe

void intservice(void) // this is called for every input rising edge

{

numint++;

}



void setup() {

pinMode (buttonPin, INPUT);

pinMode(INPIN, INPUT);

pinMode (OUTPIN, OUTPUT);

digitalWrite(OUTPIN, HIGH);

digitalWrite(INPIN, LOW);

attachInterrupt(0, intservice, RISING); // attach interrupt routine

lcd.begin(8,2);

lcd.clear();

Serial.begin(9600);

}



void loop() {

int avalue;







lcd.setCursor(0, 0);

lcd.print(numint); lcd.print("cps"); lcd.print(" "); //print number of pulses in counts per second(cps)

lcd.setCursor(0,1);

avalue= analogRead(buttonPin); //variable for button input





if (120<avalue && avalue<150 &&(safevalue >=0 && safevalue < 1000)) {safevalue=safevalue+100; goto finish;} //upon pressing the up button, safevalue increases by 100 while lower than 1000

if (270<avalue && avalue<320 &&(safevalue > 0 && safevalue <= 1000)) {safevalue=safevalue-100;} //upon pressing the down button, safevalue decreases by 100 while lower than 1000



if (120<avalue && avalue<150 &&(safevalue >=1000 && safevalue< 10000)) {safevalue=safevalue+500;} //upon pressing the up button, safevalue increases by 500 while higher than 1000, up to 10000

if (270<avalue && avalue<320 &&(safevalue > 1000 && safevalue<=10000)) {safevalue=safevalue-500;} //upon pressing the down button, safevalue decreases by 500 while higher than 1000

finish:



lcd.print(safevalue); lcd.print(" "); //prints current safevalue

numint=0; // zero counter

delay(1000);



if (numint > safevalue){digitalWrite(OUTPIN, LOW); // beeper beeps if pulse count is higher than allowed

delay(10);

digitalWrite(OUTPIN, HIGH);

}

else {digitalWrite(OUTPIN, HIGH);}



Serial.println(numint); // print pulse count to serial



}



This code programs the Arduino to count gamma-rays (or other energetic stuff that dumps at least some 20keV at a time in the crystal) detected by the scintillation detector, in counts per second (cps). It will also send a signal to the beeper (that we will be connecting in the next step) if the value is higher than a selected "safe" cps level. You can change the preset safe value by pressing the up/down button on the LCD Keypad Shield. Events can also be monitored an a computer via a serial monitor when the Arduino board is connected to the PC via a USB cable.



Note: We will be using a USB cable to power the Arduino. If you want to make the whole thing portable, follow these instructions to power the Arduino from a battery, or simply buy a soldered one online.





