Swing gates with multiple open command inputs

Good morning all,

I’m in the process of using a mega 2560 board to control dual swing gates. The gates will be opened/closed by two gear motors. The motors will be controlled by an H gate motor driver(60 amp continuous 100 amp peak dual channel). There will be 4 limit switches(one set for closed and one set for open). The gates will also have to be timed. One will open a few seconds ahead of the other on the open command and the same on close command. There will be multiple “triggers” that prompt the gates to open(loop detectors, remote transmitter and receiver with clicker button…etc.)

I came across the following post…

Looking for general guidance for coding. Would the aforementioned post be a good starting point? Is there another method that would suffice? Any help is much appreciated.

Begin by producing a complete description of the task(s). It should be a design document using diagrams and words, no code at all. It should be as modular and heirarchical as possible, and leave out no details of the system. In your particular case, timing is important so you should make timing diagrams, showing all triggers, events and dependencies.

Then code.

What is your C/C++ skill level?

You need to be aware that electrically operated gates can be very dangerous, and can even cause DEATH.

https://www.hse.gov.uk/safetybulletins/electricgates.htm

My coding skill level is solely based on what I’ve learned by lurking here and multiple other sites. No formal training. I can and have made the system work on a small scale. But the problem there is that I used a lot of delays and it was… well….ugly. Bull in a china shop approach if you will.

I’ve read up on state machines, switch case, millis and pretty much any other article that can be read. At this point, I’m trying to pick an approach and run with it.

It sounds like you are looking for examples to emulate, not approaches. Also you can never learn much from lurking. You need to make some serious study and independent practice. Avoid "pop" sites and go directly to authoritative references, especially for C++. Most of the information that is pushed out on popular platforms such as [sue me] is pure, unadulterated garbage. Recycling it won't look good on you.

It's strange that you are asking for help with this, and provide no details at all about what you have already done.

Thank you John! This particular setup will have laser detection for this reason.

I have prototyped this on a bread board with rc motors with gear boxes. I used push buttons to simulate the limit switches and other “trigger” inputs.

Did you write any code? If so, why not just use it?

It's just hard to understand what you are asking for...
https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966

I have written code for it(bread board prototype). But as stated before it was full of delays, and if and while statements. I guess the question is… is it worth pursuing another more efficient method when I carry it over into the actual project? Or take the “if it ain’t broke, don’t fix it” approach.

Was just curious about other methods…

Yes, you should replace the "delays and whiles" with "millis and if's". It will give you more timing flexibility.

Thank you, aarg and John, for the engagement!

I have had a commercial version of your project for 15 years. The controller also checks for torque on the motors and stops that side of the gate when the torque reaches a limit. The gates sometime get blocked by snow.

Once you have an emergency stop of some type, how do you reset?

Good luck, it's a massive project!

Also, another idea I have been kicking around is using switch case for two separate loops. The idea being that wind load could affect the timing of the gates. As in wind could inhibit one gate and assist the other if conditions were right with wind direction. This could possibly cause the two moving gates to jam against one another on the close sequence of timing tolerances were too tight.

Would it be possible to get a digital read from an Anemometer to change the variable for switch case? The idea being that case 1: would be normal operation and timing parameters and case 2: would only allow one gate at a time to operate.

I’ve thought about this scenario. What I had in mind is monitoring dc amps to correlate the relationship with torque. If x amount of amps is seen for x amount of time, stop.

As far as the reset, I think it would be best to physically be at the gates to inspect the reason for the stop condition.

Do you happen to know the torque specs on the output shaft of your opener’s gearbox?

MY gate system is a "Mighty Mule". The mechanical parts are DC motors driving a nut on a lead screw. The controller watches the RPM of each motor and counts the revolutions to know when to stop the movement. I suspect they detect a rapid decrease in RPM as a gate blockage. It may also watch the current to each motor, but I am not sure of that.

Sounds like maybe it has an encoder on the motor…??

Yes.

Thank you Paul!