Go Down

Topic: Gate Opener (Read 5703 times) previous topic - next topic


Jul 26, 2016, 08:02 pm Last Edit: Jul 29, 2016, 12:13 am by d12f6m
This is my first stab at arduino programming. I am new to the whole programming thing.
I needed to replace the board on my Mighty Mule gate opener that fried and they wanted
350 bucks for a new one. I decided to try my hand at it. Any comments or criticism are  
welcome as long as it is constructive.



Author:Michael Wellner
Email: xxxxxxxxxxxx@gmail.com
Date: 7/18/2016
Description: This is a sketch to openGate and shut my driveway gate.
This is my first attempt at arduino programming so take that into
consideration before giving me any grief.

Next phase for this code will be using some electronics current sensor for
detecting the load of the motors so it will know when to cut off the power of the
gate instead of using the delay as the timing to openGate or close the gate.

int remoteState = 2;
int pwm = 9;
int openNow = 6;
int closeNow = 5;
int switch1 = 3;
int switch2 = 4;
int ledPin = 13;
int remotePress = LOW;       // Getting the reading from the remote controller
int switch_1 = LOW;       // Getting the reading from the gate openGate switch
int switch_2 = LOW;       // Getting the reading from the gate closeGate switch
int bothOpen = 1;           // setting state of bothOpen to "1"

void setup() {
pinMode(remoteState, INPUT_PULLUP);  //set up I/O
pinMode(switch1, INPUT);     // openGate limit switch
pinMode(switch2, INPUT);   // closeGate limit switch
pinMode(openNow, OUTPUT);          // send openGate command to H-bridge
pinMode(closeNow, OUTPUT);        // send closeGate command to H-bridge
pinMode(pwm, OUTPUT);           // send speed command to H-bridge
analogWrite(pwm, 0);            //make sure H-Bridge is off
pinMode(ledPin, OUTPUT);        //setup our status LED

 if(remotePress == LOW)  {
   analogWrite(pwm, 0);      // Stops motor
   Serial.println("STOPPED the MOTOR no signal recieved");

void loop() {

while(remotePress == LOW) {
 remotePress = digitalRead(remoteState);
 Serial.println("remotePress");            // for debugging purposes
 Serial.println(remotePress);              // for debugging purposes
       Serial.println("remotePress");      // gets readings from the switches and prints them for
       Serial.println(remotePress);        // for me to see what values they are sending.
 switch_1 = digitalRead(switch1);          // for debugging purposes    
 switch_2 = digitalRead(switch2);  
 bothOpen = switch_1 + switch_2;  
      if(switch_2 == LOW)  {       //sends loop to "openGate" module
         openGate();    }
 else if(switch_1 == LOW)  {     //sends loop to "closeGate" module
         closeGate();  }
    else(bothOpen != 1); {    //sends loop to "problem" module to stop program
         problem();  }

void openGate()  {     // opens gate till the gate meets open limit switch
   Serial.println("gate is opening");    // for debugging purposes
   digitalWrite(ledPin, HIGH);
   digitalWrite(openNow, HIGH);
   analogWrite(pwm, 245);

 while (switch_1 == HIGH)  {
   switch_1 = digitalRead(switch1);
   Serial.println("switch_1");  // for debugging purposes
   Serial.println(switch_1);    // for debugging purposes

  digitalWrite(openNow, LOW);
   analogWrite(pwm, 0);
   digitalWrite(ledPin, LOW);
   remotePress = LOW;

void closeGate()  {      // opens gate till the gate meets close limit switch
 Serial.println("gate is closing");     // for debugging purposes
 digitalWrite(ledPin, HIGH);
 digitalWrite(closeNow, HIGH);
 analogWrite(pwm, 245);
 while (switch_2 == HIGH)  {
   switch_2 = digitalRead(switch2);
   Serial.println("switch_2");         // for debugging purposes
   Serial.println(switch_2);           // for debugging purposes
 digitalWrite(closeNow, LOW);
 analogWrite(pwm, 0);
 digitalWrite(ledPin, LOW);
  remotePress = LOW;

void problem()  {
   Serial.println("Code WTF....Something is wrong with the limit switches ?");     // for debugging purposes
    while(0 == 0){}       // stops program here because there is a problem machanically.


Try getting rid of the delay(). See the BlinkwithoutDelay example. You should alo use interrupts on the limit switches. Then you will have an immediate stop when one is hit. 
What remote/receiver are you using?
Do not PM me for help. I will delete immediately.

After Tuesday, even the calendar goes W T F


I got this off of ebay

4.5-7V 4 Channel 433Mhz Wireless Remote Control



Hi...did you get this working? I have a GTO 350 that the control board also died so I'm trying to build my own as well. I think it would be good to use the photo sensor to help control motor and detect position.


I need to do something like this, did you get it to work?


Your project seem to be experimental, it is good anyway. But in practical with heavy duty gate motor, can it work?


I have a similar issue and I plan to start with this code and get my driveway gate working.  I see there haven't been any replies from the OP, so I'll post here as I complete the solution. 

I'll be using relays, as I have a dual swing gate.  This will allow me to use an external power supply for my actuators (24v DC).

I've been through 4 control boards in 2 years and have no method to troubleshoot a suppliers boards or logic

Go Up