Sunday, September 7, 2014

ATtiny85 and ATtiny84 DIY Programming Shield

To program an ATtiny85 or ATtiny84, smaller microcontroller brothers to the ATmega328 used in the Arduino, you can use a dedicated ISP programmer, or breadboard the chips and use an Arduino. I used the latter technique, but as I wanted an easier and more reliable way to work with a handful of chips for multiple projects, I decided to build my own programmer shield.

The Omega-MP, which I bought on eBay, is a great shield to program the ATtiny85 (and many other chips) but didn't support the ATtiny84, so my shield here will support only the ATtiny85 and 84.


Here's a Fritzing diagram of how it's wired. Ignore the labeling of the 14-pin connector. That should represent the 14-pin DIP of the ATtiny84. Pin 1 for both chips is to the left and down (yellow lead on the 85 and red on the 84). The Fritzing program didn't have an exact representation of the prototyping shield I used, so the actual wiring and the diagram will be different in practice. I used a cheap prototyping shield that's readily available on Amazon or other retailers' websites. Use a 10uF capacitor between the ground and reset pin of the host Arduino.

Here's the pinout diagram for the chips: ATtiny Pinouts and ISP Guide

I followed the linked diagram to initially breadboard my chips and then to wire up the shield. I used DIP sockets for the completed shield, but ZIF sockets would probably work well too (but take up a lot more room).

Here's my completed shield, with crappy soldering and all!

Completed Shield on an UNO R3
Top View
Bottom View
I ran the wires for the ATtiny84's 14-pin DIP socket on the bottom, tying them into the Arduino pins. I then routed the ATtiny85's 8-pin DIP socket on top, tying them in to the shared pins alongside the 14-pin socket.

