Showing posts with label Arduino. Show all posts
Showing posts with label Arduino. Show all posts

Thursday, March 23, 2017

IR to IP Bridge with Arduino

Looks like I've been away for a while...Well it's worth it, cause I searched high and low for something to accomplish this and came up empty.

I recently got rid of my Harmony remotes (which had seen 10+ years of faithful service) in exchange for a URC control system. It always felt like the Harmony was getting in my way in an attempt to be helpful (like Clippy, that obnoxious little paperclip MS put on us). In contrast, URC is very straight forward for someone with a little programming knowledge. I love them!

One this they allow is for amazing customization and total house control. Once I got the basics of the IR and base stations figured out, I started to fully integrate the home controls. HDMI matrix in the equipment closet, each of the four main level televisions connected to it with each room's remote able to talk to each room's RF base station.

Then it hit me! The only thing I need to really be inside the "home of tomorrow" is remote-based control of my lights. Already having a robust Insteon system powered by the incomparable ISY-994i, I finally used the ISY's IR receiving.

Loading the 40 pre-built IR codes into the URC remote's CCP software was a breeze. Then making a program on the ISY to look for those IR signals and turn on or off the appropriate lights was simple enough. I already was using tabletop controllers and Insteon's wireless keypads to do this, but now I have one remote to do it all. You could easily have it dim the lights when you press play and raise them when you pause for that cool theater effect.

Once this was working, I somehow caught wind that Roku (my set top box of choice) allows for a lot of fine grained IP control. You can remotely query which apps are installed, which one is currently running, send remote key presses, or (and this is where I salivated) make it launch a particular program.

One thing the Roku's do not have is a super full featured remote. The included remotes are simple and have few buttons. They do have a couple (depends on model) direct app access buttons (Netflix, Amazon, etc.) but they have yet to come out with a remote that allows quick access to the apps that I use most often (Plex, or more accurately Plex RARFlix, and PS Vue). Roku's network control guide gives you the framework to launch whichever app you desire, but only through an http POST request. URC's "Complete Control" series, which is what I use as a DIY guy, do not have IP control. Their higher end, and fully locked down, "Total Control" do, but that wouldn't be DIY and wouldn't be fun.

Luckily for me, the ISY has a networking module from which you can send HTTP POST and GET requests. Combine that with an IR trigger and voila, I've got direct access to my favorite Roku apps. However, for some reason the ISY wasn't liking to learn new remote codes for me. So I was limited to the 40 in-built codes. This quickly was dwindled once I started to play.

What I really needed at this point is an IR-to-IP device. My Google-fu skills are tip top, but I wasn't able to find anything, other than possibly an irTrans device. Those were fairly expensive for what I'd want and would have to come from the EU.

So what I present here is an Arduino powered IR receiving, IP command sending device. It'll take whichever IR command you want to use and, upon receiving it, send an HTTP command over the network.

The hardware is simple. Arduino of your choice (I initially used an UNO clone, but moved to a Mega for more memory), an ethernet shield, and an IR receiver.

Anyone who's worked with Arduino should be able to understand the code. IR receiver needs to have the data pin plugged in to pin 8 on the Arduino in my example.

Here's the code:

----------Code Starts Here--------------

#include <SPI.h>
#include <Ethernet.h>
#include <IRremote.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //MAC Address of the Arduino
char rokutheater[] = "192.168.1.254"; //IP Address of the target device
EthernetClient client;
IPAddress ip(192, 168, 1, 250); //IP Address of the Arduino
//IPAddress gateway(192, 168, 1, 1); //Uncomment if you need Internet access
//IPAddress subnet(255, 255, 0, 0);
int RECV_PIN = 8; //Pin the IR Receiver is on

#define TheaterPlex 2397 //IR code when the desired IR remote button is pressed
#define TheaterPlex2 349
#define TheaterPSVue 2372
#define TheaterPSVue2 324
#define TheaterHome 52275

IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
  Serial.println("Serial Output Begun");
  Serial.print("My IP address: ");
  ip = Ethernet.localIP();
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(ip[thisByte], DEC);
    Serial.print(".");
  }
  irrecv.enableIRIn();
}

