IR Remote Momentary Control of Linear Actuator

Hello Everyone, I have searched quite a bit and I am finding so many answers I am having difficulty implementing this feature into my code.

What I would like to achieve is momentary control of my linear actuators using the IR remote.

Basically similar to how a volume up/down button would function, I would like the command for up/down of the actuators to continue with the button press until the button is let go.

(Linear actuators move when holding down the key, and stop when key is depressed.)

Is someone able to think of a clever way of implementing this without changing all my code? Your help is greatly appreciated.

#include "IRremote.h"
#include "IR.h"

IRrecv irrecv(RECEIVER);     // create instance of 'irrecv'
decode_results results;      // create instance of 'decode_results'
bool ledState; //track the on/off state of the onboard LED
const int forwards2 = 9; //assign relay INx pin to arduino pin
const int backwards2 = 8; //assign relay INx pin to arduino pin
const int forwards = 7; //assign relay INx pin to arduino pin
const int backwards = 6; //assign relay INx pin to arduino pin

void setup() {
  Serial.begin(9600);
  Serial.println("IR Receiver Button Decode");
  irrecv.enableIRIn();
  // Set up LED
  ledState = false;
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, ledState);
  pinMode(forwards, OUTPUT); //set relay as an output
  pinMode(backwards, OUTPUT); //set relay as an output
  pinMode(forwards2, OUTPUT); //set relay as an output
  pinMode(backwards2, OUTPUT); //set relay as an output
}

void loop()
{
  int tmpValue;
  if (irrecv.decode(&results)) // have we received an IR signal?
  {
    for (int i = 0; i < 23; i++)
    {
      if ((keyValue[i] == results.value) && (i<KEY_NUM))
      {
        Serial.println(keyBuf[i]);
        tmpValue = results.value;

        // Respond to the Power Button
        if (keyValue[i] == KEY_POWER) {
          ledState = !ledState;
          digitalWrite(LED_BUILTIN, ledState);
        }
        
        if (keyValue[i] == KEY_1) {
          digitalWrite(forwards, LOW);
          digitalWrite(backwards, HIGH);//Activate the relay one direction, they must be different to move the motor
          delay(1000); // wait 1 second
        }

        if (keyValue[i] == KEY_4) {
          digitalWrite(forwards, HIGH);
          digitalWrite(backwards, HIGH);//Deactivate both relays to brake the motor
          delay(1000);// wait 1 second
        }

       if (keyValue[i] == KEY_7) {
          digitalWrite(forwards, HIGH);
          digitalWrite(backwards, LOW);//Activate the relay the other direction, they must be different to move the motor
          delay(1000);// wait 1 second
          
        }

        if (keyValue[i] == KEY_3) {
          digitalWrite(forwards2, LOW);
          digitalWrite(backwards2, HIGH);//Activate the relay one direction, they must be different to move the motor
          delay(1000); // wait 1 second
        }

        if (keyValue[i] == KEY_6) {
          digitalWrite(forwards2, HIGH);
          digitalWrite(backwards2, HIGH);//Deactivate both relays to brake the motor
          delay(1000);// wait 1 second
        }

       if (keyValue[i] == KEY_9) {
          digitalWrite(forwards2, HIGH);
          digitalWrite(backwards2, LOW);//Activate the relay the other direction, they must be different to move the motor
          delay(1000);// wait 1 second
        }

        if (keyValue[i] == KEY_2) {
          digitalWrite(forwards, LOW);
          digitalWrite(forwards2, LOW);
          digitalWrite(backwards, HIGH);//Activate the relay one direction, they must be different to move the motor
          digitalWrite(backwards2, HIGH);//Activate the relay one direction, they must be different to move the motor
          delay(1000); // wait 1 second
        }

        if (keyValue[i] == KEY_5) {
          digitalWrite(forwards, HIGH);
          digitalWrite(forwards2, HIGH);
          digitalWrite(backwards, HIGH);//Deactivate both relays to brake the motor
          digitalWrite(backwards2, HIGH);//Deactivate both relays to brake the motor
          delay(1000);// wait 1 second
        }

       if (keyValue[i] == KEY_8) {
          digitalWrite(forwards, HIGH);
          digitalWrite(forwards2, HIGH);
          digitalWrite(backwards, LOW);//Activate the relay the other direction, they must be different to move the motor
          digitalWrite(backwards2, LOW);//Activate the relay the other direction, they must be different to move the motor
          delay(1000);// wait 1 second
        }
      
      }
      
      else if(REPEAT==i)
      {
        results.value = tmpValue;
      }
    }
    irrecv.resume(); // receive the next value
  }
}

Getting this far, what stops You from doing it Yourself?
Have You tried to play with just a controller and a remote?

As long as the IR remote push button is pressed, a repeat code is sent.

The first receive message sets the operation, the repeat code message does just that.

delay ( ) is hardly every recommended to use in your sketches.

I was hoping someone knew a command that might implement this in an elegant way. I am tapping out. Tried a number of methods and they aren’t giving desired result.

What is "a command"?
Don't think there are any easy solutions.
Being thrown into new, large systems during many years, before Internet and helpers, inventions was the only way.
Use serial monitor and strategic Serial.println in the code that show things inside the code, data received......

FYI a simple “I don’t know” would have sufficed. Thank you, you may move on.

I say the same.

What part of your "move on" post did you not understand?

What part of your "move on" post did you not understand?

Stop the childish bickering.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.