Devices & Components
Arduino Uno Rev3
DC-DC 1.5-3V to 300-400V 380V High Voltage Boost Step-up Voltage Inverter Module
SunFounder IIC I2C TWI Serial 2004 20x4 LCD Module Shield for Arduino Uno Mega2560
STS-5 Geiger Muller Tube
Hardware & Tools
Breadboard, 270 Pin
Soldering iron (generic)
Project description
Code
Code
arduino
1#include <LiquidCrystal_I2C.h> 2#include <Wire.h> 3 4unsigned long counts; //variable for GM Tube events 5unsigned long previousMillis; //variable for measuring time 6float averageCPM; 7float sdCPM; 8int currentCPM; 9float calcCPM; 10LiquidCrystal_I2C lcd(0x27, 20, 4); 11float CPMArray[100]; 12 13#define LOG_PERIOD 30000 // count rate (in milliseconds) 14 15void setup() { //setup 16 counts = 0; 17 currentCPM = 0; 18 averageCPM = 0; 19 sdCPM = 0; 20 calcCPM = 0; 21 lcd.init(); 22 lcd.backlight(); 23 Serial.begin(9600); 24 pinMode(2, INPUT); 25 attachInterrupt(digitalPinToInterrupt(2), impulse, FALLING); //define external interrupts 26} 27 28void loop() { //main cycle 29 lcd.setCursor(0,2); 30 lcd.print("CPM Count: "); 31 lcd.print(counts); 32 unsigned long currentMillis = millis(); 33 if (currentMillis - previousMillis > LOG_PERIOD) { 34 previousMillis = currentMillis; 35 CPMArray[currentCPM] = counts * 2; 36 lcd.clear(); 37 lcd.setCursor(0,0); 38 lcd.print("uSv/hr: "); 39 lcd.print(outputSieverts(CPMArray[currentCPM])); 40 counts = 0; 41 averageCPM = 0; 42 sdCPM = 0; 43 //calc avg and sd 44 for (int x=0;x<currentCPM+1;x++) { 45 averageCPM = averageCPM + CPMArray[x]; 46 } 47 averageCPM = averageCPM / (currentCPM + 1); 48 for (int x=0;x<currentCPM+1;x++) { 49 sdCPM = sdCPM + sq(CPMArray[x] - averageCPM); 50 } 51 sdCPM = sqrt(sdCPM / currentCPM) / sqrt(currentCPM+1); 52 53 Serial.println("Avg: " + String(averageCPM) + " +/- " + String(sdCPM) + " ArrayVal: " + String(CPMArray[currentCPM])); 54 currentCPM = currentCPM + 1; 55 displayAverageCPM(); 56 } 57} 58 59void impulse() { 60 counts++; 61} 62void displayAverageCPM() { 63 lcd.setCursor(0,1); 64 lcd.print("Avg: "); 65 lcd.print(outputSieverts(averageCPM)); 66 lcd.print("+/-"); 67 lcd.print(outputSieverts(sdCPM)); 68} 69float outputSieverts(float x) { 70 float y = x * 0.0057; 71 return y; 72}
Downloadable files
Schematic.
Schematic is weird so when you open with Fritzing, things are moved around for some reason.
Schematic.
Schematic.
Schematic is weird so when you open with Fritzing, things are moved around for some reason.
Schematic.
Comments
Only logged in users can leave comments