Introduction: ControlBox: an Internet-connected Knob to Control... Anything!

About: Developer at Electric Imp
After putting together a half-dozen or so Electric Imp projects, it occurred to me that just because the imp is powerful enough to handle complicated tasks doesn't mean that making a simple thing internet-connected is any less powerful. This is one application that I find to be *very* powerful, particularly in the context of driving a simple physical interaction into "the cloud". It's a knob. A simple, familiar, analog control.

Ok, so I'm a little ahead of myself: if you aren't yet familiar with the Electric Imp, it's time to check it out. The imp is a tiny, powerful, wifi-connected processor that looks like an SD card. It connects easily to any wireless network, phones home to the Electric Imp service, and lets you connect all sorts of things to the internet and each other. You program it in your web browser using the electric imp planner. Check out the overview at http://electricimp.com/.

Right now I have my copy of this demo hooked up to a fun little board I use to control some in-ceiling RGB lighting. We've got more instructables coming along soon for that - for now you can check out the video we posted here. Check out the pictures - the kicker is that this method of controlling that light:
  1. is totally wireless and was installed in about the time it took to get the light in the ceiling in the first place
  2. works from anywhere in the world
  3. can be connected, disconnected, or changed (pre-program light shows or interpret inputs differently) from anywhere in the world, without tools, just by opening my browser. 

When you're ready, check out the next page and see the (short) list of things you need to connect a knob to the internet!

Step 1: What You'll Need

When you're ready to get started with this instructable, you'll need an imp. They're available on Sparkfun, along with the Electric Imp breakout board, which you'll also need. If you got one of Electric Imp's April dev boards directly from Electric Imp, you can use that.

In order to connect and program your imp, you'll need a computer, a wireless network for the imp to connect to, and an iOS or Android device with the Electric Imp app (free in the App Store and Google Play store). You'll need to create a free Electric Imp developer account, which is pretty quick to do. You can view all your connected imps at plan.electricimp.com.

You'll need a few other pieces as well, but the list is pretty short:
  1. An enclosure. Should be big enough to hold an imp+breakout board and battery (1.25" x 2.25") and deep enough to hold the aforementioned contents and leave room for the base of a potentiometer. I used a Serpac RB33-1TC1BC enclosure, which is about 1.9" deep, but you can get away with about 1.6" of depth.
  2. A potentiometer, 1k ohms or 5k ohms. Get a linear potentiometer, not a logarithmic one. Mine includes a switch (it clicks nicely when you turn it all the way counter-clockwise), and I incorporated that into my firmware. I recommend finding one with a switch, but it's not essential. Just useful.
  3. A knob for your potentiometer! The pot I used had a 6mm outer diameter on the shaft, so size the knob to fit. I like the kind with the set screw to hold it in place. 
  4. A battery pack or clip. It's not a good idea to run the Imp off of two alkaline AA batteries because they only give you 3V DC, and the imp needs 3.3V. The imp has an on-board regulator, but it won't even turn on until above 3.3V. You can use a 2-AA clip and a couple of UltraFire lithium ion batteries, though, because they're 3.6 V each. A 9V works too. Pick the appropriate battery clip.
  5. Optional: a toggle switch. I used an single-pole-double-throw (SPDT) or "changeover" switch, and I use it to switch between USB and Battery power. Since I usually don't have USB power available, this turns the power selector switch into a simple power switch. This lets me turn the box off and save battery when I'm not using it.