This shield will program one (at a time, won't do two chips at once) ATtiny85 or ATtiny84. It'll also work with related chips from those families, but I don't know why you'd want to use an ATtiny25 or 45, or the 24 or 84 as the price difference at the hobbyist level is nil, but since they are pin identical to their siblings with more memory, they will work.

Friday, September 5, 2014

Control Stop Light with an ATtiny85 or Arduino

One of my first projects with Arduino was to provide a little automation to an old stop light (and crosswalk signal) I had out in the garage. I'd already wired them to individual switches (good for games of "red light, green light"), but the allure of having it operate light a real light (green, then yellow briefly, then red, repeat) was too great. Arduino seemed like the perfect fit.

Of course, the Arduino can't switch anything high voltage nor high amperage. So you'll need to use a relay. I am a big fan of the cheap relay boards like these. For a regular stop light, you'll need three individuals or a four in one. I used a four in one relay board and a two in one separate board for the crosswalk lights. I stuffed it all in a plastic enclosure box. Don't undertake the high voltage part of this project without a firm understanding of the risks involved. This post isn't about high voltage relays or how to integrate them with the Arduino, so I'll assume you know how to do that. Follow along if you want to build a stop light simulator with 5mm LEDs, the same principles apply.

ATtiny 85
I recently wanted to find a way to experiment with using an ATtiny (baby brother of the ATmega microcontroller in the Arduino). I picked up some ATtiny85 and ATtiny84 chips off an eBay vendor. The ATiny can be programmed, with a new library, in the Arduino IDE, are much cheaper than an ATmega ($1.3/ea for the ATtiny85 vs $2.30 for the ATmega328p, and $5+ if you don't want it shipped from China), but are limited in the number of input/output options. The ATtiny runs slower (internal clock, the ATmega uses an external), uses less energy, and comes in a bare chip form factor (need some soldering skills to get beyond the breadboard phase). Here's a good comparison of the two chips.

Since the ATtiny chips run off 5v I planned on using a commodity USB power supply. Since the ATtiny85 has an internal clock chip, it's easier to build a circuit (no external crystal).  My original stop light controller was powered by an Arduino Micro (about $20). So I wanted this new controller to be smaller and cheaper. My total cost to replace the Micro was about $3.

Since I used only 5 outputs and no inputs for my light controller, the ATtiny85 is about the smallest and cheapest of the Atmel chips that will do the job.

First, to program the chip. I used a programmer shield, but you can use some hookup wire and do it yourself or build your own shield. Follow these directions if you want to take that route.

Program it!
Here's the code:

"


int Walk = 3;
int DontWalk = 4;
int Green = 0;
int Yellow = 1;
int Red = 2;

void setup()
{
 

  pinMode(Walk, OUTPUT);
  pinMode(DontWalk, OUTPUT);
  pinMode(Green, OUTPUT);
  pinMode(Yellow, OUTPUT);
  pinMode(Red, OUTPUT);
}


void loop()
{

  //HIGH = ON, LOW = OFF
 
  digitalWrite(Walk, LOW);
  digitalWrite(DontWalk, LOW);
  digitalWrite(Green, LOW);
  digitalWrite(Yellow, LOW);
  digitalWrite(Red, LOW);
 
  digitalWrite(Green, HIGH);
  digitalWrite(Walk, HIGH);
  delay(800);
  digitalWrite(Walk, LOW);
  digitalWrite(DontWalk, HIGH);
  delay(50);
  digitalWrite(DontWalk, LOW);
  delay(50);
  digitalWrite(DontWalk, HIGH);
  delay(50);
  digitalWrite(DontWalk, LOW);
  delay(50);
  digitalWrite(DontWalk, HIGH);
  delay(50);
  digitalWrite(DontWalk, LOW);
  delay(50);
  digitalWrite(DontWalk, HIGH);
  delay(50);
  digitalWrite(DontWalk, LOW);
  delay(50);
  digitalWrite(DontWalk, HIGH);
  delay(200);            
 
  digitalWrite(Green, LOW); 
  digitalWrite(Yellow, HIGH);
 
  delay(350);
 
  digitalWrite(Yellow, LOW);   
  digitalWrite(Red, HIGH);  
 
  delay(1200);             

}
"


Now to breadboard it. Follow this pinout guide to wire it up. Here I used LEDs to take the place of the relay outputs to see if it looked like a stop light and to test my timings. Since my relays are triggered by a "high" signal, when the LED is on, the relay would be triggered to send the high voltage to the light.


It works! Now to solder.

Top of the board
Bottom, my lackluster soldering skills...
Now back out to the garage to plug it in to the relays and the lights.


Here is the final, ready to be buttoned up project.

This photo shows the dramatic size reduction you can realize switching from the already small Arduino Micro to a basic ATtiny85 on some perfboard.

Provided you don't need a bunch of inputs/outputs the ATtiny might be a cost, and perhaps more importantly size, effective solution.

Here's the Fritzing diagram:


Friday, August 29, 2014

Repurpose an old hard drive as a new project case

Today I finally got around to doing something with a really nice Seagate 3TB hard drive that went toes up. Normally, you'd RMA that bad boy and get a fresh piece of kit. However, mine must have come from an external enclosure (something I do on occasion because they're cheaper than bare drives, however that makes sense), and Seagate won't RMA it directly.

Not wanting my data floating around a dump somewhere (who remembers what they filled 3TB with???), I disassembled it for destruction. As I was doing so, I was keeping an eye on spare parts and cool things to keep.

Taking apart the drive itself is pretty easy. All you need is a T8 screwdriver or bit.






There's seven screws on the top of the drive, one hidden behind the label. After that, the top pops right off and you can begin tearing apart the insides. You'll need a T6 screwdriver for most of the internal screws.

Once you take apart the inside components you're left with a pile of largely useless parts, the hard drive platters, and an empty case with the SATA interface components.



You think you're badass having old CDs as coasters? I use hard drive platters. It separates the nerds from the rest as to who can identify them. :) I suppose they'd be good as a wind chime too.


Anywho, I took the logic board off too. My empty hard drive was now destined to become a small project case for something in the future. Then I began to wonder, could I use that logic board's power interface to get enough juice to run an Arduino?


The power cable has 5 volts and 12 volts on the rail as well as ground, labeled as COM here. 

So I soldered a couple of test leads onto the back side of the power rail, plugged it into a trust external USB enclosure, and flicked the switch and prayed.


Much to my surprise, the USB enclosure didn't short out, the lights in the house didn't explode, and the hand of God didn't bitch slap me across the face. What I had, according to my multimeter, was a steady 4.78v on the 5v side and 12.35v on the 12v side. 

Attaching the 12v lines to the input on an Arduino (a Ruggeduino, just in case) and wahla! I've got a blinking pin 13 led. 

  

There's even a nice little hole from the bottom of the hard drive to the inside (where I'm pointing) to allow the power and whatever input/output I need for the project.


