Fun with a 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.


Comments 49 comments

  • Just a note, while the stock firmware is pretty good ‘as is’, most of the active development is going on in David Hilton’s fork: dhiltonp/hexbright. David and others are frequently available for Q&A in the #hexbright IRC channel on freenode (same network as the SparkFun IRC channel).

  • Looks like it could be fun. First thought that pops into my mind would be for a hunting light. Use the accelerometer to detect the angle the light is pointed at. Down towards the ground = lower brightness. The further up towards straight ahead that you point it, the brighter it gets.

    That way, when you’re walking in to your treestand early in the morning you can point it towards your feet and have just enough light not to trip on things, but if you lift the light up because you heard something, it gets brighter so you can illuminate most distant objects.

    • The firmware I’m running does exactly that. Although, it only checks the orientation when you activate the light, or if you hold the button while angling the light. Without really good noise filtering on the accelerometer, having it constantly adjust the brightness causes a lot of flicker, but of course, aggressive filtering would tend to lag the changes in brightness. This sketch (up_n_down in Hilton’s repository) has a lot of other bells & whistles, but you could simplify the program so that it changes brightness whenever you tap the button.

      That’s the main benefit that I see - you don’t have to create something brand new; simply customizing the light to your specific needs is worth it alone.

  • A blender that goes to 10? You need a blender that goes to 11!

    “Eleven is way better than 10!”

  • My toaster oven (Krups) has two pizza settings on it that are absolute crap. The oven has quartz heating elements on the top and bottom and every single mode besides broil simply alternates between the two. No matter the setting, the cheese is always burnt and the crust is always soft. It would be nice if it were programmable. Throw in some sensors (humidity, optical, infrared, etc) and build a truly automated pizza oven!

    • I bet you could adapt one of the many ‘DIY reflow oven’ tutorials and instead of PCBs, put pizza inside :)

  • My first thought when I saw this was “lightsaber”. Use the accelerometer to make it flicker as you wave it around, and to add a fade on/off, and stick a honking big piece of acrylic rod on the end of it. Put some coloured filter between the LED and the acrylic to tint it the colour of your preference.

  • It would be nice to create “cooking schedules” for microwaves that allowed variable power settings over time spans.

  • A $100 Arduino board with LEDs which requires a $12 battery would be logistically unaffordable.

    • How about if it’s also a 500 lumen tactical flashlight. It’s new, and it’s incredibly customizable, so it’s hard to claim it’s as reliable as a Surefire, but it can certainly put out as much light as one. And of course it comes with the battery. For all of that, $100 is a steal, but if all you’re looking for is an Arduino board, this isn’t for you.

      • I think you really have to be looking for either the programmable aspect, or the formfactor - as there’s certainly better Arduino boards if you want an Arduino, and there’s arguably better flashlights if you just want a flashlight. It’s the combination of the two that really makes this and why I backed the KickStarter. There is at least 1 other programmable flashlight nowadays (MyTorch), but its flexibility in terms of programming is extremely limited and lacks the accelerometer/gpio.

  • is there a datasheet somewhere showing the enclosure and lens dimensions? i’m assuming it’s using an off-the-shelf TIR optic though i can’t seem to find any info on that.

  • Too bad the Cree LEDs aren’t rated for reverse bias, or you could use it as a light sensor too. OTOH, they can’t be using all the GPIOs, so soldering on a phototransistor should be easy.

  • http://harleyhacking.blogspot.com/2009/10/strobe-light.html

    Not a sketch, but I think you might be able to adapt it to an RPM strobe.

    • There are many “mature” hexbright sketches in the dhiltonp github repository, and many of them include strobes.

      https://github.com/dhiltonp/hexbright

      My favorite so far is up_n_down.

  • This flashlight is awesome! I love modular/programmable things, and this looks like something that could get really tricked out.

  • I have quite enough flashlights, thank you.

    What I am still waiting for, however, is a tasty little lightning detector chip that’s going to help me conquer the world.

  • You could make a strobe light or that strobe weapon thingy from adafruit!

  • Seriously, you should write something where, if it falls more than say 10 feet, it will flash Morse Code for SOS. Seriously.

    • Are you thinking of hikers/climbers/etc.? We had a discussion about this on IRC a while back, and while a height drop would be difficult to realize (there’s no altimeter, and detecting freefall isn’t very reliable), it is very easy to write a program that makes the light blink an SOS if it is stationary for more than N seconds. The up_and_down program already contains a ‘nightlight’ mode where the exact opposite happens; if the light is moved around, it turns on, then after 10 seconds of no motion, it turns itself back off (save for a tiny LED in the back). All you’d have to do is invert the logic - and of course make sure that program runs while any other use applies. One down side is that this means it always drains at least a tiny bit off the battery.
      ( And of course it should not be your one and only emergency device - always bring a locator beacon if going into desolate places. Wish I didn’t feel the need to add this, but too many people end up on the news within the context of “after an extensive search, the body of…” )

      • Sorry, I thought there was an altimeter in it.

        Perhaps using the accelerometer to see if it bounces around a lot?

        • Possibly - either through the accelerometer’s built-in ‘shake’ detection, or manual processing. Might be difficult to differentiate a fall (and who’s to say it bounces all that much when it does fall?) vs a person jogging, though :)

          • Most modern accelerometers have free-fall detection built into them. It looks for zero G on all 3 axes for longer than a set threshold.

            • The biggest issue is that the flashlight is cylindrical, so it can easily be experiencing acceleration due to rotation while in freefall.

              The best you would be able to do is detect a short, large number of Gs, then a long period of 1 G down - but then how well will it handle bounces? And each axis can only read up to 1.5 gs of acceleration - if the light hits on just one axis, that’s the /maximum/ impact you can detect.

              I’ve recently been looking at accelerometer stuff again (but mostly with gesture recognition in mind). I’ll consider the free-fall detection as I’m considering what can be done.

            • I don’t think this one does - datasheet says it does shake and tap, has some nice registers to aid in common orientation detection (perhaps if all 3 are in limbo), and the library has some nice tricks up its sleeve, but freefall (detecting drop) is WIP. Again, though, freefall detection may not be as useful as it would seem at first glance (but everybody has different use cases - and even being able to consider them is one of the beauties of this light).

  • hmm…wish it was an RGB LED.

    • Yeah, for such a freakishly expensive flashlight it really should have RGB; especially since it is programmable. I mean there is only so much programming that you can do with one color!

      Really, a flashlight with one AA battery that costs a hundred bucks or more? Really? I could buy one at wally world for $2! Sure it doesn’t have an arduino, but I could buy an arduino for another $10. Some people have way more money than common sense.

      • For the record, the “one battery” the Flex uses is an 18650 - a 3.7V rechargeable Li-Ion battery that is definitely not a AA.

        As a pretty extreme user of flashlights (and believe me, I have many…) the Hexbright is usually in my bag when I go out.

      • lol. different strokes for different folks :) i imagine if i said that anything over IP v4 is useless, many would be eager to tell me how wrong i am!

        during the work day, i carry a little over $150 in flashlights (3 of them) with my tools/on my person. not a single one of them is rgb, and none of them use standard batteries. and i consider them to be some of the best ‘tools’ i’ve got. i use at least one of them every day.

        4 years ago, i would have agreed with you– such a crazy amount of money for such a simple device that i can get so much cheaper at large chain stores. but after a few uses, i’m hooked!

      • Good luck fitting the Arduino into the flashlight, though ;) I agree that it is expensive for a light - even if it is powered by an 18650, not an AA, can be recharged over USB, programmed, has an accelerometer, etc. etc.
        Then again, I got mine for much less through the original Kickstarter.

        There’s good reasons for not having an RGB LED, however - from powering them through to optics, things get a fair bit more complex and not nearly as rewarding as you might think; and I’m a huge fan of the RGB LED strips for lighting, so it’s been on the list of things to try, just pushed down due to the challenges involved.

        That said, the design is open, so if you wanted to make an RGB one and bring it to market, you’ve certainly got my vote.. and if executed well, perhaps even my dollars. But it can’t be an Arduino duct taped to a dx flashlight, that’d be cheating ;)

        • My bad on the AA, but it sure does look like one in the picture. Actually I would prefer a AA, I’m a big fan of readily available standards; maybe the 1850 is a standard, but not one you can get at any convenience store, like a AA.

          For the arduino, I was thinking of a mini-pro, and I would use something higher tech than duct tape, maybe velcro or even epoxy for a more permanent installation. :)

          • You just can’t get much current from a AA. This translates to not many lumens.

          • The down side to an AA is that it just doesn’t pack a whole lot of oomph, requiring a boost circuit, etc.* The 18650 is actually fairly standard, although it is indeed not readily available here (I’ve seen them in the U.S. in fishing/hunting type stores), Amazon et al will happily sell you either quality or cheap ones.
            * I’ve been meaning to try one of the small portable chargers that take an AA and charge a phone, for example. With a bit of filing down, it should fit the battery compartment. On the down side, those can only handle a very small amount of current draw, so at full brightness the boost circuit - unless protected - would probably release the magic smoke.

            Velcro almost sounds tempting ;)

            • AW brand 18650 cells are very good and and can be found at lighthound.com (Texas); AW’s are expensive but you get what you pay for. A good selection of economical 18650 cells can be found at batteryspace.com (California).

              The LED driver modules are pretty hard to kill, except if you hit ‘em with reverse polarity. So buy “protected” type batteries, mind the polarity, and the magic smoke will stay where it belongs.

  • Man..these are exciting times, I never would have imagined 20 yrs ago that one day I would be in total control with the ability to program my flashlight!

    /sarcasm off

    What I would really love is a programmable FORK!

    /sarcasm truly off

    • I’ll start v2 of the Spork, complete with an embedded atmega. And a microwave.

    • What I would really love is a programmable FORK!

      Be careful what you wish for; you might just get it.

      • Retractable tongs, fold for safety when placed down, extend with a satisfying snap into your food of choice, perhaps with capacitive touch sensor safety knife that recoils from fingers. Would you carry it?

        EDIT: Oh.

  • Y'know, I can see how this could be quite useful. A flashlight that varies the current/voltage output to the led in a “smart” way, according to the state/age of the battery, could probably significantly increase the useful battery life, and increase lifespan of the led and battery.

    • Definitely. A good hack would be to add an ambient light sensor so it could modify the brightness according to the situation. If there’s more ambient light, the flashlight is brighter - less ambient light, the flashlight could dim. In very low-light situations, you often don’t need much light to do the job.

    • Unfortunately the battery charge state can’t be measured accurately enough for that. However, there’s a few I/O pins available off the board and hardware hacks are in the works for making that an option. I’ll be adding a buzzer to one of mine. Why? Why not.

      • Looking at the schema, they seem to have one of the ADC channels on the battery voltage rail. Given that it’s a 10-bit ADC, a resolution of .003v is, In my book, fairly good. Granted that one might have a bit of difficulty measuring the “full” voltage, I think it would definitely be possible.

        • I’d have to ask what schematic you’re looking at - the units received so far have no direct measurement to the battery, only what’s coming off of the voltage regulator. See also: voltage_readings

          • Oh, whoops, -1 reader of schematics. And, sorry. Thought you meant the actual resolution of the measurement. And I suppose coding an algorithm accurate enough would be a nightmare.

            • Gotcha - yeah, once hooked up directly (well, almost directly) to the battery reading levels is actually fairly accurate, although the discharge curve of a Li-Ion battery still means you’re only going to get so much accuracy out of measuring by voltage alone. It is apparently originally not done for power conservation reasons.


This Week

This Month

Heartbleed

Happy Arduino Day!

SXSW Create 2014