You're going to need a few tools, too:
  1. A decent soldering iron and some good solder. 
  2. Some spare wire. Solid-core is a bit easier to work with. 
  3. Some heat-shrink tubing is very useful. You can do without if you need to.
  4. If you're using heat-shrink, you'll need a heat gun to shrink it. A good hair dryer will do in a pinch. 
  5. Wire cutters / wire strippers
  6. A ruler for measuring out dimensions to drill holes in the enclosure lid
  7. A drill and a few drill bits:
    1. A center punch and a hammer to mark the center of the holes you're going to drill. This keeps the drill from "walking"
    2. A small drill for drilling starter holes. A 1/8" drill will do nicely. You'll start all your holes with this drill, then step up to the appropriate size drill bit for the hole. 
    3. The switch I used required a 3/16" drill bit for the final hole.
    4. The potentiometer I used needed a 5/16" drill for the final hole.
    5. The potentiometer I used also had a small tab to prevent the pot from turning when you turn the knob. This is pretty typical. The 1/8" drill should be enough to take care of this. 
  8. You might need to trim some length off the potentiometer shaft to make everything fit nicely. I used a dremel with a cut-off wheel for this. A hack saw works just fine, too. You'll have more success with the hack saw if you have a vice to hold the part still.

When you've gathered the things you need, check out the next step to see how to connect the potentiometer to your breakout board!

Step 2: Step 1: Attach the Potentiometer to the Imp Breakout Board

Quickly attaching parts to your Electric Imp is exactly what the Electric Imp breakout board is made for, so this step is pretty easy. We're going to connect four wires - three between the potentiometer and the imp, and one bridging two pins on the potentiometer, for a total of eight solder connections.

A quick aside on potentiometers: a potentiometer, or "pot", can be thought of as a resistive divider with a variable ratio; two resistors that always add up to the same resistance, but can be varied inversely to each other. The two outer pins connect to either end of a long resistive track; the resistance between these pins is always the same (the marked value of the potentiometer, in our case 5k ohms). The middle pin connects to a "wiper", a movable pin that touches the resistive track between the two other pins. The position of this middle pin on the resistive track is controlled by the position of the potentiometer knob. Turn the knob counter-clockwise, and you decrease the distance between the first pin and wiper, decreasing the resistance between those pins. At the same time, the distance between the wiper and third pin increases, increasing that resistance. 

What this means for us is that if we apply a constant voltage across the fixed resistance of the potentiometer and use the imp to measure the voltage at the wiper, we'll "see" a voltage that is between 0V and the voltage we apply to the pot, depending on the position of the wiper. The imp has an analog-to-digital converter on every user-accessible pin, so we can very quickly convert this voltage to a usable number in software, and we're off to controlling things from the internet!
  1. Cut some pieces of wire. Give yourself plenty of length. I cut pieces about 4" to 6" in length. I used three colors here to keep things clear for myself.
    • We're going to connect a signal line between the wiper of the potentiometer and one of the imp's user-accessible pins. I used blue wire for this. 
    • We'll connect the right side of the potentiometer (from the front, see the pictures) to the 3.3V supply on the breakout board. Red wire is a good choice here. 
    • The left side of the potentiometer (again, from the front, check the pictures) will be connected to ground on the breakout board. I used black wire. 
    • You're also going to need to connect the bottom switch terminal on the pot to ground. The closest ground is the left pin of the pot, so bridging these two pins with a short piece of wire is most convenient. You'll want to cut this wire and put it in place before you solder the wires to the pot. A 1" piece of black wire will do just fine. 
  2. Solder your wires to the pot:
    1. Strip the ends of the wire. An 1/8" of bare wire at the end should be sufficient. If you have a good pair of angle cutters, you can trim the extra wire off when you're done. 
    2. Secure your potentiometer in place. I taped mine down to my solder station with kapton tape. You can use a "helping hand" for the same purpose. Make sure you secure the base of the pot, not just the shaft, as it'll spin and your wires will fall out if you don't. 
    3. Hook the bare wire through the appropriate solder lugs. I like to avoid twisting the wire up in the solder lug too much so that I can disconnect and re-use things if I want to. Taping the wire in place once you have everything positioned makes this much easier. 
    4. Apply the soldering iron to the solder lug and wire. The goal here is to heat the parts that we're going to solder, then use the hot parts to melt the solder; we don't want to melt the solder with the iron directly as it will lead to a weak "cold solder" joint, and likely break. 
    5. Flow a little solder into the joint by applying it to the heated solder lug.
    6. Pull the iron and solder away gently and wait for the solder to cool. You'll see the solder go from shimmering silver to a sort of matte finish as it cools. 
    7. Repeat for each terminal.
  3. Solder the appropriate wires to the breakout board. Remember:
    • The red wire goes to the 3V3 (3.3V) terminal.
    • The black wire goes to GND (ground).
    • The blue wire attached to the potentiometer wiper goes to Pin 8 on the breakout board.

