Wednesday, October 25, 2017

Arduino Project One: A long-distance garage door remote

Want to keep updated on this project? See the end of this article for a list of all progress reports.



Introduction

I've enjoyed "hobby computers" for a long time. I have more than one each of Raspberry Pi, C.H.I.P., and Arduino. There are many others out there, but I don't spend enough time with the ones that I have. I have worked through the tutorials, and I have done some breadboard constructions that are rather fun, but I haven't done any serious work with any of them.

Our garage door opener has given us a scare a couple of times in the eleven years that we've lived in this house. Twice, we have come home to find that it was open when we thought it was closed. The first time, a large lime against the door frame on one side caused the door opener to reverse, lest the closing door squish the lime. The second time, the door forgot where "closed" was, touched the ground, and opened again. Why did it forget? It could have been the house settling, the concrete heaving, or something slipping in the door opener mechanism.

After the incident with the lime, I started getting paranoid about the garage door. Don't tell anybody this, but I have driven two miles back to the house, just to drive past and make sure the garage door was really closed.

Finally! I have a great idea for a hobby computer project! I will build a web-based garage door sensor and actuator. I'm sure it's never been done before! I'll commercialize it and make millions!

Research on the State of the Art

Actually, in the world of hobby computers, I'm a few years behind. A Web search for "Arduino garage door" shows how many people have already done it.

Moreover, in the world of commercial, web-based, garage door sensors and actuators, I'm way behind. Here's a kit for only $120 from Overhead Door (or Genie).

I don't care. I'm going to do it anyway, just because it's fun.

Basic Design

So here's a basic design. TODO: Insert a graphic, a block diagram of the system.

Sensor
Actuator
Computer
- Arduino
- Wifi shield
Either a tiny webserver on the Arduino, or some executable code on a private webserver
Browser-based interface
Android app

Now for the details:

Sensor

A garage door can have three states: fully open, fully closed, or moving.

No, a garage door can have five states: fully open, fully closed, opening, closing, or stopped in the middle.

That's too much work. How are you going to keep track of all of that? You could put a shaft encoder on one of the rotating parts of the opener. That would let you tell if it was opening, closing, or stopped — but not whether it was fully open or fully closed. That's three states, but not the two that matter most.

One solution online was to use two powerful magnets and a Hall effect sensor, with the magnets positioned on the drive chain exactly where "fully opened" and "fully closed" should be. That allows the garage door to have three states: fully open, fully closed, or somewhere in the middle and presumably moving.

A one-button controller for a garage door opener works like this: press the button to start it moving. Press it a second time to stop it moving. Press it a third time to start it moving in the opposite direction. The door opener stops automatically at the fully open and fully closed settings. This takes us back to the five states.

How about we simplify the problem? I only care whether the door is or isn't fully closed. If it's not fully closed, then it's moving up, moving down, fully open, or stuck in the middle, and I don't care. Those all count as not fully closed — or open.

I already know that a photosensor and reflector wouldn't work reliably at our house. The photosensor might get confused by the sun's glare on summer mornings.

I could mount some kind of sensor (magnetic, photovoltaic, pressure) flat on the concrete, and the door would come down flat on top of it. This might not work in the winter, when we get a layer of ice on top of it.

I could mount a 3D linear accelerometer on the top panel of the door. When that panel goes completely vertical and stops moving, then the door is closed. I like this idea! But the accelerometer has to have some way to communicate with the computer, and it's attached to a moving door. 

Reed switches. Mercury switches. Mechanical things wear out. What if there were a mechanical switch that doesn't wear out? My pilot son had a great idea.

Aircraft have a switch built into the landing gear, called a squat switch, or a weight-on-wheels switch, which tells them when the aircraft is solidly on the ground. Some things in the aircraft, you don't want to have happen until the plane or helicopter cannot fall out of the sky. These switches are, by necessity, extremely robust. A squat switch will tell you whether the airplane is or isn't on the ground.

Where to mount the switch? Well, when a garage door closes, the top of the door is pressed flat across the lintel of the door frame. (The lintel is the horizontal part across the top. The vertical parts on the sides are called the posts.) When the door starts opening, the top of the door is pulled away from the lintel, and no other part of the door touches the lintel. So the lintel seems like a good place to mount a squat switch.

Now I just have to get one. My son, the pilot, is finding a source for me.

