const int geigerPin = 2; // the pin number connected to the Geiger counter output
volatile int count = 0; // variable to count the number of pulses
void setup() {
// put your setup code here, to run once:
pinMode(geigerPin, INPUT); // set Geiger counter pin as input
Serial.begin(9600); // initialize serial communication
attachInterrupt(digitalPinToInterrupt(geigerPin), pulseCount, FALLING); // interrupt on falling edge of Geiger counter pulse
pinMode(13, OUTPUT);
pinMode(5, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
delay(60000); // wait for 1 minute
detachInterrupt(digitalPinToInterrupt(geigerPin)); // disable interrupt
float cpm = count; // * 60.0 / 60000.0; // calculate counts per minute -- this seems wrong
// Serial.print(cpm); // print counts per minute //
Serial.println(cpm); // print counts per minute
count = 0; // reset count
attachInterrupt(digitalPinToInterrupt(geigerPin), pulseCount, FALLING); // re-enable interrupt
}
void pulseCount() {
count++; // increment pulse count
digitalWrite(13, HIGH);
tone(5, 3800, 5);
delay(50);
digitalWrite(13, LOW);
}
Powershell:
# Configure serial port settings
$port = new-Object System.IO.Ports.SerialPort COM3,9600,None,8,one
# Loop indefinitely
while ($true) {
# Read integer from serial port
$port = new-Object System.IO.Ports.SerialPort COM3,9600,None,8,one
$port.Open()
$number = $port.ReadLine()
# Write number to file
$path = "\\samba\dean\web\counts.csv"
$timestamp=get-date -format s
# // $NewLine = "{0},{1}" -f $date,$number
# Format the data as a CSV string
$data = "{0},{1}" -f $timestamp , $number.Trim()
#// $NewLine | add-content -path $file
# $string=$date,$number
# //Add-Content $path $string
# Append the data to the file
Add-Content $path $data
echo $data
$port.Close()
}