To solder these connections:
  • Strip about 1/8" of insulator off the end of each wire
  • Put the bare wire through the hole in the breakout board
  • Heat the pad on the breakout board and the wire with the soldering iron. Be gentle; there's not much metal here so you won't need to add much heat. You don't want to press very hard or scrape the board with the soldering iron, as you can damage the breakout board. 
  • Flow a little solder onto the pad. It should form a nice little cone on the pad with the wire in the middle
  • Remove the heat and let the solder cool
  • Trim your extra wire with wire cutters

Alright! The potentiometer is connected! Next step: we'll connect the switch (if you have a potentiometer with a switch). Check your work against the pictures and move on when you're ready. 

Step 3: Step 2: Attach the Potentiometer's Built-in Switch

Even quicker than step 1! We're going to make three solder connections in this step. 

The built-in switch in the potentiometer I chose is nominally closed; the two switch pins are connected until you turn the pot all the way to the left until it clicks. On the imp, what we'll do is set up a digital input on one pin with an internal pull-up resistor. Then, we'll connect one side of the switch to this pin on the imp, and the other side of the switch to ground. When the switch is "turned on", this will connect the imp's digital input pin to ground, driving it low. When the switch is "turned off", the internal pullup resistor (inside the imp, configured in software) will hold the line high. 

Since we're running another signal from the potentiometer to the imp, I used blue wire again. You'll want a piece about 4" to 6" in length, and go ahead and strip 1/8" of insulation from each end. 
  1. Using the same technique we used in soldering leads to the potentiometer lugs in the first step, solder one end of the blue wire to the top lug on the back of the potentiometer body.
  2. Remember that 1" black jumper wire we soldered to the left terminal in the last step? Solder the other end of it to the bottom lug on the back of the potentiometer now. Check your work against the pictures.
  3. Solder the other end of the blue wire you attached in step 1 to Pin 7 on the imp breakout board. Again, we've got some pictures here for you to check your work. 

With that done, you're all wired up! In the next (optional) step, we wire up a power source selector switch so that you can quickly cut power to save battery or switch between battery and USB power. 

Step 4: Step 3: Add a Power Switch

The electric imp breakout board gives you two different options for a power source for your imp; you can either the 5V supply provided by a USB connection, or power the imp from a battery. Either way, the power is regulated by on-board circuitry to give the imp the 3.3V supply voltage it needs.

On the Sparkfun breakout boards, the terminals for these two power connections are unpopulated. On the boards from Electric Imp, there's a three-pin male header with a little plastic jumper used to connect two of these pins at a time. We can handle either situation. 

First, let's put some leads on your toggle switch. A SPDT switch just selects between two connections: for each switch position, one connection is on, and one connection is off. The center pin is always connected; the switch selects which of the two outer pins it's connected to. Three wire colors is again a good idea here to keep you from getting confused. I used blue wire for the center, yellow for one side, and black for the other side. 
  1. Cut your wire leads to about 4" to 6" in length and strip the ends. Use the same technique we used with the potentiometer, solder the leads to the switch. 
  2. Since my switch was pretty small, I used a bit of heat shrink to keep things looking neat and prevent shorts. Trim a bit of heat shrink tube with the wire cutters, slide it down the wire over the solder joint you just made, and heat it with the heat gun. 

