Saturday, June 19, 2010

Taking Forever to Fix the Garage Door Opener Pt. 2

In Part 1, I admitted several of my failures, at least one of which wasn't very compatible with the boards I was using from Radio Shack. I also noticed that my soldering skills seemed much better when I was soldering on a Printed Circuit Board rather than a prototyping board. I recently purchased a copy of Practical Arduino which gave me some ideas on how to solve a couple of other challenges I had with other projects. My main frustration with the introductory chapter was that it didn't give any good tips on soldering using a prototyping board. What I did find was a rather cool tutorial on surface mount soldering written by the author. That tutorial looked even easier than what I was doing with through the hole soldering. It was also the final push that I needed to try having my own printed circuit board created.

The design of my board is really quite simple (even though I couldn't get it right). I shared part of the schematic in Part 1, that is, the screw up trying to create an inverter with an NPN transistor. Here is the whole schematic:


This is actually the second iteration of the schematic. The first one didn't have a Vcc net and when I let Eagle autoroute the board, I at least noticed that the 7804 chip didn't have it's power pin connected to anything. To solve that problem, I created a Vcc net and connected it to the 5v net and everything seemed to route like I wanted. Although I wasn't very confident in the design, I shipped it off to BatchPCB anyway so that it might be ready when I got back from vacation.

I got the board on Thursday and started soldering things up. Here's the way it looked when I thought I was done:




Of course, my test program didn't work and I quickly found that I had made the same mistake twice...this time in the form of a printed circuit board! ARGH! Well, At least that mistake wasn't too hard to fix. I needed a resistor between Pin 12 and the base of the transistor, so I soldered one end of a resistor in the hole meant for the base of the transistor and then connected the base lead of the transistor to the other end of the resistor. My pretty board isn't so pretty, but at least that problem was fixed.

Unfortunately, my test program still didn't work. The test program adds a couple of LEDs that I just jumper from the female headers on the shield. The test program doesn't get through the initial indication that all of the parts are there...that is, the program resets. If I disconnect one of the LEDs, the program runs farther before resetting, so I believe that my problem is that I'm shorting power somewhere and the processor resets due to the lack of power.

My initial thought was to verify how the buttons and switches were wired. Using a tutorial by Lady Ada, I found a completely different schematic than what I was using. First there was a 100 Ohm resistor between the +5 rail and the Arduino pin. Second, there was a 10K pulldown resistor between the switch and ground. The tutorial talks about different resistor values and specifically talks about wasting power if you choose too low of a value. I'm not sure how I would rig up both resistors, but I could at least try replacing my 1Ks with 10Ks. I tested the ability of the Arduino to read the state of the switch using my schematic with 10K resistors instead of 1K resistors and it didn't seem to have any problem. So I desoldered the 1Ks for each switch and soldered in 10Ks instead. So now the board looks like this:



It might not be easy to see, but the mess to the left of "Relays" is the resistor soldered into the hole for the base lead of the transistor. That's why the transistor is sitting so high on the board. The 1K resistors have been replaced by 10K resistors except for the one at the top right of the board.

With high hopes, I went back to my test program. It didn't take long for my hopes to be dashed. Right now I'm stuck with two problems that I haven't been able to track down. First, the 10K resistors didn't change the fact that the program resets with what appears to be a power failure. Second, the "down" relay is activated when the program fires up. If I have the relay connector plugged in, the program resets almost immediately. The relay activates and drains the power, then deactivates as the board resets. If I don't plug in the connector for the relays, but do have the connector for the external LEDs that come on when the relays are active, the program runs longer. The "down" LED lights almost immediately upon program startup and stays lit until the program resets...which takes a bit longer without the relay connector plugged in. Long enough, in fact, for me to measure values coming out of the AND gate.

And this is where I have a real problem that I can't figure out. Pins 12 and 13 are both read zero on my volt meter. Pins 1, 2, 4, and 6 all read zero as expected. Pin 5 reads 5 volts as expected. Pin 3 reads 4.7 volts. That's supposed to be the output of the AND gate supplied by Pins 1 and 2. Even stranger is that this pin is supposed to control the 'up' relay. Yet it is the down relay LED that is lit. So part 3 of this mess won't be coming until I figure some things out.

Friday, June 18, 2010

Taking Forever to Fix the Garage Door Opener

We have a commercial garage door opener that opens a 12 ft x 16 ft door on our trailer shed. The opener failed a couple of years ago and the repair consisted of a service call and an over priced part. When the opener failed again last year, I somehow convinced my wife that I could build a circuit board that would take over the job of controlling the opener motor and not have to pay for a service call again. Of course, our door still isn't working.

The process of creating a circuit board using a micro-controller and a couple of relays seemed fairly straight forward. In fact, it still seems straight forward even though I have failed thus far in creating the board. In my first attempt, I purchased an Arduino Pro Mini from Sparkfun, a simple prototyping board from Radio Shack, and various electronic components to be able to read the state of the buttons and limit switches. The Mini has 12 holes on each side in which I soldered male header pins. I made a little socket in which to plug the mini by soldering female headers on the prototyping board.

The garage door opener motor is controlled by switching power on one of two wires. Which wire you switch determines the direction the motor runs and therefore the direction the door moves. I purchased one relay for each wire, but I wanted to make sure that I couldn't activate them both at the same time. The relays are easy to control with an output pin of an Arduino, but rather than wiring a pin to each relay, I decided to put a logic chip in between to make sure that only one relay could be active at a time. I used pin 13 to indicate whether or not I wanted the motor to be active (HIGH means running, LOW means stopped). I then used pin 12 to determine the direction the motor should run (HIGH means up, LOW means down). Pins 12 and 13 are connected to an AND gate with the output of the gate driving the relay that makes the door go up. Pin 13 is also connected to a second AND gate, but I needed to invert the value of Pin 12 before connecting it to the other input. The output of that gate drives the relay that makes the door go down.

I'll stop here to admit that I'm not an EE major, I'm a computer science major. I'm good at programming. Things that may be obvious to an EE major, aren't obvious to me until I screw up good! I purchased a logic chip in a 14 pin DIP package, but I didn't want to waste the board space on an inverter chip, so I contrived a way to use a transistor as an inverter. Again this seems straight forward, but there was some fundamental knowledge that just isn't there for me. Even after I figured it out, I managed to make the mistake again! Here's the diagram of what I did:
The top line in the picture is Pin 12, the one under is Pin 13. The idea was that when Pin 12 was high, the transistor would ground input 6. When Pin 12 was low, the transistor would not connect the collector and emitter and the input on the gate would be high. Unfortunately, I discovered that when Pin 12 was high, all of its current was grounded through the transistor and input pin 2 was pulled to ground. The top AND gate would never yield a high value. Of course, I'm getting ahead of myself because I didn't actually discover this until the second version of the board!

The first problem I had was that I couldn't get my program to upload to the Mini. I built a simple little programming board that contained the same female header that I had built on the prototype board. The "socket" connected the appropriate pins of the Mini to the programming header. Unfortunately, the mini wouldn't take the program. I still have no idea why. So I changed gears and decided to use an Arduino Pro that I had purchased a while back.

The next thing that I have to admit is that I make stupid mistakes while I'm soldering up wires and I have to desolder and re-solder too often. The cheap prototyping boards from Radio Shack don't stand up too well to this and the copper foil they use to connect holes peels up. I had already moved the power supply portion of the board to a different area because I had destroyed a whole section. Most of what I had done would have to be moved now because the foot print of the Arduino Pro is so much bigger than the Mini (as the name would suggest). So I started a new board.

As an example of making stupid mistakes, I didn't wire the 7408 from a diagram but from trying to match the wires on the previous board. However I screwed it up, I managed to swap one of the input pins and one of the output pins on each gate. And wouldn't you know it, the relays didn't work! I actually managed to desolder the wires and wire it up correctly without doing too much damage to the board. It was then that I discovered the problem with the transistor. By the time I got that straightened out, I was having problems with the board resetting and my connectors kept coming apart.

So I ordered polarized connectors that would clip when connected, desoldered the old connectors and soldered in the new ones. The board looked pretty nice from the top...the bottom showed off how many mistakes I had made:



At this point I decided to take the learning experience one step further. I would design my own Arduino shield using Eagle and have a PCB custom made for my project. I'll relate my experience with that in part 2!