Access control, from the circuit board up

This is part 3 of the 'building a custom steel entryway and gate' series, but it's a bit of a different project than the welding and concrete pouring you've seen so far.

Find part 1 here: Custom driveway gates part one
and part 2 here: Custom driveway gate part two
Design files, schematics and code for the project that follows can be found here: Cj's gitlab


Custom electronics, custom access control

So I've had some time to admire my gate design. It's working great but still missing a latch, but I've decided that's not quite enough; a custom gate and fence deserves a custom electric opener. Ok, so the high cost of any quality dual-swing gate opener is certainly a factor. I'm sure the motors and actuators are solid products but it seems the markup on access control systems is pretty drastic even for the most basic actuator with a keypad. Wireless remotes and underground sensors cost even more, and maybe I can integrate it with my own automation systems; or maybe I can't. Turns out, I have most of the parts and some code for such a system mostly complete from some earlier projects. So I'm going to start Kicad up again and build myself a custom dual-swing gate opener that can integrate with whatever other systems I want. If you're interested in my R&D adventure for cheap and custom gate control, read on!

Some thoughts on design concepts and keeping things simple

For most electronic projects I design, I start with a big list of wants and features and then try to pair that down to whats essential, what's most valuable, and what's most achievable without horrible long development cycles. Trying to build circuits or write code too complex to complete and debug in a timely manner is a recipe for orphaned projects. Trust me I know. I'm a member of feature-creeps anonymous: I get all sorts of big ideas for one-size-fits-all fill-every-use-case designs that are great on paper with all sorts of cool stuff. Turns out wiring a string of sensors together to a microcontroller is a lot easier than writing code for it all, with long spaghetti logic functions that don't play nice with each other. Loading up a circuit board with lots of sensors, counters, and amplifiers can get complicated in a hurry too. An ATMEGA microcontroller, a radio module, and a thermometer is pretty easy to get going, but bundle a suite of digital sensors together with switch-mode regulators, radios, power saving and charging circuity and now you'll have a time of it debugging all sorts of strange glitches of cross-talk and EMF feedback and other mysterious behaviors. This leads often to a drawer full of 'I'll get back to that later' projects that languish for years. I'm probably not the only one who has problems with this right? I guess the point of this tangent is that it pays to keep it simple. Maybe look far enough to the future add some room for expansion and new program features, but keep a narrow focus and get the basics of a projects running reliably first. Then maybe look at adding the fancier features. As they say of the Unix design philosophy: Do one thing and do it well...

Collecting design requirements

Ok, so what do I need for double gate opener? Let's start with the physical hardware:

  • Linear actuators seem like the obvious choice for the actual motive force to apply here
  • Some method of telling the gate how and when to open: do I want a keypad, an RFID card reader, a remote control, or a combination?
  • Safety devices: This isn't a heavy gate, and this won't be a powerful actuator. All the same it's bad form to dent a car door when the delivery guy lingers too long, or worse of course if a person got a limb caught between them. Again these can be a combination of things like an electronic eye, an underground coil to detect vehicles, etc.
  • A power supply setup
  • The resulting bracketry, pins, whatever to hold everything in place and an enclosure to keep the electronics out of the weather.

So here's the hardware to start with:

  • A pair of 220lb-force linear actuators from ebay: . The actuators are 16" stroke length, and move about 1/2" per second. Should be plenty of strength to open the gate from fairly close to the hinge, and will take about 30 seconds to fully open or close. Maybe a little slow, but I think it will be adequate.
  • A Lora/SX1278 radio module, as my driveway is longer than any wi-fi could reach and it's a favorite radio for my sort of 'property area network'. I might add a keypad later. There's also an RFID reader in a drawer around here somewhere.
  • For the microcontroller, an Arduino 'Pro-mini', which is really an ATMEGA328p running at 8Mhz and 3.3volts. This just avoids a need for logic level shifters for 3.3volt only devices like the radio. I like using header pins and sockets in a project like this; it's easy to pull the controller and take it back to the shop for some software updates.
  • My safety plan: a pair of INA219 current sensing modules. These actuators claim to pull 3 Amps at full load, but these gates are unlikely to take even an amp. So the idea is to measure that current carefully and, if more current than is usually needed is detected, assume the gate has hit an obstruction and reverse direction. I may need more sensors than that to make it reliable, but I'll start there and do some through testing.
  • Perhaps I could dig the trench and run AC power in conduit underground all the way from the garage, but that sounds like a lot of work. So I've got a small solar panel, a standalone PWM charger, and a pair of 8 amp-hour 12v SLA batteries to run it all.
  • I've got a nice aluminum NEMA enclosure to hold it, and the rest of the hardware bits I will mostly design as I go.