void loop()
{
if (irrecv.decode(&results)) {
        unsigned int value = results.value;
        switch(value) { //Branch off to the correct subroutine based on the received code
       
          //Theater
           case TheaterPlex:
             TheaterRoomPlex();
              break;
          
           case TheaterPSVue:
             TheaterRoomPSVue();
              break;
          
           case TheaterPlex2:
             TheaterRoomPlex();
              break;
          
           case TheaterPSVue2:
             TheaterRoomPSVue();
              break;
          
           case TheaterHome:
             TheaterRoomHome();
             break;
        }
        Serial.println(value); // Sends the received IR button code to the serial monitor, helpful to find new keys or otherwise debug
        irrecv.resume(); // Ready to receive the next command/value
      }
}

//-------------------THEATER-------------------------
void TheaterRoomPlex(){

    client.stop();

    if (client.connect(rokutheater, 8060)) {
    Serial.println("connecting...");
    client.println("POST /launch/13535 HTTP/1.1");
//    client.println("Host: www.arduino.cc");
//    client.println("User-Agent: arduino-ethernet");
    client.println("Connection: close");
    client.println();
    Serial.print("Plex on Theater Roku"); 
    delay(500);
 
  } else {
    Serial.println("connection failed");
  }
}

void TheaterRoomPSVue(){

    client.stop();

    if (client.connect(rokutheater, 8060)) {
    Serial.println("connecting...");
    client.println("POST /launch/93374 HTTP/1.1");
//    client.println("Host: www.arduino.cc");
//    client.println("User-Agent: arduino-ethernet");
    client.println("Connection: close");
    client.println();
    Serial.print("PS Vue on Theater Roku"); 
    delay(500);
 
  } else {
    Serial.println("connection failed");
  }
}

void TheaterRoomHome(){

    client.stop();

    if (client.connect(rokutheater, 8060)) {
    Serial.println("connecting...");
    client.println("POST /keypress/Home HTTP/1.1");
//    client.println("Host: www.arduino.cc");
//    client.println("User-Agent: arduino-ethernet");
    client.println("Connection: close");
    client.println();
    Serial.print("Going Home on Theater Roku"); 
    delay(500);
 
  } else {
    Serial.println("connection failed");
  }
 
}

----------End Code------------

You'll need both the Arduino Ethernet library (found here) and shirriff's IR Remote library .(found here)

Any IR Receiver will work, but I used the YwRobot IR Receiver breakout board out of convenience like this one. I also used a generic Arduino Ethernet shield. I'd imagine with a little tweaking, you could use an ESP8266 or a wifi shield too. That'll probably be my next step. 

I also used a generic Arduino UNO R3 at first, which the above code compiles to use 56% of program storage and 44% of ram. Using a Mega2560 clone, it compiles to use about 7% storage and 11% ram. So if you're only going to use it for a few commands an UNO is capable, but I only wanted to build the device once, so I went with Mega.

Now, to just find someone who is good at programming and making websites. Ideally, I wouldn't have to hook it to a computer to program it. Would be nice to use the SD card functionality to serve up a web page that would display received IR codes and allow you to create new commands to send when a code is received. I would think that this would be fairly easy, but beyond my basic skills. I guess this leaves me plenty of room to continue to tinker.

Meanwhile, I've now been using it, shoehorned into a plastic project box, for a week to test its function. It has operated flawlessly thus far. Even by my standards I'm impressive sometimes!

UPDATE 07/01/2018

For some reason this past week this system quit working on me. For some reason, the Rokus suddenly stopped liking the formatting of the HTTP POST messages in my code.

After some troubleshooting, I stumbled across the solution. Remove (or comment out) these two lines in each section of your code:
    client.println("Host: www.arduino.cc");
    client.println("User-Agent: arduino-ethernet");

I've updated the code above to reflect these changes. Not sure why this change was necessary. So if you used my code, you need to update the Arduino a bit.

At least it's an easy/quick change.

Thursday, March 26, 2015

RFID Garage Door Opener with Arduino

This week I took a leap to add RFID access to my garage door. This was largely spurred by how flaky my manufacturer's wireless keypad is for my opener in the cold weather. I wanted something hard wired, and I knew RFID was fairly cheap to add to Arduino. And it's freaking awesome!

This setup isn't network aware, so you cannot monitor the status of the garage door or add/remove keyfobs remotely. You're getting short on digital pins on a standard UNO/Leonardo, so you'd probably want a Mega if that was something you wanted. I will probably add that in the future. I've never done WiFi with the Arduino, so this would be a good opportunity. I'll probably also look at adding a real time clock module so I can permit access only within certain windows (such as giving spare fobs/cards to family but only allowing entry during the day).

