Fun with a Programmable Flashlight

My experience researching the HexBright; an open source, Arduino programmable flashlight.

As part of my job as the technical researcher, I review pretty much every product and product proposal sent our way. If I think it's a cool product, I pitch it at the engineering meeting every Monday morning. This meeting more often then not consists of me pushing new products in an atmosphere similar to that of the TV show Shark Tank (Dragons' Den for those outside the US). I do my best to give each product a fighting chance when proposing it at this meeting which requires a lot of research. In addition, researching the product lets me figure out the cool points of the product that we should highlight from a marketing and product description standpoint.

HexBright Flex

So a couple months ago we were contacted by a company called HexBright regarding their product, the HexBright Flex. They bill the Flex as an open source, Arduino programmable flashlight. My first thought being "Program what? It's a flashlight". I started making more reasonable theories such as SOS patterns and such, but I still couldn't justify why someone would want a programmable flashlight. So I decided to check with some people who might know more about flashlights (one of the great things about working at SparkFun is no matter what the topic, someone here probably has an interest in it and can help you out). Their suggestion was to compare it with similarly priced flashlights and gave me a few recommendations.

Now I admit, I haven't had a use for a good flashlight in a while. I find my camping headlamp works fine for most stuff. So when I started looking at these flashlights, I was rather amazed. First, thanks to LED technology like Cree's X-Lamp LEDs, flashlights have become blindingly bright. It's absolutely amazing how bright flashlights can get for their size. The next thing I noticed was most of these flashlights were in these intense weather proof enclosures, which made sense. Then I saw the optional attachments, people go nuts with flashlights like this. In addition to your typical holsters and heavy duty clips, some of these flashlights had attachments that would weaponize them. One had a sharp-edge bezel that would make it similar to a bayonet. So I then turned to the operational features of these flashlights. There were a lot of features built in that made a lot of sense that I would not have thought to add to something simple like a flashlight.

Before we go any further, I need to point out when I get excited about something, I tend to lose some common sense. Rather than checking if the Flex had any of these operational features, my train of thought immediately went to "I wonder if I can program the Flex to do that?". This slight lapse in judgement and increase in excitement led me to start typing out small snippets of code blindly for each feature. If I had taken the time to check the code HexBright posted to their site or even just check the flashlight to see if it does what the other flashlights do, I would have noticed that most of the code I was writing was already implemented, in a much nicer fashion than I was coding.

HexBright Flex USB Micro B Port

The HexBright Flex is a flashlight with an on-board Arduino clone making it easy to add or customize features. In addition, there is an accelerometer allowing you to add features such as adjusting the brightness based on how the flashlight is tilted. A USB micro port handles the serial communication needed for programming the flashlight as well as charging the rechargeable batteries. With this knowledge in hand, I set out to replicate some of the nicer features of the Flashlights I was comparing it against.

The first feature I wanted to replicate was one involving the high setting of the flashlight. When at full power, the LED is a huge drain on the battery. If you forget to turn the flashlight off or just forget you have it on full power, you can drain a full battery in a couple of hours. To conserve battery life, some of the nicer flashlights had a feature built in which would drop the LED intensity to 70% if left on for more than 5 minutes. Enough to conserve battery life, but won't dim it too much if you actually need it really bright for more than 5 minutes. Since the Arduino needs a clock, including something like this shouldn't be too difficult of a task.

if (time-lastTempTime > 1000)
{
  lastTempTime = time;
  int temperature = analogRead(APIN_TEMP);
  Serial.print("Temp: ");
  Serial.println(temperature);
  if (temperature > OVERTEMP && mode != MODE_OFF)
  {
    Serial.println("Overheating!");

    for (int i = 0; i < 6; i++)
    {
      digitalWrite(DPIN_DRV_MODE, LOW);
      delay(100);
      digitalWrite(DPIN_DRV_MODE, HIGH);
      delay(100);
    }
    digitalWrite(DPIN_DRV_MODE, LOW);

    mode = MODE_LOW;
  }

Code from the Factory Firmware on the HexBright Github Repository. Safeguard code to prevent overheating similar to the battery conservation safeguard I explained above.

The next feature I wanted to replicate was a strobe feature. While not a feature strictly seen in more higher end flashlights, it's a cool feature to have. I really wish I had taken the time to try clicking the button a few times before I set in on coding it, as this too was a feature on the factory firmware.

 switch (mode)
 {
 case MODE_BLINKING:
 case MODE_BLINKING_PREVIEW:
   digitalWrite(DPIN_DRV_EN, (time%300)<75);
   break;
 }
 ...
case MODE_BLINKING:
case MODE_BLINKING_PREVIEW:
  Serial.println("Mode = blinking");
  pinMode(DPIN_PWR, OUTPUT);
  digitalWrite(DPIN_PWR, HIGH);
  digitalWrite(DPIN_DRV_MODE, HIGH);
  break;

Factory code for the blinking mode.

I felt I was putting too much time into this, so I stopped short of doing anything with the accelerometer. However if I have time in the future, I'd like to try to implement a feature where the light turns off and the status LED Illuminates if it experiences free fall. This would make it easy to find and less likely that you would be staring directly into the flashlight should you drop it.

In the end, there were some logistical hurdles we couldn't overcome internally to make it viable to be sold through SparkFun. I still recommend it for someone looking for a customizable flashlight or for something they can program in Arduino, but aren't ready to dive into the hardware end of things. It also got me thinking what other typical household products would be made better if you could program different features on your own. Imagine taking a 5 speed blender to 10 speeds (not sure why you would want that, but maybe it's desirable) or programming variable temperature profiles into your oven.