So for the circuitry, we only need a couple things: An MCU, the radio module, some power regulators, the INA219 current sensors, and to drive the actuators: two pair of relays in an H-bridge configuration. I'll cover more of this later, but it's basically a backwards three-way light switch than can reverse the polarity on the the motors to drive them in two directions.

Now here's the schematic

schematic
There's no bonus points for minimum-size here so I'm going with all through-hole parts where possible. A little easier to debug and modify in development if necessary. So here's the two H-bridges with their current monitors, some extra capacitors and flyback diodes to protect from the relay coils and any back-EMF from the motors. There's some expansion headers in case I need extra safeties like an electronic eye, and the I2C lines have terminal blocks because I'm going to try and integrate my magnetometer vehicle detector into the same package: https://gitlab.com/motivemachine/magneto-driveway-alarm
But you know that endless feature-additions I was on about earlier? This is what I mean. The pins are exposed for future use, but I'm only going to focus on getting the code working with the basics before ad1ding in more possible random glitch generators.

Then that becomes a printed circuit board

Not much to this 2-layer layout. Relays out the bottom, power inlet and I2C out the sides, radio towards the top. Don't forget the mounting holes- I've done that more than once.
circuit board layout

H-Bridge dc motor control

The H-Bridge, especially one built with relays make a quick and easy way to reverse the voltage polarity through a DC motor. Consider the following schematic:
Hbridge
So here we have two relays, pretty standard SPDT with the common (usually central) contact connected to each wire of the DC motor. The normally closed (NC) contacts connect to ground and the normally open (NO) contacts connected to positive voltage. This can be done with a double-throw-double-pole (DPDT) relay as well, but the SPDTs like what I've got are very common, especially in those premade banks of relays available for Arduino and Raspberry Pi projects. Now if any one relay is fired, we'll have a current flow from that relay through the second relay and on to ground. Simply switch which relay is high and which is low, and now the current flow through the motor windings the other direction and it spins the other way. This design is also very safe and just about any failure mode results in the motor not moving. If both relays are turned on at positive voltage, the lack of voltage differential is just the same as grounding both relays and therefore both motor wires: current doesn't flow, so the motor doesn't turn. In the event of only one relay being stuck on, our safety is the limit switches built into the actuators.

Parts arrival

These are quite possibly the cheapest linear actuators money can buy; yet I think they will be quite adequate between the light weight gates and the ball bearing hinges.
unboxed actuator
Only two weeks after ordering my latest PCB package has arrived. Yes that's right, I now have 10 gate opener control boards when I only need one... that's the minimum order but it was still $10 for all 10 boards. Shockingly cheap. Possibly useful in future projects that need reversable DC motor control.

In the same box was boards for three other projects. More parts, for more projects, for more blog posts:
new pcbs unboxed

A few board assembly pictures

Quick bodge repair

Well the design was good, but my bill of materials was not. I ordered surface mount when I needed through hole parts for the current-sense resistor. Here's how I fixed that anyway:
bodge repair

Finally a completed controller:

done

Hooked up and testing on the bench:

bench testing

Installing the actuators

Well I've got some nuts-and-bolts hardware to sort through next. I started sorting through some buckets of brackets and found some stainless steel angle that would be a good start. The actuators didn't come with any kind of hinge so I bent a couple up out of some 1/8" aluminum.
bracket building
I really wanted these gates to open a little beyond 90 degrees, so I'm going to weld a piece of steel angle onto the side of the post. This provides a flat place to bolt the brackets on and also offsets it from center to give the actuator a little more room between it and the gate. To work out exactly what angles everything needed I bolted these random bits together, extended the actuator, and adjusted everything until the gates lined up straight when closed.

When the retacted, the gates open about 110 degrees, perfect!
adjusting brackets
So with those measurements taken I cut up some stainless steel brackets to make a nice pair of heavy duty, forever weather-resistant brackets. After final adjustment I think I'll drill another hole by each pivot to lock it in place. There's just too much leverage for simple clamping pressure to keep things from working loose after a while.

Final welding and hardware installation

So now I've got the angle base-plates welded onto the posts, some brackets built and welded to hold the solar panel, and the enclosure to hold the electronics drilled and mounted. It's starting to look like something now!

Another in progress picture, with the trench for 3/4 PVC holding the wires to the second actuator:

wip

Inside the control box. A cheap PWM solar charger, 7ah SLA battery, and the board:

inside control box

Project complete, pending further testing...

My biggest mechatronics project to date, and I'm super excited. So far everything works as expected, but I'm sure there will need to be some changes made if/when problems develop. This project is crossed off my to do list for now, but check back in a few months after everything has been through its first winter, there will likely be some lessons learned and adjustments made.

Picture taken after a few weeks of testing and the first snow of the year:

gate complete