First you'll need an Arduino. I've used both UNOs and Leonardos with this build and they both work great. You'll also need an RC-522 reader, available on Amazon and eBay. This is easy to integrate with Arduino. Extra cards/fobs are also nice, and you'll want to get ones that work with "Mifare" in the 13.56Mhz band. These are also available for cheap in bulk from the 'Bay.

You'll also want to use some sort of relay or transistor as your output. In this case I used a regular Arduino-compatable relay module. I liked that it gives me an audible click for testing purposes, but a solid state relay or transistor would do just as well to trigger a garage door opener (which just momentarily touches two wires together). 

RC-522, with right angle pins (included) soldered on
I took my code and inspiration from miguelbalboa's GitHub. His code uses a single RGB led for feedback, which I found works the best. I tried paring this down to two leds, but you really want all three.

Hook the pins up as follows:

* 3.3V on Arduino to the 3.3V on the RFID reader.
* Pin 9 on Arduino to RST on RFID.
* Pin 10 on Arduino to SDA on RFID.
* Pin 11 on Arduino to MOSI on RFID.
* Pin 12 on Arduino to MISO on RFID.
* Pin 13 on Arduino to SCK on RFID.
* Red LED to Arduino Pin 7
* Green LED to Arduino Pin 6
* Blue LED to Arduino Pin 5
* Finally, your output relay on Arduino Pin 4
* There's an option for a reset button to be used on Pin 3. This reset button will wipe the memory of all cards, so you can start fresh. This is nice when you're first playing with things. 

The code from Miguel is annotated to allow for both common anode or common cathode RGB LEDs.

First time you boot it up, watch your serial console in the Arduino IDE to make sure you know what's going on. The first card you scan becomes the "master" card that puts the system into program mode (where you can add or remove cards).

Once you scan a master card, put the system into program mode. All three colors will flash in sequence. Now begin scanning additional cards. A successful "add" will be followed by two green flashes. If the card is already part of the system, then scanning it again removes it. Successful removal is indicated by two blue flashes. You'll see this written verbosely in the serial console. The LED feedback is needed once you install it in the field.

Cards are stored in the ATmega's EEPROM and so will survive a loss of power. This EEPROM has a limited number of writes (about 100k), but can be read unlimitedly. Realistically you could add and remove cards in normal usage for years before you hit the write limit.

I breadboarded mine, with an LED hooked up to the output to see how well it operated.


 Then it went into a case I had lying around.


In the right photo you can see the two relay module at the bottom. 

I used a Rugged Circuits Aussie Shield to connect everything up in the finished product. This was just easier than soldering a prototype shield, which would have been much cheaper. This is a great product to use, and in the future will be much easier to repurpose than a soldered up protoshield.

The wires coming into the case include the five control wires for the RFID reader and the four wires for the RGB feedback LEDs. There's also two wires that tie into the garage door opener's button circuit. I made the wiring harness myself, which is why the level of craftsmanship is so unbelievably high.

I have intentionally left the reset button off the physical build (but in the software). This means that to reset (erase all the memorized cards, including the master) the system, you need to manually jumper pin 3 to ground. To me, this works, since I don't want someone who is clicking buttons to accidentally reset everything.

You'll also notice that I used a separate box for the "brains" of the system, the Arduino and relay. My initial inclination was to shove this all into a single gang box with only a power wire and the garage door triggers coming in/out. My wife insisted that it be "hack proof", so I put the smarts (and the garage hook ups) on the inside. If you take off the wall plate outside, in order to hack into the system you'd still need to simulate the RFID board (protocol and the correct key codes).

I hotglued the RFID board directly to a plastic faceplate. This doesn't seem to interfere too much with the signal, but you do have only a couple of millimeters range to begin with. You basically need to touch the fob to the plate to get a read. This is a little more awkward with the credit card style than it is with a keyfob. 


Here's the finished outdoor portion, with my wiring harness fed through a hole into the garage. The box (initially surface mounted) has been recessed into the garage trim.

The blue is intentionally dim. I put an extra resistor on that part of the circuit when I put the recessed box together so that it wasn't a bright blue beacon for the neighborhood. The green and red are of "normal" brightness to give a clear indication of a read. 

Overall this was a simple build, since it doesn't involve network access or a RTC. However, since it doesn't use those you get a rather "dumb" appliance. This can be good, since it seems like the more functionality you add, the more points of failure you encounter.  I'm also only using one output. I've got an extra relay that might find some usage in the future.

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 21, 2014

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