Close
0%
0%

OpenOpener

Open source (software and hardware) DC motor controller for electric gates

Similar projects worth following
A few days ago, I wanted to add an RFID reader to my electric gate opener because HF remote controls are quite expensive. Unfortunately, during the wiring of the reader, I screwed up the existing controller board (with a short-circuit on the mains transformer...). Too bad for me, I should have disconnected mains power before that. Lesson learned. As I can't find any decent schematic on the web, I decided to design my own bi-DC motor controller. Of course, I want to add some nerdy features that usually cost a lot on this type of consumer electronic devices (like wifi-enabled electric gate opener).
The feature of this boards are:
- 24V DC motor controller x2
- automatic search of the limit switch (with overcurrent detection)
- remote control (HF 433MHz or ISM band)
- dry-contact input for RFID reader, keypad, mechanical key...
- uart interface to an embedded computer (Raspberry Pi typically, but most linux SBC should be fine)

I have seen many hacks about remote triggering automatic gate openers (wifi, bluetooth, whatever-wireless-protocol-connected). But, correct me if I am wrong, I cannot find any open source hardware project about a controller board for a typical 2 motors configuration usually found in a lot of houses like the one I live in.

Finally, after burning the existing controller board delivered with the (proprietary) automatic gates (silly me), I decided to design my own board and make it OSHW (and software).

It is a way for me to learn a few things I have in minds since quite a while: kicad software, decent power switching motor H-bridge.

System design document:

Here are the features that I need to make an automatic gate opener to work for a dual arm entrance gate:

- 2x H-brige for 2 DC motors (24V like most of the automatic systems). The motor-controlled arm opens and closes, so each motor must rotate in both directions.

- a current monitoring device for each H-bridge to detect the limit of each gate (fully open and fully close). It is similar to a electric car window device: when a peak current is detected, controller stops the motor. An overcurrent condition may be caused by an obstacle (cars, children, ...) during an opening or closing movement, stop the gate has to stop to be secure.

- acceleration-controlled start and stop: to prevent too much inrush current, the motor has to follow an acceleration curve to prevent inrush current during the start or stop phase. Moreover, the gate tends to oscillate if the motor starts and stop brutally. So it is better to keep those critical phases under control. The motor is connected to its DC power supply via a MOSFET. By switching its gate with a PWM output of a microcontroller, we can speed-up or slow-down the motor with the PWM duty cycle.

-  My double-wing gate has a priority to respect whether it opens or closes. So the controller has to setup two different sequences for the opening or the closing process. I have to implement a delay between the first and the second arm.

- Ideally, I want my controller to be smart enough to learn (at the initialization of the board) how many time it needs to open or close. In that way, the controller can time-out if a sequence lasts too much time. It should also report some issue. This "smart" feature should also determine the delay beetween each arm and the speed of the motor (it must slow down in order not to bounce againt the mechanical limit of the arm).

- Most of the automatic gate controller have an awful human-machine interface: if you have more that a few leds and push-buttons, your controller must be very pricy. So I'd like to implement a wizard interface to initialize the system. There are a few steps that has to be humanly assisted to setup the controller for your particular needs. Let's make them understandable, at least by me, and preferably to my mother also. It could be as simple as a USB cable to a terminal program that writes, in plain english text, what you have to do and what the controller is actually doing. Not pricy at all, but way better than morse code on 2 or 3 leds (I wish I could decode Morse code too, but it is another story).

- HF remote control, because I am lazy :-)

- rfid reader in case the remote control battery fails

- dry-contact input to add a  push button, a mechanical key, ...

- I want a gateway to a computer board (like a raspberry pi or another SBC computer). Well, I don't need that, but I am miserable and with all that Internet of Things thing, I feel it is mandatory these days to have a wifi controlled gate opener ;-) More seriously, it is nice to log unwanted events in case of something goes wrong and I want to keep the system open(!) for future features like a video intercom.

  • 1 × ATMega328P / Arduino pro mini board Microcontroller to sequence everything
  • 4 × relays Easy a reliable way to make an H-brige for a DC-motor. Scale-up easily for different DC motor powers.
  • 2 × shunts and current shunts monitors Mechanical limit switch detection with overrcurrent detection
  • 1 × IRFB3006 MOSFET: power interface to flaslight. Visual indicator when the automatic gates are opening or closing.
  • 1 × Nice HF 433MHz receiver Remote control for Nice remote Tx. Because I hace already 3 of them, but should be easily swappable with other models.