After thinking about it overnight (no wonder I didn't sleep well!) I realized that the location for the squat switch — top of the door, top center of the lintel — is also an ideal place for a magnet and Hall effect sensor. So if the squat switch ends up being expensive, I'll go back to SparkFun for one of their ACS712-based Hall effect sensor boards.

Actuator

The garage door opener is an Overhead Door SilentMax 4040. Installed by Yours Truly eleven years ago, it works as well as the day I put it in. Its rubber belt drive is almost completely silent, especially after I lubricated the belt with a thin spray of white grease a few years back.

The SilentMax 4040 has a wired remote on the wall of the garage, with two buttons: one for the door, and one for the light. Only two wires go into the opener itself, so the wired remote must do something to differentiate between the DOOR button and the LIGHT button. And it does. Here are the pertinent details:

  • With no buttons pushed, a 4.1Vdc difference exists between the terminals on the opener.
  • Pushing the DOOR button shorts the two terminals, so there's a 0.0Vdc difference for around 200 ms.
  • Pushing the LIGHT button doesn't short the terminals, but engages a voltage divider, so there's a 2.76Vdc difference between them.
Since I don't care about the light, I can just have the computer switch a relay. 
Anyway, I'll need to attach a relay to the same terminals used by the wired remote. The computer will switch the relay, which will duplicate the action of the remotes.

Computer

A Raspberry Pi or a C.H.I.P. would be overkill for this project. You don't need Linux to open and close a garage door. I'll use an Arduino. In fact, I'm going to go really old-school and use an Arduino Uno. I have two to choose from: a Redboard from SparkFun; and an Uno R3 from Elegoo. I should be able to run the same program on both boards. I'll try the Elegoo first. It's brand new, and I want to try it out.

The Arduino has general-purpose digital inputs and outputs that will work just fine for the sensor and the relay. I'll need to add a transistor to the relay output, and perhaps an op amp or other buffer to the sensor input.

For Wifi capability, I have two choices from SparkFun: either the Electric Imp, or the  ESP8266. Both solutions are versatile enough that someone smarter than me could figure out how to use the Electric Imp or ESP8266 by itself, without the Arduino, to do this project. I'm not that smart. Both solutions come in either an Arduino R3 shield form factor, which is ideal for my Arduino Uno boards, or in a smaller "breakout" board. I ended up buying both.

I tried the ESP8266 shield first. It worked the first time I powered it up.

I tried the Electric Imp next. It didn't work. That is, I couldn't get it to connect to my Wifi router. The setup requires you to download an app to your tablet or smartphone, power up the Electric Imp, hold it next to the phone screen, and run a function on the app which transmits your Wifi router information to the Electric Imp by strobing the phone screen into a light sensor on the Electric Imp. When the strobing is completed, you're supposed to wait up to 90 seconds for the Electric Imp to connect to the Wifi router.

Wouldn't it be simpler just to set up a serial connection to the Electric Imp and type in the SSID and password manually? It would certainly make troubleshooting easier. The concept of the Electric Imp is intriguing, but if I can't make it work, what use is it?

Since I'll be using an Arduino and a Wifi shield, and one can stack an infinite number of shields on an Arduino (as long as the pin assignments don't conflict), I bought the Relay Shield from SparkFun. I will stack it on top of the Wifi shield - or maybe the Wifi shield should be on top. We'll experiment.

The hardware as of 26 Oct 2017 (rawr)

Webserver

My first implementation will use a webserver. This could be a mini-webserver on the Arduino, or on the Wifi board (like I said, they're both versatile enough to handle it), or on a private server. All three are viable options right now.

I should probably use a port, for a couple of reasons — the main one being that it gives me some security, however weak. How many low-level hackers are going to be trying different ports?

For the sake of security, the webserver will require some kind of authentication. This is important so that some random hacker doesn't spend all day running my garage door up and down for his own amusement. This could be as simple as a login and password. 

In the long term, I'll also want some kind of security between the webserver (if it's remote) and the Wifi. One of the prior implementations used a dual challenge and response: the server sent the host a hashed number, and the host then replied with the unhashed number. If the number was correct, then the host sent the server a hashed number, and the server had to unhash it and check it. I dunno yet. I'll figure this part out later.