This is a Pro Micro Arduino clone, with its headers, to show the scale and space available in the hard drive shell. There's more than enough room to let me work wires in and get the case closed.

Now I can Arduino-ize my computer, without needing to find a seperate power source or line from the power supply. I can just plug it in.

And the case itself should provide a solid, rugged, and reliable operating environment for some future project.

Thursday, August 28, 2014

Comcast digital cable on 3 TVs with one box

So I recently cut some costs by eliminating a couple of Comcast DVR boxes from our account that we only occasionally used. We retained one on our living room TV that gets the most use.

Of course, just a few days after doing this we wanted to watch something on cable in the bedroom (where we'd had a cable box previously) and could not now. This got me thinking, how can I distribute, on the cheap, the cable box in the living room to the TV in the bedroom (and hit the office along the way)?

I have a rambler style house, with my office being one room over from my living room (sharing a common wall) and the master bedroom on the other side of the office (again, sharing a wall). I'd previously poked some non-descript holes in both of those walls to run cabling from the office to both the bedroom TV and the living room TV to support using a single HTPC (home theater PC for those not in the know) at both locations, while placing the computer itself in the middle ground of the office (so I can use cheap wireless keyboard/touchpad combos to operate it without having to transmit more than 25ft from either location).

I recalled from previous forum readings that the Motorola DVR boxes (the older style anyways) permitted the use of both the HDMI and the component video (the red, green, and blue cables) simultaneously (something most devices do not permit). A quick check show that my (slightly) updated box, a DCX-3400M, supports the use of both as well! As luck would have it, my living room already uses the component connections, leaving the HDMI free on the cable box. Excellent, this would allow me to run at least one more TV off the box. To challenge myself, I demanded a total of three TV's.

So I grabbed an HDMI splitter from Amazon, you can find it here, and some extra long HDMI cables (which are surprisingly inexpensive now). I bought those at Amazon as well (Prime free shipping FTW!), but would highly recommend Monoprice should you be in the market. I put together a couple of big Monoprice orders a year. They are the cheapest supplier for cabling (structured, device to device), connectors, and even accessories (my in-ceiling speakers for distributed sound come from there).

Anyway, before I get too sidetracked, the little splitter and cables were delivered. After digging in behind the TVs and pushing cables through the walls, I was ready to test it.

I can indeed confirm that the DCX-3400M (and probably all similarly designed boxes) support simultaneous output. I'm even told the low-res outputs (the passthrough coax or the composite video) are also powered at the same time, so if you've got a low-res set on your patio or in the kitchen, you might want to string a wire up. Then you can watch the same thing in multiple rooms, and without the sound delay you'd get from two DVRs (or one DVR and one live using an antenna).

Now, the biggest downside here is that you can watch the same thing on multiple sets. This means you HAVE TO watch the same thing. There's no, I'll watch my show here and you go to the room and watch yours. So either really agree with your significant other about what to watch or have a backup plan (i.e. another input, DVD player, Roku, Amazon TV, etc.). Second, controlling the DCX-3400 requires a line of sight, something you pretty much can't do from several rooms away. So, to change channels you have to go back out to the living room. Not convenient, to say the least.

Since I generally get along with my wife, and always have multiple source options in case I'm not at the moment, I only had to tackle the second problem, the issue of control.

To control the cable box from another room. I picked up a Next Generation Remote Transmitter. This little electronic box works with your existing remote to make it work over radio frequency (RF). Since RF signals will go through walls without problems, this little wonder can make my cable box remote control the box from two rooms away!

How the RF transmitter works, I don't know, and I was skeptical as all heck it would work. The sales pitch is that you can turn any old IR remote into RF by just replacing the battery. How is that possible? Supposedly the little battery replacement catches the stray signals generated by the remote when you press a button, translates that to RF, and sends it to the flying saucer-like base station which rebroadcasts the original IR signal. Sounds implausible I know, but it works! And really, really well.

I already am heavily reliant on RF remotes in my theater, living room, and master bedroom. I like the Harmony remotes from Logitech. I use an older 890 in both the bedroom and theater and a newer (and unfortunately out of production) 900 in the living room. Since these Harmony remotes do all the functions of the original remotes, those originals are stuffed into a drawer. I located my Comcast DVR remote to use with the Next Generation RF device.

After replacing the battery, I set the saucer up near the living room TV. I stuffed it behind the entertainment center and threaded the included remote IR emitter "eye" into the entertainment center near the cable box. It works flawlessly. I can watch and control the cable box from a room (or two) away!

So this takes care of the office. I don't mind having a couple of remotes to juggle in my office, since I'm the only one that uses it and needs to understand the logic (or lack thereof) the way the TV is wired. The bedroom however, which has a Harmony 890, will be controlling the cable box in the living room by using a second RF receiver base station. The 890 came with one, and supports at least two, but I'm using the included one to operate the TV and inputs in the bedroom. Once you go RF, you'll never go back. You don't realize how annoying it is to try and find the right angle for a remote's command to be received, or worse yet, when people, dogs, or other things obstruct your remote's path. So as soon as I get that second base station for the 890, we'll be able to watch and control a single cable box from 3 rooms!


Thursday, August 21, 2014

AmazonBasics Antenna Review

http://www.amazon.com/AmazonBasics-Ultra-Thin-Extreme-Performance-Amplified/dp/B00DIFIP06/ref=cm_aya_orig_subj
 I was surprised at just how much better this was than the old rabbit ears antenna I was trying to get to work. I wasn't expecting such superb performance from something that is so easily hidden on the wall (mine is tucked neatly behind a framed picture).

I live only about 16 miles from all of the nearby broadcast stations, and my market is nice enough to all broadcast from towers in the same direction, actually in a cluster of towers that are all together. So getting a good signal, theoretically, should be as simple as finding something that I can point in a vaguely east by northeast direction. I've gotten antennas to work before, but with limited success. With Comcast apparently turning off ClearQAM in my area (I lost it about halfway through last football season) I needed a better solution than the rabbit ears strung up through my office for this football season. To make it worse, not only were they ugly (my wife can be quoted as saying, "Where the heck did you get that!?!", upon seeing it for the first time), but they only received 3 of the 4 major networks.

So it was with tempered expectations I plugged this antenna in to my TV. Expecting the lackluster performance of past antennas I set the set to autotune and discovered every channel and subchannel.

With only some minor repositioning, this antenna now sends every channel, clear as day, to my TV. The TV reports full strength bars on each of the major networks.

The AmazonBasics flat antenna is basically a copy of the Mohu Leaf, but a few dollars cheaper.

Though a type of modern fashion symbol all by itself, meaning you could hang this on the wall as a piece of art or discussion piece, it is easily hidden behind a picture with no degradation of the signal. 


Integrating a Generic Relay Module with Insteon



SainSmart 4-Channel Relay Module

Relay modules such as the one pictured above, available in 1, 2, 4, 8, and 16 versions, are readily available from a number of sellers. Click the picture above to be taken to Amazon for the SainSmart version.

All of these modules are similar. They work on a 5v system, both requiring 5v to operate and switching when they receive 5v or ground (depends on the model, some can be switched by a jumper), and switch up to DC30v or AC250v at 10A.  They are an excellent addition to any budding Arduino enthusiast's toolbox. I used relays like this in my Arduino-powered stoplight, which uses an Arduino to give the logic to a standard stoplight, which is powered by 120v mains.


My home automation system of choice is Insteon, a powerline communication system.

This summer, I installed recessed can lighting in my living room. Six lights in total, but I wanted to be able to turn the one directly above my TV off, without having to resort to such archaic means as unscrewing the lightbulb.

I initially tried a Micro On/Off module hidden in the can light I wanted to remotely control. If I hadn't wired all of the lights together in series, adding this to the scenes for the living room would probably have given me what I want. The problem is, that though once the living room can lights were turned on  the micro module received power and would work to switch that can at will, it didn't boot up instantly. So it wasn't a seamless solution. When you'd turn on the cans, all of them would come up, then the micro module would boot up, and only then could you turn that TV can on and off.

This solution would also cause Insteon network communication issues, since anything with that micro module in the scene would continue sending requests and eventually give failed communication notices. This isn't good networking.

My lack of foresight required some clever electrical engineering. I remembered some of these relay modules, more than able to handle switching a single 120v led can light, but how to integrate it into my Insteon network?

I took a rather simple approach, avoiding the inclination to make a wifi-enabled, Arduino-powered, relay switching, network-enabled do-it-all box. I wanted to use an older I/O Linc Insteon module to provide the power and then activate and deactivate the 120v relay to the TV light.

Though the I/O Linc has ports for 5v, GND (ground), S (sense), N/C (normally closed), N/O (normally open), and COM (common). The latter three are used for the output of the I/O Linc, as it has a built in relaying function. The in-built relay function will only switch low voltage, for example, I have one hooked to my garage door opener to trigger the door to open or close as needed. I/O Lincs respond to any Insteon input, so if I could get the I/O Linc to switch one of my relay modules, with those relays switching the high voltage side, I'd be in business.

One word of note, the output of the I/O Linc can function in either momentary or latching mode. In momentary mode the I/O linc will open the N/C contact and close the N/O contact (sending it to common) for a period of time before switching it back. This is how it functions as part of my garage door operation, it shorts the N/O and COM for a second, simulating the physical press of the garage door button on the wall.  Latching mode makes the relay output work as a switch, going back and forth between the N/C and N/O being sent to COM. Think of latching mode working like a light switch, it's either on or off until you flick the switch again, nothing is timed.

On the bench, the 5v output of the I/O Linc will power the relay modules, no problem. So I ran the 5v and GND from the I/O Linc to the relay module, jumped the GND to the COM, then used the output from the I/O Linc (set to latching mode) to send ground (from the COM) to my output of choice (in latching mode it doesn't matter which, the N/C or N/O is used, as it just moves back and forth).

After crawling into the attic, the relay functioned just as expected. My remote (either a Remotelinc or a Keypadlinc) can send a command to the I/O Linc to cycle the high voltage relay on and off. This worked beautifully for all of about 10 minutes. Back up into the attic I go, rewire everything, thinking the attic was just too hot for the I/O Linc or that the I/O Linc failed. Replace everything, bring the Remotelinc up with me to check, and get it working again. Ten minutes later, it quits working.

I figure out, from all these failures, that either using the 5v from the I/O Linc constantly or (more likely) shorting the ground from the I/O Linc to COM was causing the I/O Linc to overheat and become inoperable. I fried one of them doing this, so DO NOT SEND AN I/O LINC'S GND OR 5V TO COM or else you'll crap the bed.

I hooked an old cellphone power brick into the mix, to both power the relay board and to become the new source for my ground (or 5v into COM if your relays switch with a high input). What you end up with is a relay that is controlled by the I/O Linc, can switch a 120v line signal, and the relay board is powered by any 5v power adapter which can be plugged into the pass through mains plug on the I/O Linc.

***DO NOT UNDERTAKE SWITCHING HIGH VOLTAGE IF YOU DO NOT KNOW AND UNDERSTAND WHAT YOU ARE DOING. YOU CAN KILL YOURSELF. HIGH VOLTAGE IS DANGEROUS.****

You'll also, if making a permanent installation, need an understanding of the rules, laws, codes, etc. for high voltage wiring.

Here's how to wire the relay up. Remember to switch the I/O Linc into latching mode. Since Fritzing doesn't have either of these devices, I resorted to wiring up another on the bench.

I use a mini breadboard to be the backbone of the system, but it's not needed. Once you get it working, you can solder the wires together. The line on the left, with the black at the top, is the ground/negative lead from a USB 5v power supply. Yellow and orange leads are tied to ground.

The line on the right, the red wires, are 5v power.


Yellow, tied into the COM port on the I/O Linc is the ground from the external power supply.

Orange is the N/C port on the I/O Linc here, but if you're in latching mode, it really doesn't matter. Tying it into N/C means that it'll default to "on", so in the event of some failure, the relay will be triggered to close (i.e. on).


On the relay board side, the brown wire from the breadboard brings ground to the GND pin (far left) and the red lead brings 5v from the breadboard (far right). The orange wire comes from the I/O Linc and is the low side trigger for the IN1 (relay on the left, where my finger is). Though I have a yellow wire in IN2, ignore it, that's not the same as the other yellow wires, it was just a spare wire on the test leads.

If you've got it all wired up, toggling the I/O Linc (either by sending commands from a linked remote or by tapping the black button on the side) should toggle the relay (you'll hear a click and the led on the relay board will turn on).

You can now use the relay's high voltage side to switch a load (switch it on the "hot" wire, typically black, not on the neutral, typically white). There's a little diagram on the relay's output side to tell you which terminal is normally open and which is normally closed. Use a multimeter to help make sure your circuit is wired correctly and operating how you want before you put the more dangerous high voltage hookups in.

The biggest advantage of switching my TV can light this way is that the relay doesn't care what the voltage or current is, it just switches back and forth. So I can toggle that one can light on and off while the upstream circuit is powered by a dimmer switch. For example, I can dim the lights to 50% and then toggle the TV can off and on. It truly operates seamlessly now, essentially like a bulb I can remotely unscrew when I don't want the TV washed out with light from above.

Wednesday, August 20, 2014

Piranha LED panel

So I was buying some components on eBay, from seller nyplatform , who was a pleasure to do business with. While browsing some of the seller's wares I was intrigued by the Piranha LED panels. I've since seen them for sale from several Chinese vendors, but this one is in the US, has comparable prices, and ships USPS promptly.

I ordered the white led panels , thinking that for the price, even if they don't work well, I'm not out much money.

Unwrapping the panel, which came wrapped in bubblewrap and encased in a static bag, you'll find a non-descript white panel of LEDs, with convenient power inputs (or passthrough) on either side. Polarity is clearly marked.

I wasn't sure exactly what I was expecting, but upon powering the first panel with an old 12v power supply, I was blown away. These panels put out a lot of diffuse light!


Here's the panel lit up. The light is blinding.


Here's my best attempt at showing the amount and wide throw of the light it puts out.


So I used a little super glue to bond three panels together, soldered some wire in, and they now provide ample supplemental light to my workspace.

If you're looking for a lot of bright light for a project, give these panels some serious thought. The seller above had 24 and 48 led options available, I went with the 48. There are also larger (up to 96) and smaller options available at other sellers. My seller had blue, red, and green in stock as well, and a quick search of eBay turned up a variety of color choices in most of these sizes.

These lights will surely be finding a way into more of my projects. I'm especially eager to try the "warm white" available from some sellers (the ones pictures are the "bright white" and are very much a cool white). If they truly give off an incandescent-like warm white color, I'll be using them to supplement some of my rope light and led strip lighting around the house. I'm a big fan of always having some light around.

Friday, August 15, 2014

Arduino Leonardo powered password keychain

Welcome to my inaugural blog-post. Recently, I've become infatuated with automating everything in my life. It all started when I discovered Insteon a few years back and proceeded to install their devices throughout the house. My coworkers laugh when they see me check my thermostat or adjust a lighting scene from my phone, but those types of behaviors are becoming increasingly normal now that the Nest, Hue, and even Comcast are pushing into home automation.

My desire to create automated systems led me to the world of Arduino and other microcontrollers. The fun of making your own hardware to go along with software is thrilling to me.

I started with an Arduino Uno, built a few circuits, automated a couple things, and even made my own Arduino on a breadboard. I got into the smaller Arduino boards and clones. Eventually I started to check out the other boards in the Arduino world, which led me on to the Leonardo.

The Leonardo, as compared to the Uno has the ability to act as a keyboard and/or mouse. This has the benefit of being able to send commands from the Leonardo. I immediately saw the benefit in being able to automate my computer, a way to create a macro-like system that I could make portable.

The Leonardo's USB port provides the power and the computer link, so all I need is a case to hold the board, some momentary switches, and a couple of LEDs so I can monitor what's going on.

The major caveat here is that the password, commands, whatever you send from the Leonardo are sent as plain text, as if you were typing at a keyboard. They are not encrypted or otherwise obscured. If someone opens a command line or text editor, they can hit the button and see in clear text your password. For my purposes, as the fob will never be off my person, I wasn't concerned.

After a trip to Ax-Man Surplus (the best place to go for odds and ends, including a wide selection of dirt cheap switches, project boxes, etc.), I raided my supply of plastic boxes, and assembled a desktop password entering machine.

I miniaturized this so that I could take it with me. One advantage of my password in a keychain is that you can create a very complicated password, for example use an RSA key, and adapt it for each site/program/network. For example, at work I can hit my password device, which enters the RSA key and add a number or word that's easier to remember than the corporately mandated password polices that make your password impossible to remember (and then require changing it every fifteen minutes).

Here's my design, my sketch, and some pics of my project:

This is the schematic for a breadboard setup password (or more correctly keyboard emulating) system.

The push buttons are momentary and send the digital inputs to ground. The LEDs are just to monitor the system. I have the red set to be always on, as in "red means ready". The blue is to show that the command is being sent, and remains on during the wait period in my program. So it tells me that I can't hit another button quite yet.

The circuit is pretty dang simple, and even the sketch is pretty basic. The challenge comes in miniaturizing it so that you can carry it with you.

This is my first, desktop ready setup. At about 6 inches wide by 4x4 inches, it definitely isn't pocket-ready. But it did prove the design works, and that I actually will use it.

I had an OKW Minitec enclosure that I wanted to use, as it had a USB passthrough port and keychain loop.

I forgot to take some "before" pictures, but found that a generic "Pro Micro" Arduino clone (which uses the ATmega32u4 as the Leonardo does), with a micro usb adapter fit perfectly.

After cutting down a blank circuit board to fit, I started to assemble to wiring. The case provides ample room, so I could leave enough wire to let me pull it apart as I worked.


As you can see from my mangled up board, this was used in a previous project. My desoldering skills aren't all that great, but they get the job done. Besides, as long as it works it doesn't need to be pretty.

For buttons I wanted something low profile, so putting screw base switches like in my desk-side box was out of the question. I tore into some old remotes to experiment with reusing them. The circuit boards of old IR remotes are excellent sources for IR emitting LEDs and for our purposes here, are an even better source of conductive pad membrane switches.

The pad of buttons you'll find in most remotes is easily cut and each button has a small conductive pad on the bottom. So when the button is depressed, it will connect any two circuits underneath. After experimenting with making my own traces out of wire and solder I discovered that even this was too tall. It interfered with the proper "pop" down and up of the button. I did find that soldering wires through the perfboard and cutting them just flush with the "top" side (that is to say the side on which the buttons will lie) gives enough wire to make the connection. However, I'd recently read about conductive paint and thought that might give a more reliable connection.

Here's my board after being coated with conductive paint in little traces that are to lie under my buttons.

I later added my solder points on the underside of the board and added some more paint into the wired area to ensure a solid connection.

One bit of advice, use a heat gun or a hairdryer on the paint. It says it'll dry in ten minutes, but it didn't. The hairdryer dried it in about a minute, and the label says it makes it stronger. So here's hoping it'll hold up to some abuse.


 I drilled holes for the membrane buttons and inserted them. They didn't want to stay in place, so I attempted to super glue them, but the glue didn't want to hold. So they are held in place by the pressure of the circuit underneath, which works OK. It doesn't end up giving me the fit and finish I want, as the case has a curve to it. So the bottom button (furthest on the left in the bottom picture) is exactly what I was aiming for, the remainder of the buttons slowly start to recess into the case. It doesn't affect the operation, and someday I'm sure I'll figure something out. The perfboard I used is too rigid, so maybe a perfboard that has some elasticity, or cutting some relief joints into it is called for. I'll update the blog if I ever get around to that.

Fully assembled. I took it to the bench grinder and sawed down those dome LEDs so they are now flush with the case. They are plenty bright, so I took a permanent marker to them, so they look just like the buttons, sit flush with the case, and provide a good amount of light to monitor the device by

Here it is plugged in for the first time! The beauty of using a single port for power and communication (both up and down stream) is no wires. I plug it in, and download my sketch to it and can begin using it right away.

You can see how the buttons have recessed (especially the one with the power symbol on it) into the case, as I discussed above.


And here it is, fully operational, transmitting a keystroke(s). The loop on the far right is going to help me put it on a lanyard or a key ring. It's a bit large overall for a pocket, but not prohibitively so.

 I also made one (forgetting to take any pictures whatsoever of my process) out of a slightly smaller keyfob case I had, but this one didn't have room for the full size USB adapter. So it needs it's own cable, but is smaller and much more pocketable.



 Here they are side by side:


Now for the sketch. For your first test, since if you mess this up it'll just continually enter text (into the command line or Arduino IDE), I HIGHLY RECOMMEND changing the delay to something like 10 seconds (add a zero, I use a 1 second delay). This will give you enough time between key commands being sent so you can make sure it's working properly. On my desktop box I go a step further and use a "master" switch by running all of the switch ground leads through a toggle switch. In this way, the master toggle needs to be "on" for me to be able to send the other switches to ground and thus send the commands. It just adds a layer of security, but keep in mind that these commands/passwords are being sent in the clear.

Here's the code to get this working:

"
char* password = "password";                   //place your chosen password within the quotes
char* aptget = "sudo apt-get update && sudo apt-get dist-upgrade -y";          //I use this string to help speed up my server updates

const int buttonPin = 2;                            //These can be changed to whichever pin you want to use
const int buttonPin1 = 3;
const int buttonPin2 = 4;
//const int buttonpin3 = 5;                        //I left this button in for future expansion, so commented it out as it's unused
const int ledPin = 9;                                 //This is your status led, the other one constantly receives power

void setup()
{
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(buttonPin1, INPUT_PULLUP);
  pinMode(buttonPin2, INPUT_PULLUP);
  //pinMode(buttonPin3, INPUT_PULLUP);
  Keyboard.begin();
  pinMode(ledPin, OUTPUT);
}

void loop()
{
  if (! digitalRead(buttonPin))
  {
    Keyboard.print(password);                   //send the password string from abov
    Keyboard.press(0xB0);                        //sends an enter key press, inputting the password
    Keyboard.release(0xB0);                     //releases the enter key
    digitalWrite(ledPin, HIGH);                //turns on our blue LED
    delay(1000);                                        //waits, so that the computer isn't sent multiple key presses
    digitalWrite(ledPin, LOW);                //turns off the blue LED
  }
  if (! digitalRead(buttonPin1))
  {
    Keyboard.print(aptget);
    Keyboard.press(0xB0);
    Keyboard.release(0xB0);
    digitalWrite(ledPin, HIGH);
    delay(1000);
    digitalWrite(ledPin, LOW);
  }
    if (! digitalRead(buttonPin2))
  {
    digitalWrite(ledPin, HIGH);                             //Turns the blue LED on
    Keyboard.press(0xCA);                                    //Presses the F9 key
    Keyboard.release(0xCA);                                 //Releases the F9 key
    delay(1000);                                                     //delay before the next command is sent, to allow the program time to respond
    Keyboard.print("autossh -X server");               //Enters the string on the command line
    Keyboard.press(0xB0);                                    //Presses enter
    Keyboard.release(0xB0);                                 //Releases enter
    delay(1000);                                                     //Allows the program time to process before we start the next tab
    Keyboard.press(0xCA);
    Keyboard.release(0xCA);
    delay(1000);
    Keyboard.print("autossh -X vboxserver");
    Keyboard.press(0xB0);
    Keyboard.release(0xB0);
    delay(1000);
    Keyboard.press(0xCA);
    Keyboard.release(0xCA);
    delay(1000);
    Keyboard.print("autossh -X torrentbox");
    Keyboard.press(0xB0);
    Keyboard.release(0xB0);
    delay(1000);
    Keyboard.press(0xCA);
    Keyboard.release(0xCA);
    delay(1000);
    Keyboard.print("autossh -X plexserver");
    Keyboard.press(0xB0);
    Keyboard.release(0xB0);
    delay(1000);
    Keyboard.press(0xCA);
    Keyboard.release(0xCA);
    delay(1000);
    Keyboard.print("autossh -X livingroom");
    Keyboard.press(0xB0);
    Keyboard.release(0xB0);
    delay(1000);
    Keyboard.press(0xCA);
    Keyboard.release(0xCA);
    delay(1000);
    Keyboard.print("autossh -X raspi");
    Keyboard.press(0xB0);
    Keyboard.release(0xB0);
    delay(1000);
    digitalWrite(ledPin, LOW);
  }
}
"

- Button 0 sends my chosen password and then presses the enter key.
- Button 1 sends the apt-get update and dist-update commands, so I can quickly move from window to window in my terminal emulator to update all my servers.
- Button 2 shows a much more complicated series of commands. This one, one initiated in my terminal emulator of choice begins opening new tabs, enters the command to ssh into the server, and goes down the line.
- Button 3 is left open for now on my project, but if you read through the code you should be able to add a function to it fairly easily.

I am bad about commenting my code, so I hope it's easy enough to understand.

Search This Blog