Components, NeoPixels, and Arduino IDE

A project log for Trinket EDC Radiation Detector

Using a Trinket Pro and Photodiode to detect gamma radiation.

eric-friedrichEric Friedrich 12/08/2014 at 03:240 Comments

Over the past week, Black Friday/Cyber Monday sales were a great excuse to purchase all the parts. The only things outstanding are a few 47pF caps that need a newark or mouser order. I'll post the formal component list later in the month once the schematic is finalized.

One mistake so far- I accidentally ordered a Trinket non-pro from Adafruit instead of the correct "Pro" part. Rather than pay $8 shipping to order a replacement, I bought a Pro-version off a fellow maker from the local Makerspace, so I know its got good juju.

I also took the opportunity to start populating the headers on the Neopixel board and the Trinket Pro, as well as to start writing some of the code.

The Neopixel display was also assembled this week, which basically came down to soldering three wires onto a PCB. It was harder than it sounds, because Adafruit was not nice enough to put through holes for connectors on the NeoPixel sticks. A coating of hot glue will help to reinforce the joints.

I basically had to solder the wires to the board twice, as the first round of wires had the wrong gender connectors on the other end. I soldered male connectors, when I needed females to connect with the header on the Trinket.

On the software side, my first task was to learn how to upload images to the Trinket Pro. After messing around with Linux for a few hours, I gave up and fell back to the pre-packaged OS X Trinket Pro Arduino IDE. This worked on the first try. I also wrote a quick program that will manage the LED display. With 8 LEDs, an "alert level" between 1 and 8 is provided to a function. This determines how many LEDs are lit up and the color of the LEDs. The colors progress from green (just one or two LEDs) up to red (all 8 LEDs). There is also a fade effect, which will slowly turn the LEDs off over the next 2 seconds.

 * Trinket Radiation Detector
 * Written for Adafruit Trinket Pro
 *  Uses a PN photodiode to detect gamma radiation. Radiation levels
 *  are displayed on an 8-pixel NeoPixel board. If things are especially
 *  hot, a vibrating motor activates to alert the wearer.
 * 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
 *   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 <>.
 * Copyright 2014 Eric Friedrich

#include <Adafruit_NeoPixel.h>

#define COUNTER_PIN 2
#define VIBRATE_PIN 3
#define NEOPIXEL_PIN 3

const uint32_t colorMap[8] = {

 * Track current state of the LED array 
#define NUM_PIXELS 8

static unsigned int lastLevel = 0;
static uint32_t lastLevelTime = 0;
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_PIXELS, NEOPIXEL_PIN);

 * Initialize NeoPixel library and global pixel state
void initPixels() {

void setup() {
  pinMode(VIBRATE_PIN, OUT);
  digitalWrite(VIBRATE_PIN, LOW);

 * Update NeoPixel strip with current radiation level.
 * @param level - 0 to 7 inclusive
void displayLevelOnPixels(unsigned int level) {  
  for (int i = 0; i <= level; i++) {
    pixels.setPixelColor(i, colorMap[level]);

  lastLevel = level;
  lastLevelTime = millis();;

void updatePixels() {
  uint32_t now = millis();
  uint32_t age = 12*(now - lastLevelTime)/1000;
  if (age > 24) {
  pixels.setBrightness(24 - age);;

void loop() {

  for (int i = 0; i <= 7; i++) {
    for (int j =0; j < 200; j++) {