View all 7 components

  • Code

    Manu05/03/2015 at 21:33 6 comments

    Well, I never posted any code for that project, because I forgot it, let's correct that:

    Arduino Pro Mini 5V w/ ATmega328

    Read more »

  • Adding flashing light

    Manu05/03/2015 at 21:23 0 comments

    A little update to support the existing flashing light to my custom dual motor controller.

    It's a simple 24V bulb with a 555 integrated timer and a TIP120 transistor on a PCB (I should have done a photo of the existing PCB...)

    It's very simple to use: just apply 24V (DC or AC, a Graetz diode bridge rectifies if AC and allow plug any polarity you want) and the light bulb blinks every 5 seconds or so.

    To apply 24V to the light, I used a Grove relay module from seeedstudio connected to pin D12 of the Arduino board.

    It's ugly but it works.

  • TODO list

    Manu01/22/2015 at 00:51 0 comments

    My proto board does its minimal requirement: I can open an close the automatic gate with a remote control.

    Yet, I have some bugs to fix:

    - add a proper antenna to the 433MHz receiver: in open field, I can open and close the automatic gate about 10-15 meters away from the receiver. But when I'm in my car, with an athermal coated windshield which filters IR to prevent overheating in summer but blocks also some useful RF data links, it only works 2-3 meters away. It would be a great improvement to add an external antenna with some coaxial cable to the receiver. For the moment I only have a piece of copper wire badly positioned in the case. I would have a better sensivity if an antenna was on a door post.

    - I use an external interrupt pin on the arduino board (INT0 - digital pin D2) connected to the 5V logic output pin of the remote control receiver. This thing is a little picky and should be more debounced. As the remote control has only one push button, a state machine follows a sequence like this: STOP - OPEN - STOP - CLOSE - STOP - OPEN ... at every pulse generated from the remote control. Sometimes, when from a stop state, it skips an OPEN or CLOSE state immediately to a STOP state if a glitch happens. Maybe some more coding could fix it (or a more filtered/flip-flopped D2 pin).

    - current sensing: as the motor power supply is only rectified, but not filtered nor regulated, the current in the motors is pulsed at 100Hz (2x50 Hz mains frequency in Europe). I am currently using a peak detector (10xopamp + diode + cap//resistor) and a basic RC low-pass filter to smooth it out, but it needs to be tuned.

    - current sensing without diff amplifier: when the 2 motors run, the shunt resistor "see" the other mother and the current value is impacted. By tweaking threshold values in software, it works, but it is not satisfying. I need to work to isolate the both current measurements from the 2 motors.

    Things that I would like to improve:

    - clean the power supply to power motors and logic board from the same 24V rectified. I am using a 24V regulated power brick temporally in order to prevent microcontroller brown-outs. Kinda ugly, I would prefer just one cable from mains power.

    - add a mosfet to switch the original flashing light. It is annoying not having a visual indicator when the opener is doing something.

    - add an xbee wireless uart to do some checks from my house (especially when it's raining outside). I have a little command interpreter in the arduino code which is a more user friendly than a single push button remote control.

    - add rfid (because I can).

    - replace the proto board with a clean custom pcb to save some real estate in the case.

    - software: estimate the angular position of a gate by timing it from a mechanical limit. For fun, maybe, but it can be useful when it stops before gates reaches their fully open or fully close position as you need to maintain about 3 seconds between each gate to prevent them from colliding.

    Things to give up:

    - connecting a raspberry pi is not very useful at the moment. Maybe if I add a camera module, but I don't feel like doing it until next spring.

    - watchdog timer: I need to double check AVR datasheets but it seems that 8 seconds is a max. It also seems that the bootloader has issue with it. So, I am relying on the timeouts I implemented in software to return from error states.

  • First goal achieved

    Manu01/21/2015 at 23:52 0 comments


    It's been 2 months since I have installed my proto board and it works barely well.

    It is a minimal system compared to my first intentions: it justs open an close the 2 arms of my opener from the original remote control (433MHz).

    I made some adjustements to make it usable before winter:

    - no more mosfet pwm control to slow down the motors before they stall. At the nominal voltage, everything runs fine as it take about 20 seconds to fully open, or close, the doors. I don't want to slow it down because, even when an arm reaches its mechanical limit, it is slow enough not to damage anything. So, let's use the maximal speed.

    - to make my proto board fits in the original case, I switched to an arduino pro mini

    - as the original 24V is just a rectified 24V without filtering (I removed the, maybe dying, original big electrolytic cap) it only powers motors. Yet, I added a 24V regulated power supply from the main ac power supply (230V here in Europe) stepped down to 5V to power the logic part of the system (little Traco Power integrated switching module under the arduino Pro Mini).

  • Always check power supply first

    Manu09/29/2014 at 19:42 0 comments

    Ok, I assumed that my 24V power supply was somewhat regulated and it's not. Just a Graetz diode bridge behind a transformer inside the motor case of my existing opener. As a result the voltage that is powering the motors is just redressed but not regulated. As you can imagine, when a (dc) motor is driven, the current that flows through it follows the voltage waveform. Unfortunately, my opener controller was supposed to stop an arm when an overcurrent is detected. Because of the non-continuous nature of the current, I coudn't sample shunt resistor voltage at random time to detect an overcurrent stall condition. I finally decided to solve it in hardware with a cheap diode/cap peak detector followed by a lowpass filter. I also added a median filter in software to avoid artefact from the shunt resistor. I will add oscilloscope captures to illustrate it, but I have a nice stable current value. It is not as accurate as a rms-to-dc converter but I don't need the exact current value: I'm only interested in the trend to dectect that a motor is stalling. So far, so good, I will continue to make my own opener controller in my spare time.

    Yellow trace : "24V" power supply (rectified, not filtered nor regulated)

    Blue trace : motor current (1V = 1A : 0.1ohm shunt resistor and a x10 amplifier)

    On average, a motor sinks 1.3A and a peak of 5+Amps occurs when the motor starts and when it stalls.

    A close up:

  • HF pinout guessing

    Manu08/25/2014 at 22:45 1 comment

    I own an OXI receiver with a few remote controls. As I don't have a pinout of the receiver, I checked which of the 4 output pins react when the remote control is pushed.

    I connected the 4 output of the 433MHz HF receiver to 4 digital inputs of an Arduino Duemillanove (with a piece of breadboard I already have for IR testing).

    With a simple sketch, I detected an output pin toggles for about 500ms when one of the remote control's buttons is pushed. This receiver output will be connected to a digital input of my dual gate controller board.

    The forth pin of the 10-pin header is toggling:

    thin edge of the oxi Rx

    xx

    xx <- this pin is toggling

    xx

    xx

    xx

    (thick edge)

    pin 1 & 2: antenna

    pin 4: signal

    pin 7: +5V

    pin 10: GND

  • Breadboarding time (sort of)

    Manu08/25/2014 at 22:32 0 comments

    As a proof of concept, I stacked a few Arduino shields to test if I can stop a gate with overcurrent detection. My setup is composed of:

    - (mandatory these days) Arduino Uno

    - seeedstudio grove shield, (very handy) to add 3 push buttons: Open, close and stop test functions

    - protoscrewshield with screw terminals to connect power supplies, motors, ...

    - relay shield: 4x 3Amps 24V relays

    - a revamped board of mine (hot-glued on top) with (very basic non-inverting) amplifiers and 0.100ohms shunt resistors.

    On my installation a motor sinks about 0.5A in normal conditions. I measured a 5A stall condition, so I setted a 2.5A limit to stop a motor. An inhibition time of 1 second is used to ignore the first second when a motor starts and its currents consumption increases before stabilize after about one second.

    I used a dummy load from arachnid labs to test if the microcontroller triggers when current reaches its limit.

    As the current shunt voltage analogRead() function only get a sample from the AtMega controller, I will add some sort of filtering to dampen the spike that might occur and the voltage shunt measurement. (Probably a moving average filter).

  • You shall not pass

    Manu08/19/2014 at 00:07 0 comments

    ...unless you have the remote control, the rfid tag, or whatever makes the input detect a pulse.

    I want to keep the remote control as simple as possible: just one button. So I have to implement a finite 4-states machine: OPEN - STOP - CLOSE - STOP. One clic on the open opens the gates, an other stop them, an other make them close and another one stop them.

    The motion controller detects automatically (when a sufficient time has passed) that both gate are in the stop state with the current sense system. In this case, a clic on the button starts the gate in the opposite way than the previous move (it closes if the gates are fully opened and opens it the gates are fully closed).

    So any pulse on the input make the controller change between these states. In intend to remote it with 3 sources:

    - the HF remote controls that I already have. As long as the receiver will work, I will use them, but they are not my best choice: they are powered by 12V batteries, that are pretty uncommun compared to 1.5V AAA-size battery.

    - the rfid reader: rfid tags are cheap and can be found in many shapes (card, button, wristbands, even rings!). No power is necessary (on the tag side obviously, if there is no power on the reader side, well, ... the motors cannot move too, so it not a real problem).

    - rapberry pi connected to my wifi router: it is an excuse to learn to write a small app on a smartphone and setup a decently securised web server on a pi).

    That beeing said, anything that is a dry contact (push button, relay, ...) can control the gates.

  • Current sensing

    Manu08/18/2014 at 23:59 0 comments

    To make the motion controller automatic, it has to detect the mechanical limits of each arm of the gates. In my configuration, an arm is fully opened when the gate is in contact with the box containing a motor. The same arm is fully closed when the gate is in contact with a small piece of metal cast in concrete.

    The sensing process uses a current shunt: it is a small value resitor (a few tens of ohm) that has its voltage proportional to the current that flows through it. A DC motor has approximately its torque proportional to the current that flows through it. By detecting that the current overshoots, we can determine that the torque increases and, if it increases enough, should stop.

    One nice thing with H-brige is that you can reverse current in a motor to make it turn the opposit way, but another nice thing is that current direction outside the bridge is the same whatever the motor direction is. So we have the same current sign value in a motor direction or the other. This keeps us to sense the current in both ways, which is always painful. No need to have bipolar amplifier and bipolar power supplies. Great, I want to keep it simple.

  • Speed-up then slow-down

    Manu08/18/2014 at 23:48 0 comments

    To make a DC motor move, it has to be connected to a DC power supply. Its speed is somewhat proportional to the voltage value. The more the voltage value is (until its nominal voltage), the more the value of the speed of the motor is (until its nominal velocity). As a DC motor is pretty much a low-pass filter (as many of physics systems, by the way), you can switch its DC power supply fast enough to use it as an integrator of the voltage. To do this, you can setup a MOSFET between the motor and it DC power supply. By using a PWM output of a microcontroller (my Arduino board, in this case) connected to the gate of the transisitor, you can make as if the motor sees the mean value of the DC voltage depending of the duty cycle of the PWM output (from 0 to 100%, i.e. from 0V to it nominal voltage).

    If you do this on the dc-voltage of the H-bridge, you can control the speed and the direction of the motor.

    To speed the motor up, you increase the PWM duty cycle / To slow it down, you have to decrease the duty cycle.

    To prevent vibration in the gate, we can use a linear acceleration, or better a S-curve (no discontinuity in the velocity) to make the motor start smoothly.

View all 12 project logs

Enjoy this project?

Share

Discussions

Ian Dunn wrote 02/06/2022 at 04:41 point

very cool! It's funny that I just stumbled on your project the day after I posted my gate opener control board project. I ran into the same delima with a priority black box control board that died on me, so I invented my own. https://hackaday.io/project/183888-replacement-mighty-mule-swing-gate-control-board

  Are you sure? yes | no

Manu wrote 03/04/2022 at 21:26 point

great project!

  Are you sure? yes | no

inayath wrote 11/05/2017 at 05:29 point

Could you please provide me circuit diagram. I am student and my mail id is inayath77@rocketmail.com

  Are you sure? yes | no

damian.osullivan wrote 06/07/2016 at 15:38 point

Hi there - Was looking to build my own gate opener also. What is current state of this?

Thanks!

  Are you sure? yes | no

Manu wrote 06/07/2016 at 20:58 point

Hello. I wish I had more time to make this project better. I tested it with an ESP8266 and it seems promising. I didn't test some ideas I have to solve the motors current measurements problems.

  Are you sure? yes | no

satek.p wrote 09/13/2015 at 03:33 point

Hi  Manu

This is Interesting project I had same problem with my gate opener  board !

what about using hall effect current sensing chip instead of resister voltage drop sensor ?

can we include mechanical limit switch at either ends swing range and use one input on arduino  to detect this  and switch of the motors ?

  Are you sure? yes | no

Manu wrote 09/14/2015 at 06:24 point

Hello, we could definitely give a try to hall effect sensors. The other option is a high side shunt or a bidirectionnal current shunt monitor.

Limit switch are a good option to detect the end of movement. But, for a security view of the system, it is almost mandatory to check if a current surge happens during the oening of the gates (child, animal, car, ...) to stop the motors.

I haven't mechanical switches on my gate opener, so I will stick to current detection to switch the motors, but there are some spare pins on the Arduino board to implement this feature. In this case, I would use the interrupt pins INT0 INT1 for the limit switches (and some debouncing).

  Are you sure? yes | no

hortam97 wrote 09/09/2015 at 04:57 point

Dear Manu,

Your "Open Opener" program is awesome! Thank you for this!

I have made this, works fine, but I have a question about the shunt resistor, and about this resistors wiring... 

My Linear Actuartors consumed 1.30A with no load. With load: 2Amp

I'm a Newbe with Arduino..... And with electronics....

How much value are you suggesting of the resistors?  Can you help me with a practical hand made schematic, about the resistors wiring to the Arduino?

Sorry for my poor English!

Best regards,

Tamás from Hungary

  Are you sure? yes | no

Manu wrote 09/09/2015 at 06:22 point

Hello Tamas,

The current sensing on my project is not so great, so I won't advice you to do the same current sensing circuit that I used. It barely works for my needs and I probably won't work for another system.

However, you have to match the resistor value to your voltage supply and your Arduino analog input (5V max). Let's say your power supply is 24V, if your actuator draw 2A and your shunt resistor is 0.1ohm, your will have 0.2V across it which doesn't impact the 24V power supply. You should use a 10x amplifier to have 2V on the arduino analog input.

This could be done with a current shunt monitor (CSM) like the INA21x serie IC (or INA219 if you want a digital output).

Manu

  Are you sure? yes | no

hortam97 wrote 09/18/2015 at 20:54 point

Thank You!

This vesion goes to my friend gate, whitout current sensing.....

Now I use a well selected fast response 5x20mm fuse to the gate.

My actuators have inbuild limit switches.

Regards,

Tamás

  Are you sure? yes | no

hortam97 wrote 09/18/2015 at 20:54 point

Thank You!

This vesion goes to my friend gate, whitout current sensing.....

Now I use a well selected fast response 5x20mm fuse to the gate.

My actuators have inbuild limit switches.

Regards,

Tamás

  Are you sure? yes | no

Manu wrote 10/09/2014 at 19:54 point
I received yesterday a t-shirt for my participation for the hackaday prize. Thank you Hackaday!

  Are you sure? yes | no

Manu wrote 08/20/2014 at 08:40 point
The (very formal) video for the project description: http://youtu.be/xbExZyaC3zs
Sorry, I don't have a video showing the gate opener for now. I will post it on youtube as soon as possible.

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates