Example Code for Arduino-Radiation Intensity Detection
Last revision 2026/01/07
Detect CPM radiation intensity, the readings may have a large deviation at first, and the data tends to be stable after 3 times. Users can learn how to use the Gravity: Geiger Counter Module with Arduino, read CPM (counts per minute) and radiation intensity values (nSv/h, μSv/h), and understand the use of external interrupts for counting.
Hardware Preparation
- DFRduino UNO R3 (or similar) x 1
- Gravity: Geiger Counter Module x1
- Gravity 3Pin Connector x1
Software Preparation
Wiring Diagram

The Geiger counter library needs to use external interrupts for counting, so it can only be connected to external interrupt pins.
On Arduino UNO, the external interrupts are pins 2 and 3. For other development boards, please refer to the development documentation.
Arduino Development Board External Interrupts Reference Document
Other Preparation Work
Ensure the Geiger counter module is connected to the correct external interrupt pins of the Arduino board. For Arduino UNO, use pins 2 or 3.
Sample Code
/*!
@file geiger.ino
@brief Detect CPM radiation intensity, the readings may have a large deviation at first, and the data tends to be stable after 3 times
@copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
@licence The MIT License (MIT)
@author [fengli]([email protected])
@version V1.0
@date 2021-9-17
@get from https://www.dfrobot.com
@https://github.com/DFRobot/DFRobot_Geiger
*/
#include <DFRobot_Geiger.h>
#if defined ESP32
#define detect_pin D3
#else
#define detect_pin 3
#endif
/*!
@brief Constructor
@param pin External interrupt pin
*/
DFRobot_Geiger geiger(detect_pin);
void setup()
{
Serial.begin(115200);
//Start counting, enable external interrupt
geiger.start();
}
void loop() {
//Start counting, enable external interrupt
//geiger.start();
delay(3000);
//Pause the count, turn off the external interrupt trigger, the CPM and radiation intensity values remain in the state before the pause
//geiger.pause();
//Get the current CPM, if it has been paused, the CPM is the last value before the pause
//Predict CPM by falling edge pulse within 3 seconds, the error is ±3CPM
Serial.println(geiger.getCPM());
//Get the current nSv/h, if it has been paused, nSv/h is the last value before the pause
Serial.println(geiger.getnSvh());
//Get the current μSv/h, if it has been paused, the μSv/h is the last value before the pause
Serial.println(geiger.getuSvh());
}
Result
Upload the program and open the serial monitor to view the output results. The reading takes about half a minute to stabilize. The serial monitor will display the current CPM, nSv/h, and μSv/h values.
Additional Information
Since the Geiger counter uses external interrupts, other programs that are being executed by the Arduino are suspended when the output signal triggers the interrupt. If the I/O pin is being operated to communicate with other devices, a sudden insertion of an interrupt may cause a communication error. The Geiger counter library provides a pause counting function to temporarily turn off external interrupts to avoid the impact.
//Pause count
geiger.pause();
//restore count
geiger.start();
geiger.pause(); Keeps radiation readings in their last state before pausing until geiger.start(); is executed to continue counting.
Pausing the count will affect the measurement accuracy, please only pause when necessary.
Was this article helpful?