IF YOU ARE SOLDERING TO A THREE-PIN HEADER:
  1. Tape your breakout board down and put some solder on each of the header pins. Heat each pin with soldering iron, and with the heat applied, flow a little bead of solder onto the pin, then remove the heat. Be careful not to bridge the pins with the solder. If you do bridge the pins, a solder sucker or a little bit of solder wick can be used to clean up.
  2. Tape the wire ends down and apply a little solder to the end of each wire, using the same technique as we used in step 3. 
  3.  Cut a bit of heat shrink tubing and slide it onto each of the wires. Slide it down good and far from the end of the wires; we're not going to use it in the next step, but we need it on the wire before we solder the other end to the header. You want it far enough away so that it doesn't get heated while you're soldering and shrink in place. 
  4. With the breakout board still taped down, grab the wire with a pair of tweezers and hold it against the appropriate pin. If you don't have tweezers and you're doing this by hand, be careful to keep your fingers far enough from the metal so you don't burn yourself.
    • The blue wire goes to the center pin.
    • The yellow wire goes to the battery pin (marked "BAT")
    • The black wire goes to the USB pin (marked "USB")
    • If you switch yellow and black, don't worry. It will still work exactly the same. Heat the pin and wire until the solder on both begins to flow together. Remove the heat, but hold the pins together until the solder cools. Repeat for each of the three pins.
  5. Slide the heat shrink tubing down the wire over the new solder joints you've just made and heat it with the heat gun. All set!

IF YOU ARE SOLDERING TO HOLES ON YOUR BREAKOUT BOARD:
  1. Use the same procedure we used in the previous two steps to solder the wire leads from the switch onto your breakout board.
    • The blue wire goes to the center pin.
    • The yellow wire goes to the battery pin (marked "BAT")
    • The black wire goes to the USB pin (marked "USB")
    • If you switch yellow and black, no problem, it works the same. 
  2. Trim the wire leads on the far side of the board with angle cutters. All set!


Check your work against the pictures, and let's connect some power to your board and test it out!

Step 5: Step 4: Power!

Alright, so we've got all our hardware in place, but we're not internet-connected yet. For that, we're going to need some power. Again, a nice quick step.
  1. Tape your Electric Imp breakout board down to keep it from moving around. 
  2. One at a time, apply a bead of solder to each of the battery pads on the breakout board. These are big, rectangular pads marked "P+" and "P-". The positive side of your battery clip almost certainly has a red wire, and the negative side a black wire. Red wire to P+, black wire to P-.
    1. Apply the soldering iron to the appropriate pad
    2. With the iron applied to pad, flow some solder onto the pad until you have a little raised bead of solder. 
    3. Remove the heat
    4. Repeat for the other pad
  3. Grab the appropriate wire on your battery pack or clip with tweezers and solder it down to the board
    1. Hold the bare wire against the solder bead you just made
    2. Heat the bare wire and solder bead with the iron until the solder flows and the wire drops into the bead
    3. Remove the heat and hold the wire in place until the solder cools

Done! Install your battery or batteries, push your Electric Imp into the imp slot on the breakout board, and verify that the LED in the Imp begins to blink. Next, we'll connect your imp to the internet!

Step 6: Step 5: Connect

