Generally when doing projects without strong form-driving requirements (it's just a silly button, so weight size, how it fits into your hand, how people feel about the form aren't critical to it being successful), before I do any of the physical/form design, I pick the electrical components and architecture that are going to make my life the easiest. There's a huge variety of options for controllers, batteries, connectors and wiring, but options are normally very different physically, so choose the ones you like the best, then fit them to your box. See the sketch schematic for a general overview of the final system.Choice of microcontroller wireless module
Arduino is the obvious choice for most people. Provides an electrical platforms that provides most basic functionality makers need, has a relatively intuitive language, cheap, and has TONS of online documentation. Partnering it with a well-documented Wifi module with a powerful online API like the Electric Imp seems like a natural choice (Spark Core is another option that will be released soon). However, what I'm trying to accomplish here is so simple that rather than using the Arduino to do all logic and using the Imp solely as a communication channel, I decided to take advantage of the Imp's onboard processor (which few people realize can do many things the Arduino can do) to eliminate the need for an Arduino from the system. You could just as easily use both together (which might be easier for beginners). The advantage of skipping the Arduino is fewer parts, longer battery life, lower cost. The main disadvantage is that the Imp uses Squirrel, a language that uses a slightly different flow and syntax from the Arduino, and might be harder to learn and slightly less useful (based on the frequency you might use it).The strategy:
- We're decided on using the Electric Imp, which runs at 3.3V and can consume on the order of 5mA in sleep mode. LiPo batteries come in multiples of 3.7V nominal, and I happened to have some small, lightweight 2000 mAh LiPo batteries from SparkFun
lying around that would work perfect, lasting approximately 16ish days. If you're ever looking for a source for cheap, reliable LiPo batteries, go to www.all-battery.com.
I love them.
- Next we need to make sure the Imp can control our LEDs that light the button. I'm using the common cathode diffused RGB LED from Sparkfun
, which needs to pull 20 mAs for each color. Unfortunately while going through the Electric Imp documentation
, I found the Imp's GPIOs can only source/sink up to 4 mAs, which means we can't power the LEDs directly from the Imp. To address this, a common strategy is to use transistors to turn on the LEDs. A great explanation of transistors can be found HERE. Effectively the transistors take a smaller current input from the Imp to close an internal switch that allows the LEDs to be powered from the battery, so our Imp isn't trying to provide more current than it can. The 2N2222 transistor
is very common in low-power amplification applications. Because we're using a common cathode LED (meaning positive terminal for each LED is shared) and each LED needs a different applied voltage to work (and therefore a different current-limiting resistor), I setup all of the transistors to share their emitters with ground. See the notebook work for how to size the resistors for the transistors to work.
- After selecting all the auxiliary (non-Electric Imp) components, I like to lay them out nicely and attach them to a protoboard
(printed circuit board with through holes you solder components to) that will connect to the Electric Imp with breakaway headers (this way I can easily remove the protoboard from the Imp if I want to use the Imp in another project). Protoboards come with a huge variety of routings between the through holes: the one I chose from Amazon has no routing between holes, giving me more freedom with component layout but more work doing my own routing. I included connectors for the battery (2-pin JST
), LED (4-pin breakaway), and button (2-pin JST) so the system could be easily disassembled. The final step is to add a jumper to the Imp to easily switch between battery or USB power.
Now that we have a hold on the electrical side, time to move onto the box that'll bring everything together.