The basic procedure will go like this:
  1. Requester sends authentication; host accepts or rejects it.
  2. Host queries the Arduino for the current status of the door.
  3. Arduino checks the sensor and replies to the Host.
  4. Host tells door status to the requester.
  5. Requester pushes the button to start or stop the door. (Or exits, if they're satisfied with the status.)
  6. Host sends the Arduino the "button" command.
  7. Arduino energizes the relay for 200 ms.
  8. Host queries Arduino once per second, for as long as the requester is logged in or the app is open.
  9. Requester exits the app, Host and Arduino go idle.

Browser-based interface / Webpage

The browser-based interface will be as follows:
  1. Welcome screen: login, password
  2. Main screen
    1. Status indicator: green and "open" or red and "closed".
    2. A big button, labeled "Push this button" or something like that.
    3. A smaller "Exit" button.
    4. An even smaller "setup" button - to specify the Wifi's IP address.
  3. Under the hood
    1. Queries the Arduino once a second.
    2. Sends button pushes to the Arduino.

Android app

The Android app would do basically the same thing as the browser-based interface, without the need to login. Well, maybe - as a security precaution, in case the phone is stolen.

Software Tools

The Arduino is programmed in its own dialect of C. The ESP8266 is controlled using good ol' AT commands. The Electric Imp is programmed in a C-like language called Squirrel. The webserver could be JavaScript, perl, or who knows what else?

For the Android app, I considered using Xamarin, but I didn't want to get trapped in the Microsoft tar baby, so I'm going with Corona. It's advertised as a 2D game engine, but it's much more powerful than that. I've used game engines before, and I know what they can do. Besides, I can get some expert help with Corona.

Proposed Enhancements

I've seen people connect spy cameras to hobby computers. I'd like to connect a camera to the Arduino or the ESP8266, and have a tiny picture of the garage door on the main screen.

I need to measure the time it takes for the garage door to close. If the door status is "not closed" and someone pushes the button, the door status should changed to "closed" in a reasonable amount of time. If it doesn't, then the status should change to "there's a problem".

I'm not afraid of a more complicated state machine. With the right sensors, I could incorporate all five states. I'll try other sensors, if I can figure out how to make them work &mdash and if they're reliable.

Not that it affects the basic functionality of the machine, but I'm going to have to do some graphics work to create the objects that make up the app. Call me old-fashioned or steampunk if you will, but I still enjoy the skeuomorphic user interfaces that Apple and Microsoft used to use and have since abandoned. My app is going to have a couple of old-fashioned indicator lights mounted in chrome or bronze bezels, a 3D push button bigger than a fingertip, and a black leather (or black crackle-finish or black powder-coated metal) background.

Project Timetable

There isn't any timetable. This is a hobby, a just-for-fun DIY project. But here's a list of milestones as they occur.

25 Oct 2017 First draft of this project plan is written. Happy birthday!
26 Oct 2017 Added details about the Wifi shield and relay shield from SparkFun.. Added details about the wired remote.

Updates

I ended up posting each update as a separate article. Here are the rest of them.

Saturday, October 21, 2017

John Kelly, you have disappointed the nation.

John Kelly, you were one of the last people in the White House that I respected. Now you're just like all the rest of them: a big fat liar.

That was the short version. Here's the medium-length version.

I listened to MSNBC's "All In" on the radio yesterday. Chris Hayes is the host.

Chris Hayes played John Kelly's entire talk to the press, where the White House chief of staff told, in detail, the story of Florida Congresswoman Frederica Wilson's speech at the 2015 dedication of a new FBI building in Miramar, Florida. He told a convincing story about how she had spent her time at the podium taking credit for the building, and how she had personally gotten a $20 million commitment from then-President Barack Obama to build the building. According to Kelly, her whole speech was about herself and how great she was, especially for bringing the pork home. In his words, "... we were stunned." The gall of the woman's ego and self-promotion was beyond — well, beyond almost anybody in modern history, except perhaps Donald Trump.

Well, the Florida Sun Sentinel had dug up a videotape of that dedication ceremony, and All In had obtained a copy of it. So Chris Hayes played Congresswoman Wilson's speech, in its entirety. She told a story about how, four weeks before the dedication, the FBI had approached her and asked to have the building named after two FBI agents who had been killed in the line of duty. That literally takes an act of Congress, and so Wilson talked about how she had contacted the leadership of both the House and the Senate, and gotten that act of Congress through in record time. There was nothing "stunning" about it. She spent the rest of her speech praising the FBI, law enforcement and first responders in general, everyone involved in raising the building, and her colleagues in Congress for helping to get the building named.

She didn't say anything that John Kelly had accused her of. She bragged a bit about rushing that bill through Congress, but it was a fun story, and she gave credit to all of the other players.

As for the $20 million from President Obama, Wilson pointed out to reporters this week that the $20 million was appropriated by an act of Congress in 2009, and she didn't get elected to Congress until 2011.

Everything John Kelly said about her was a lie. Everything.

The long version? If I'm able to find a transcript of Kelly's words and one of Wilson's speech, I'll add them to this post so that you can read them for yourself.

UPDATE, JUNE 24, 2021: I still haven't found the transcript. But here's a Washington Post article from October 20, 2017, corroborating what I said.

Friday, October 20, 2017

An inside joke for an audience of one

I talk to a lot of people on my morning commute. I talk to the DJs on the radio. I talk  to the texting app on my phone (guilty as charged, yer honor). I talk to my car. I talk to the traffic lights, especially the red ones. I talk — politely, of course — to the other drivers on the road. And I talk to myself.

I have fun conversations with myself. Sometimes I even make myself giggle.

For example, this morning I was coming up behind and to the left of a VW Beetle that was stuck behind a slowpoke in the right lane. I said, "Come on over, bud, there's room for you." Then I said to myself, "Actually, that's Bug, not bud."

It was an inside joke for an audience of one. The audience liked it. I thought that you might like it too.

A QUESTION FOR YOU: What do you talk about, when you're alone in the car?

Monday, October 9, 2017

Looking ahead to 2020

Every day with President Donald Trump is a new disaster. We try to distract ourselves with hurricanes, earthquakes, mass shootings, and a trust-fund baby juggling nuclear missiles, but Trump is like the guy at the party who manages to insert himself into every conversation in the room — and ruin it.

If the USA were a publicly traded company and he were the CEO, the shareholders would have kicked him out by now. Too bad it's not that easy to get rid of the Chief Executive of the United States.

It's clear now that electing him was a disaster. Don't worry, if Clinton had gotten elected, we would be saying the same things about her. The 2016 election was a lose-lose proposition.

What can we do to make sure the 2020 presidential campaign doesn't go the same way?

Well, this article on NBC News got me thinking about 2020. The second-to-last paragraph says:

Late last month, [retiring Tennessee Senator Bob] Corker announced that he would not see[k] re-election, fueling speculation that he might challenge the president in a GOP primary. 
Unencumbered by the need to watch his mouth and make sure he gets re-elected to the Senate, Corker has been speaking his mind. Speaking truth to power. Calling out, repeatedly, that the emperor has no clothes. Using his bully pulpit to stand up to Trump and Co.

I don't know, he's starting to sound downright presidential. He would be a better president than Trump.

DETOUR:

After Vice President Pence's little rehearsed stunt at the Colts-49ers game yesterday, I'm starting to believe Corker would be a better president than Pence, too.

If you want to read about Pence's stunt, Google "Pence walks out". Every link I found was biased one way or the other. Read multiple sources to get a balanced view. But it was rehearsed. It was a stunt — a rather expensive stunt.. And if his airfare and hotel were paid for by the U.S. taxpayers, then shame on him. I used to respect Mike Pence.

About Pence's stunt, the great Tom Peters tweeted:

Wonder if POTUS gave VPOTUS a "good puppy" dog buscuit after yesterday's scripted showboating episode?

BACK ON THE MAIN ROAD:

If Bob Corker is serious about running for president in 2020, then he needs to start now building a few things:
  • A team - an organization.
  • A "base". Trump and Clinton have made this a dirty word, but it's still necessary.
  • A platform - a statement of what he believes in, what he's running for.
  • Knowledge.
  • More name recognition.
  • Credibility.
  • Likeability.
  • Even more visibility.
  • Popularity. It shouldn't matter, but every election in the past 100 years (longer?) has proven that it matters bigly.
HERE'S ANOTHER IDEA:

This year, the Mormons have proven to be faster and more effective than the federal government when it comes to disaster relief. Witness the responses to hurricane Harvey in Texas, Irma in Florida, and Irma and Maria in Puerto Rico (and the U.S. Virgin Islands), and the earthquakes in Central America. LDS Welfare Services started shipping supplies, in their own trucks, even before the hurricanes hit. Local and global LDS leadership was on the ground even before the rain stopped falling. Thousands of LDS volunteers were organized and working hard, in force, before the feds ever showed up. Maybe it's time we put a Mormon in the White House?

I don't know if Mitt Romney wants to give it another try, but I think it's pretty clear that he would have been a much better president than the current occupant. If not Mitt Romney, then how about Jon Huntsman Jr., the statesman, businessman, and diplomat?

But don't vote for Huntsman — or against him — just because he's a Mormon. Vote for him because he's a good man.

ON THE OTHER HAND:

I wouldn't mind if the 2020 election turned into a race between two great women — for example, Condoleeza Rice and Madeline Albright. Come on, people, this is the 21st Century. There must be some viable options besides white, allegedly Christian, males.

And there are definitely viable options besides Democrats and Republicans. If enough people opened their eyes and had the courage to vote third party, we would break the duopoly these parties have on the presidency, a duopoly which has proven to be unconstructive, easily corruptible, self-serving, and unfortunately, self-perpetuating.

I don't care if the next ideal candidate is Democratic, Republican, or Pirate Party, as long as it's a person of maturity, integrity, wisdom and vision. All of the above. In no particular order.