Alright, time to get your imp connected.
  1. Open your browser and go to plan.electricimp.com. Sign into your Electric Imp account. While we're here, now is a good time to grab the firmware for the board you just built.
    1. Open another tab and go to https://github.com/tombrew/ei-fw-tom/blob/master/april-controlCenter.nut.
    2. Select the code in github and copy it to your clipboard
    3. Back in the planner, click the "Code" link at the top
    4. Click the big "+" button at the top of the code window. This opens the Electric Imp IDE.
    5. Paste the code you copied into the IDE
    6. Click the save button in the top left of the IDE
    7. Go back to the Code view and click "rename" next to your new firmware. Give your firmware a new name. 
  2. Open the Electric Imp app on your mobile device. Sign into your account and make sure the nearest wireless network is  added to your list of networks. Add it now if you haven't already. 
  3. Insert the Imp into the imp slot and power on your breakout board. If you added the battery and the imp and it didn't start blinking, flip your power switch - you've probably just got USB power selected. If you're running on USB power, you won't need the battery!
  4. Verify that the LED in the imp starts to blink. 
  5. Select the local network on your mobile device, press the "send blinkup" button, and hold imp up to the screen of the mobile device. The screen will send a series of flashes to the imp, which tells the imp the SSID and password of the network it should connect to.
    1. The imp will blink green once after a successful "blinkup", and red several times after a failed blinkup. If you have trouble getting this step to work, try covering the top of the imp with your thumb to shield it from ambient light, blinking up in a darker place, or check the electric imp forums for more assistance
    2. A new blue node will pop up in your plan. This is the imp you just blinked up! It will say "BLANK" on the node, because the Electric Imp service doesn't know what this impee (board with an imp in it) is supposed to do yet.
  6. Click the settings button in the top-right corner of the blue box in the planner to get a popup where you can select the firmware the imp should run. 
  7. Select the firmware you made by copying the code from github earlier.
  8. The imp should start running the firmware in a few seconds. The text in the blue node will change to "April Control Center"
  9. Also in the planner, you should see a number between 0 and 1 in the middle of the blue box representing your new impee. This number should change with the position of the potentiometer knob.
  10. If you turn the pot all the way counter-clockwise to turn the switch off, you should see the number in the planner turn to "off"
That's it! You've got an internet-connected knob! Now you can add an "HTTP Out" node in the electric imp planner with the "Add node" button and start using this interaction to drive all sorts of things, or connect the value to other nodes and impees in your planner.

For some extra style, I boxed my impee up in a nice enclosure. Check out the next step for some guidance on that.

Step 7: Step 6: Into the Box

Alright, time to pack it all up so it looks nice!
  1. Secure the lid in place. A vice is great for this. Make sure that whatever is under the lid won't be damaged by the drill.
  2. Mark out the positions for the holes you'll drill in the lid. You'll need to drill three holes:
    1. A 5/16" hole in the center of the box for the potentiometer shaft.
    2. A 1/8" hole for the tab on the potentiometer (if applicable) 1/2" from the center of the hole for the potentiometer shaft. I put mine directly to the right of the center of the potentiometer. 
    3. A 3/16" hole for the power switch. I put mine above the potentiometer hole. Mine was a little too close - my fingers run into the power switch when I'm turning the potentiometer. Go for about 1.25" from the center hole.
  3. Center-punch each of the holes with the hammer and centerpunch. 
  4. Drill each of the holes with the small starter drill, then step up to the larger drill to drill the final hole. 
  5. De-burr the holes with sandpaper or an x-acto knife. 
  6. Feed the potentiometer shaft through the hole from the inside of the lid. Place a washer and the nut included with the potentiometer over the potentiometer shaft, line the tab up with the small hole, and secure the pot in place with a wrench. Don't over-tighten - you can crack the enclosure if you do.
    1. You may want to trim the excess off the potentiometer shaft before or after this step. Secure the potentiometer shaft with a vice or something similar and cut it off with a dremel or saw. I cut the shaft down to 1/2" in length.
  7. Feed the toggle switch through the hole for the switch, add a washer and the provided nut, and tighten gently with a wrench.
  8. A bit of double-sided foam tape is great for securing your breakout board to your battery pack.
  9. Another bit of foam tape is also great for securing the board and battery to the bottom of the box.
  10. Gently tuck the wires into the box and place the lid on the box.
  11. Tighten the provided screws to tighten the lid on the box. You'll need a small torx wrench if you use the Serpac enclosure I used. 
  12. Put the knob on the potentiometer shaft. Line up the indicator line. I recommend turning the potentiometer all the way to the left of right for this. 
  13. Tighten the set screw with a small allen wrench to hold the knob in place.
Check it out! All done!
Hack It! Contest

Finalist in the
Hack It! Contest