IR controlled relay with timer

Hello again,

I’m trying to close a relay for 2 seconds for every ir signal received. I found simple code on Ir examples library and it seems to work other than timing out. As it stands now, the relay stays open or closed until the next button is pressed. All I want it to do is close for 2 seconds every time a button is pressed. This setup with allow me to kill the power to my servos and help conserve battery life.

Here is the code for the IR relay that is from the library

any input on how to make this code time out is appreciated!

void dump(decode_results *results) {
  int count = results->rawlen;
  if (results->decode_type == UNKNOWN) {
    Serial.println("Could not decode message");
  } 
  else {
    if (results->decode_type == NEC) {
      Serial.print("Decoded NEC: ");
    } 
    else if (results->decode_type == SONY) {
      Serial.print("Decoded SONY: ");
    } 
    else if (results->decode_type == RC5) {
      Serial.print("Decoded RC5: ");
    } 
    else if (results->decode_type == RC6) {
      Serial.print("Decoded RC6: ");
    }
    Serial.print(results->value, HEX);
    Serial.print(" (");
    Serial.print(results->bits, DEC);
    Serial.println(" bits)");
  }
  Serial.print("Raw (");
  Serial.print(count, DEC);
  Serial.print("): ");

  for (int i = 0; i < count; i++) {
    if ((i % 2) == 1) {
      Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
    } 
    else {
      Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
    }
    Serial.print(" ");
  }
  Serial.println("");
}

void setup()
{
  pinMode(RELAY_PIN, OUTPUT);
  pinMode(13, OUTPUT);
    Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

int on = 0;
unsigned long last = millis();

void loop() {
  if (irrecv.decode(&results)) {
    // If it's been at least 1/4 second since the last
    // IR received, toggle the relay
    if (millis() - last > 250) {
      on = !on;
      digitalWrite(RELAY_PIN, on ? HIGH : LOW);
      digitalWrite(13, on ? HIGH : LOW);
      dump(&results);
    }
    last = millis();      
    irrecv.resume(); // Receive the next value
  }
if (irrecv.decode(&results)) {

This if statement fires only when a code is received.

    // If it's been at least 1/4 second since the last
    // IR received, toggle the relay
    if (millis() - last > 250) {

Since this if statement is nested within the above if statement, it also only fires when a code is received.

Turning the relay off shouldn't be dependent on whether or not a IR code was received; it should only depend on the time it was turned on:

if (someConditionToTurnTheRelayOn)
{
   // turn relay on
   relayTurnOnTime = millis();
}

if (millis() - relayTurnOnTime >= someTimeInterval)
{
   // turn relay off
}

I have been working on this with no luck. The code for my 6x servo works fine but I can’t seem to get the relay code worked in. All I want to do is close a relay for 2 seconds whenever the IR sees a any code. The relay is going to be on pin 8 in case anyone wants to help me.

Here is the servo code I am using that I would like to add the relay code too.

/// controls SIX servos via IR remote at set positions returning back to 0 when OFF or any other servo is called

#include <Servo.h>
#include <IRremote.h>



unsigned long Value1 = 0xC0E8; // 21 channel IR remote 
unsigned long Value2 = 0xFD80DF; // not in use
unsigned long Value3 = 0xFD40BF; // not in use
unsigned long Value4 = 0xC038;
unsigned long Value5 = 0xC05E;
unsigned long Value6 = 0xC020;
unsigned long Value7 = 0xC0C0;
unsigned long Value8 = 0xC0A1; 
unsigned long Value9 = 0xC091;
unsigned long Value10 = 0xC084;
unsigned long Value11 = 0xC044;
unsigned long Value12 = 0xC0C4;
unsigned long Value13 = 0xC024;
unsigned long Value14 = 0xC0A4;
unsigned long Value15 = 0xC064; 
unsigned long Value16 = 0xC0E4;
unsigned long Value17 = 0xC014;
unsigned long Value18 = 0xC094;
unsigned long Value19 = 0xC0EE;
unsigned long Value20 = 0xC004;
unsigned long Value21 = 0xC0C8;

int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
Servo servo6;

// the setup routine runs once when you press reset:
void setup() {              

  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  

  servo1.write(90);
  servo2.write(90);
  servo3.write(90);
  servo4.write(90);
  servo5.write(90);
  servo6.write(90);
  
  servo1.attach(2); 
  servo2.attach(3); 
  servo3.attach(4); 
  servo4.attach(5);
  servo5.attach(6); 
  servo6.attach(7);
}

// the loop routine runs over and over again forever:
void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);

    if(results.value == Value1) {
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
   }
   else if  (results.value == Value4){ // servo 1-180
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo1.write(0);
    }
    else if  (results.value == Value5){ // servo 1-110
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo1.write(30);
    }
    else if  (results.value == Value6){ // servo 1-90
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo1.write(60);
    } 
    else if  (results.value == Value7){ // servo 2-180
      servo1.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo2.write(0);
    }
    else if  (results.value == Value8){ // servo 2-110
      servo1.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo2.write(30);
    }
    else if  (results.value == Value9){ // servo 2-90
      servo1.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo2.write(60);
    } 
    else if  (results.value == Value10){ // servo 3-180
      servo1.write(90);
      servo2.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo3.write(0);
    }
    else if  (results.value == Value11){ // servo 3-110
      servo1.write(90);
      servo2.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo3.write(30);
    }
    else if  (results.value == Value12){ // servo 3-90
      servo1.write(90);
      servo2.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo3.write(60);
    }
    else if  (results.value == Value13){ // servo 4-180
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo5.write(90);
      servo6.write(90);
      servo4.write(0);
    }
    else if  (results.value == Value14){ // servo 4-110
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo5.write(90);
      servo6.write(90);
      servo4.write(30);
    }
    else if  (results.value == Value15){ // servo 4-90
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo5.write(90);
      servo6.write(90);
      servo4.write(60);
    }
    else if  (results.value == Value16){ // servo 5-180
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo6.write(90);
      servo5.write(0);
    }
    else if  (results.value == Value17){ // servo 5-110
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo6.write(90);
      servo5.write(30);
    }
    else if  (results.value == Value18){ // servo 5-90
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo6.write(90);
      servo5.write(60);
    }
    else if  (results.value == Value19){ // servo 6-180
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(0);
    }
    else if  (results.value == Value20){ // servo 6-110
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(30);
    }
    else if  (results.value == Value21){ // servo 6-90
      servo1.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo5.write(90);
      servo6.write(60);
    }
    irrecv.resume(); // Receive the next value
  }
}

There is nothing in that code about turning a relay on or off.

Arch, thanks for taking a look. I am aware of the missing relay code. I posted code I was working on and have since gave up on it. I was hoping to start fresh with the serve code that works and just simply add a relay command to it. I am in over my head with this thing as it is and just can't get the relay and servos to work right. I plan on learning more about programming soon but right now I just need a little help to finish this project.

All I want to do is turn relay pin8 on high for 2 seconds after any of the IR codes are received. This will cut power to the servo bus letting me save battery life.

It won't take much to do it; the example code I posted above is all the logic there is to it: when some condition occurs (ir code was received), turn the relay on and remark the time. Outside of any other conditions, check to see if two seconds has elapsed since you last turned the relay on. If it has, turn it off.

But it sounds like you've given up on learning how to do this, and just want someone to do it for you. If that's the case, then I'll resign from this thread and let somebody else help.

Arch, I don’t mean to sound like I want to give up. It bugs me I don’t know more about basic programming. I am a prototype engineer stuck on this project at the moment and people are waiting on me. I choose Arduino as the hardware for this setup since it can do everything needed. However, I have very little programming knowledge and even less time to learn at the moment. I plan to take some classes in the near future but until then I am a fish out of water.

I think I am close to the code needed but I still get messages saying

new_remote_6_servo_perfect:31: error: expected initializer before ‘-’ token
new_remote_6_servo_perfect.ino: In function ‘void loop()’:
new_remote_6_servo_perfect:72: error: lvalue required as left operand of assignment

this is the code that I feel is close to working. My servos all work perfect and all I want to do is close pin8 relay for 2 seconds when any button is pressed on the IR remote

#include <Servo.h>
#include <IRremote.h>



unsigned long Value1 = 0xC0E8; // 21 channel IR remote 
unsigned long Value2 = 0xFD80DF; // not in use
unsigned long Value3 = 0xFD40BF; // not in use
unsigned long Value4 = 0xC038;
unsigned long Value5 = 0xC05E;
unsigned long Value6 = 0xC020;
unsigned long Value7 = 0xC0C0;
unsigned long Value8 = 0xC0A1; 
unsigned long Value9 = 0xC091;
unsigned long Value10 = 0xC084;
unsigned long Value11 = 0xC044;
unsigned long Value12 = 0xC0C4;
unsigned long Value13 = 0xC024;
unsigned long Value14 = 0xC0A4;
unsigned long Value15 = 0xC064; 
unsigned long Value16 = 0xC0E4;
unsigned long Value17 = 0xC014;
unsigned long Value18 = 0xC094;
unsigned long Value19 = 0xC0EE;
unsigned long Value20 = 0xC004;
unsigned long Value21 = 0xC0C8;

int RECV_PIN = 11;
int RELAY-PIN = 8;
IRrecv irrecv(RECV_PIN);
decode_results results;

Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
Servo servo6;

// the setup routine runs once when you press reset:
void setup() {              

  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  
 
  

  servo1.write(90);
  servo2.write(90);
  servo3.write(90);
  servo4.write(90);
  servo5.write(90);
  servo6.write(90);
  
  servo1.attach(2); 
  servo2.attach(3); 
  servo3.attach(4); 
  servo4.attach(5);
  servo5.attach(6); 
  servo6.attach(7);
}

// the loop routine runs over and over again forever:
void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
{
   // turn relay on
   2000 = millis();
}

if (millis() - 2000 >= 0)
{
   // turn relay off
}

    if(results.value == Value1) {
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
   }
   else if  (results.value == Value4){ // servo 1-180
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo1.write(0);
    }
    else if  (results.value == Value5){ // servo 1-110
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo1.write(30);
    }
    else if  (results.value == Value6){ // servo 1-90
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo1.write(60);
    } 
    else if  (results.value == Value7){ // servo 2-180
      servo1.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo2.write(0);
    }
    else if  (results.value == Value8){ // servo 2-110
      servo1.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo2.write(30);
    }
    else if  (results.value == Value9){ // servo 2-90
      servo1.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo2.write(60);
    } 
    else if  (results.value == Value10){ // servo 3-180
      servo1.write(90);
      servo2.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo3.write(0);
    }
    else if  (results.value == Value11){ // servo 3-110
      servo1.write(90);
      servo2.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo3.write(30);
    }
    else if  (results.value == Value12){ // servo 3-90
      servo1.write(90);
      servo2.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo3.write(60);
    }
    else if  (results.value == Value13){ // servo 4-180
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo5.write(90);
      servo6.write(90);
      servo4.write(0);
    }
    else if  (results.value == Value14){ // servo 4-110
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo5.write(90);
      servo6.write(90);
      servo4.write(30);
    }
    else if  (results.value == Value15){ // servo 4-90
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo5.write(90);
      servo6.write(90);
      servo4.write(60);
    }
    else if  (results.value == Value16){ // servo 5-180
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo6.write(90);
      servo5.write(0);
    }
    else if  (results.value == Value17){ // servo 5-110
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo6.write(90);
      servo5.write(30);
    }
    else if  (results.value == Value18){ // servo 5-90
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo6.write(90);
      servo5.write(60);
    }
    else if  (results.value == Value19){ // servo 6-180
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(0);
    }
    else if  (results.value == Value20){ // servo 6-110
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(30);
    }
    else if  (results.value == Value21){ // servo 6-90
      servo1.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo5.write(90);
      servo6.write(60);
    }
    irrecv.resume(); // Receive the next value
  }
}
int RELAY-PIN = 8;

Variables can't have dashes in them. Either remove it or change it to something valid, like an underscore.

// turn relay on

Statements that start with // are comments. They don't do anything to change the behavior of the program. You actually have to put a statement there to turn it on. In this case, it will probably be a digitalWrite call.

   // turn relay off

Ditto

   2000 = millis();

You can't assign something to a constant. The left side of an assignment statement needs to be a variable. You'll notice in my example, I used a variable that I named relayTurnOnTime

{
   // turn relay on
   2000 = millis();
}

The curly braces here are useless. Curly braces are used to group statements into a logical block. Typically, this is for things like if statements, loops and functions.

if (millis() - 2000 >= 0)

Some simple algebra would makes this the same as:

if (millis >= 2000)

millis returns the number of milliseconds since the Arduino was last reset. So what you're saying is that you want this statement to occur when the Arduino has been running for longer than 2 seconds. In the code that I quoted, you'll notice two symbols: relayTurnOnTime - A variable to store the time at which the relay was turned on. someTimeInterval - A constant that says how long the relay should be turned on for.

It looks like someTimeInterval should be 2000, but your code has no variable to store the time at which the relay was turned on. That's probably related to the earlier mentioned issue of trying to assign a value to a constant.

if (irrecv.decode(&results)) 
{
  ...
  if (millis() - 2000 >= 0)
  {
   // turn relay off
  }

I reiterate:

Turning the relay off shouldn't be dependent on whether or not a IR code was received

Wow, I missed the dash part, thanks..

I kinda understand most of what you are saying but have an issue with

new_remote_6_servo_perfect.ino: In function 'void loop()': new_remote_6_servo_perfect:72: error: 'relayTurnOnTime' was not declared in this scope new_remote_6_servo_perfect:75: error: ISO C++ forbids comparison between pointer and integer

Not sure what I need to change "relayTurnOntime" into. Is this a time value?

kaz321:
Not sure what I need to change “relayTurnOntime” into. Is this a time value?

relayTurnOnTime needs to be declared first before it can be used:

unsigned long relayTurnOnTime; // declared unsigned long because it receives values from millis()

void setup()
{
  ...
}

void loop()
{
  ...
}

I think I am getting close and is kinda making a little sense now. I am getting this message

Also, Do you think the rely will turn on and get power to the servo bus before the servo pulse is sent? or will I need to have a small delay so the pulse is sent after the relay closes sending power to the servos?

new_remote_6_servo_perfect.ino: In function 'void loop()': new_remote_6_servo_perfect:75: error: ISO C++ forbids comparison between pointer and integer new_remote_6_servo_perfect:81: error: expected primary-expression before '}' token new_remote_6_servo_perfect:81: error: expected `;' before '}' token new_remote_6_servo_perfect.ino: At global scope: new_remote_6_servo_perfect:236: error: expected declaration before '}' token

   // turn relay on
    if(results.value == HEX) {
      unsigned long relayTurnOnTime; 
      
if (millis >= 2000)


if (millis() - 2000 >= 0)
   // turn relay off

    }

sorry it is highlighting

"if (millis >= 2000)"

Post all of your code.

#include <Servo.h>
#include <IRremote.h>



unsigned long Value1 = 0xC0E8; // 21 channel IR remote 
unsigned long Value2 = 0xFD80DF; // not in use
unsigned long Value3 = 0xFD40BF; // not in use
unsigned long Value4 = 0xC038;
unsigned long Value5 = 0xC05E;
unsigned long Value6 = 0xC020;
unsigned long Value7 = 0xC0C0;
unsigned long Value8 = 0xC0A1; 
unsigned long Value9 = 0xC091;
unsigned long Value10 = 0xC084;
unsigned long Value11 = 0xC044;
unsigned long Value12 = 0xC0C4;
unsigned long Value13 = 0xC024;
unsigned long Value14 = 0xC0A4;
unsigned long Value15 = 0xC064; 
unsigned long Value16 = 0xC0E4;
unsigned long Value17 = 0xC014;
unsigned long Value18 = 0xC094;
unsigned long Value19 = 0xC0EE;
unsigned long Value20 = 0xC004;
unsigned long Value21 = 0xC0C8;

int RECV_PIN = 11;
int RELAY_PIN = 8;
IRrecv irrecv(RECV_PIN);
decode_results results;

Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
Servo servo6;

// the setup routine runs once when you press reset:
void setup() {              

  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  
 
  

  servo1.write(90);
  servo2.write(90);
  servo3.write(90);
  servo4.write(90);
  servo5.write(90);
  servo6.write(90);
  
  servo1.attach(2); 
  servo2.attach(3); 
  servo3.attach(4); 
  servo4.attach(5);
  servo5.attach(6); 
  servo6.attach(7);
}

// the loop routine runs over and over again forever:
void loop() {
  if (irrecv.decode(&results)) 
    Serial.println(results.value, HEX);

   // turn relay on
    if(results.value == HEX) {
      unsigned long relayTurnOnTime; 
      
if (millis >= 2000)


if (millis() - 2000 >= 0)
   // turn relay off

    }
    if(results.value == Value1) {
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
   }
   else if  (results.value == Value4){ // servo 1-180
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo1.write(0);
    }
    else if  (results.value == Value5){ // servo 1-110
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo1.write(30);
    }
    else if  (results.value == Value6){ // servo 1-90
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo1.write(60);
    } 
    else if  (results.value == Value7){ // servo 2-180
      servo1.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo2.write(0);
    }
    else if  (results.value == Value8){ // servo 2-110
      servo1.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo2.write(30);
    }
    else if  (results.value == Value9){ // servo 2-90
      servo1.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo2.write(60);
    } 
    else if  (results.value == Value10){ // servo 3-180
      servo1.write(90);
      servo2.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo3.write(0);
    }
    else if  (results.value == Value11){ // servo 3-110
      servo1.write(90);
      servo2.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo3.write(30);
    }
    else if  (results.value == Value12){ // servo 3-90
      servo1.write(90);
      servo2.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo3.write(60);
    }
    else if  (results.value == Value13){ // servo 4-180
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo5.write(90);
      servo6.write(90);
      servo4.write(0);
    }
    else if  (results.value == Value14){ // servo 4-110
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo5.write(90);
      servo6.write(90);
      servo4.write(30);
    }
    else if  (results.value == Value15){ // servo 4-90
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo5.write(90);
      servo6.write(90);
      servo4.write(60);
    }
    else if  (results.value == Value16){ // servo 5-180
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo6.write(90);
      servo5.write(0);
    }
    else if  (results.value == Value17){ // servo 5-110
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo6.write(90);
      servo5.write(30);
    }
    else if  (results.value == Value18){ // servo 5-90
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo6.write(90);
      servo5.write(60);
    }
    else if  (results.value == Value19){ // servo 6-180
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(0);
    }
    else if  (results.value == Value20){ // servo 6-110
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(30);
    }
    else if  (results.value == Value21){ // servo 6-90
      servo1.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo5.write(90);
      servo6.write(60);
    }
    irrecv.resume(); // Receive the next value
  }
}
  if (irrecv.decode(&results))

What happened to the starting curly brace? For beginners, I always recommend including curly braces with any if statement. They should also be aligned correctly:

if (someCondition)
{
  // Any code that should run within the condition should go here
}
   // turn relay on

See previous post

   // turn relay off

See previous post

    if(results.value == HEX) {
      unsigned long relayTurnOnTime;

Look at the example code I posted. I put the declaration in the global scope, not nested within an if statement inside or the loop function.

if (millis >= 2000)


if (millis() - 2000 >= 0)

I get the feeling you are just taking stabs in the dark, and not trying to understand what these statements mean. What do you think these if statements do?

not stabbing at it. My lack of understanding the basics and langue is the root of my problems. I was able to teach myself Chinese simply by matching symbols to the point I can read hundreds of words now. This however is something that is stressing me out as I am up against a time frame for this to be completed. I'm sure when I can spend a few days going over the basics I will be able to excel as in other like environments in the past. Until then, I am pulling my hair out with no sign of hope. It seems very easy and I can read what Arch is saying but it makes no sense at all right now. I'm ready to put two boards together with two codes so I can save my job at this point. one board will work the servos and the other will close and open the relay.

Well, can't say I didn't try to teach it:

void loop() 
{
  static unsigned long lastRelayTime = 0;

  if (millis() - lastRelayTime >= 2000)
  {
    digitalWrite(RELAY_PIN, LOW); // turn relay off
  }

  if (irrecv.decode(&results)) 
  {
    Serial.println(results.value, HEX);

    relayTurnOnTime = millis();
    digitalWrite(RELAY_PIN, HIGH); // turn relay on
    lastRelayTime = millis();

    // Servo code goes here

    irrecv.resume(); // Receive the next value
  }
}

I am getting this message. I also put a "int RELAY_PIN = 8; in as well… is this right? or should this change?

“relayTurnOnTime” was not declared in this scope

_6_servo_4x_position.ino: In function 'void loop()':
_6_servo_4x_position:77: error: 'relayTurnOnTime' was not declared in this scope
_6_servo_4x_position:81: error: expected `;' before 'if'
_6_servo_4x_position:89: error: expected `}' before 'else'
_6_servo_4x_position.ino: At global scope:
_6_servo_4x_position:235: error: expected declaration before '}' token
/// controls SIX servos via IR remote at set positions returning back to 0 when OFF or any other servo is called

#include <Servo.h>
#include <IRremote.h>


unsigned long Value1 = 0xC0E8; // 21 channel IR remote 
unsigned long Value2 = 0xFD80DF; // not in use
unsigned long Value3 = 0xFD40BF; // not in use
unsigned long Value4 = 0xC038;
unsigned long Value5 = 0xC05E;
unsigned long Value6 = 0xC020;
unsigned long Value7 = 0xC0C0;
unsigned long Value8 = 0xC0A1; 
unsigned long Value9 = 0xC091;
unsigned long Value10 = 0xC084;
unsigned long Value11 = 0xC044;
unsigned long Value12 = 0xC0C4;
unsigned long Value13 = 0xC024;
unsigned long Value14 = 0xC0A4;
unsigned long Value15 = 0xC064; 
unsigned long Value16 = 0xC0E4;
unsigned long Value17 = 0xC014;
unsigned long Value18 = 0xC094;
unsigned long Value19 = 0xC0EE;
unsigned long Value20 = 0xC004;
unsigned long Value21 = 0xC0C8;

int RECV_PIN = 11;
int RELAY_PIN = 8;
IRrecv irrecv(RECV_PIN);
decode_results results;

Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
Servo servo6;

// the setup routine runs once when you press reset:
void setup() {              

  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  

  servo1.write(90);
  servo2.write(90);
  servo3.write(90);
  servo4.write(90);
  servo5.write(90);
  servo6.write(90);
  
  servo1.attach(2); 
  servo2.attach(3); 
  servo3.attach(4); 
  servo4.attach(5);
  servo5.attach(6); 
  servo6.attach(7);
}
void loop() 
{
  static unsigned long lastRelayTime = 0;

  if (millis() - lastRelayTime >= 2000)
  {
    digitalWrite(RELAY_PIN, LOW); // turn relay off
  }

  if (irrecv.decode(&results)) 
  {
    Serial.println(results.value, HEX);
    
    relayTurnOnTime = millis();
    digitalWrite(RELAY_PIN, HIGH); // turn relay on
    lastRelayTime = millis()
  
    if(results.value == Value1) {
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
   }
   else if  (results.value == Value4){ // servo 1-180
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo1.write(0);
    }
    else if  (results.value == Value5){ // servo 1-110
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo1.write(30);
    }
    else if  (results.value == Value6){ // servo 1-90
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo1.write(60);
    } 
    else if  (results.value == Value7){ // servo 2-180
      servo1.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo2.write(0);
    }
    else if  (results.value == Value8){ // servo 2-110
      servo1.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo2.write(30);
    }
    else if  (results.value == Value9){ // servo 2-90
      servo1.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo2.write(60);
    } 
    else if  (results.value == Value10){ // servo 3-180
      servo1.write(90);
      servo2.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo3.write(0);
    }
    else if  (results.value == Value11){ // servo 3-110
      servo1.write(90);
      servo2.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo3.write(30);
    }
    else if  (results.value == Value12){ // servo 3-90
      servo1.write(90);
      servo2.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo3.write(60);
    }
    else if  (results.value == Value13){ // servo 4-180
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo5.write(90);
      servo6.write(90);
      servo4.write(0);
    }
    else if  (results.value == Value14){ // servo 4-110
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo5.write(90);
      servo6.write(90);
      servo4.write(30);
    }
    else if  (results.value == Value15){ // servo 4-90
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo5.write(90);
      servo6.write(90);
      servo4.write(60);
    }
    else if  (results.value == Value16){ // servo 5-180
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo6.write(90);
      servo5.write(0);
    }
    else if  (results.value == Value17){ // servo 5-110
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo6.write(90);
      servo5.write(30);
    }
    else if  (results.value == Value18){ // servo 5-90
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo6.write(90);
      servo5.write(60);
    }
    else if  (results.value == Value19){ // servo 6-180
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(0);
    }
    else if  (results.value == Value20){ // servo 6-110
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(30);
    }
    else if  (results.value == Value21){ // servo 6-90
      servo1.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo5.write(90);
      servo6.write(60);
    }
    irrecv.resume(); // Receive the next value
  }
}

kaz321: I am getting this message.

Bug in my example code, remove that line.

kaz321: I also put a "int RELAY_PIN = 8; in as well.. is this right? or should this change?

It will work, but I would recommend adding const in front of it, as best practice:

const int RELAY_PIN = 8;

I am getting another message

expected `;’ before ‘else’

_6_servo_4x_position.ino: In function ‘void loop()’:
_6_servo_4x_position:78: error: expected ;' before 'else' _6_servo_4x_position:86: error: expected }’ before ‘else’
_6_servo_4x_position.ino: At global scope:
_6_servo_4x_position:232: error: expected declaration before ‘}’ token

/// controls SIX servos via IR remote at set positions returning back to 0 when OFF or any other servo is called

#include <Servo.h>
#include <IRremote.h>


unsigned long Value1 = 0xC0E8; // 21 channel IR remote 
unsigned long Value2 = 0xFD80DF; // not in use
unsigned long Value3 = 0xFD40BF; // not in use
unsigned long Value4 = 0xC038;
unsigned long Value5 = 0xC05E;
unsigned long Value6 = 0xC020;
unsigned long Value7 = 0xC0C0;
unsigned long Value8 = 0xC0A1; 
unsigned long Value9 = 0xC091;
unsigned long Value10 = 0xC084;
unsigned long Value11 = 0xC044;
unsigned long Value12 = 0xC0C4;
unsigned long Value13 = 0xC024;
unsigned long Value14 = 0xC0A4;
unsigned long Value15 = 0xC064; 
unsigned long Value16 = 0xC0E4;
unsigned long Value17 = 0xC014;
unsigned long Value18 = 0xC094;
unsigned long Value19 = 0xC0EE;
unsigned long Value20 = 0xC004;
unsigned long Value21 = 0xC0C8;

int RECV_PIN = 11;
const int RELAY_PIN = 8;
IRrecv irrecv(RECV_PIN);
decode_results results;

Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
Servo servo6;

// the setup routine runs once when you press reset:
void setup() {              

  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  

  servo1.write(90);
  servo2.write(90);
  servo3.write(90);
  servo4.write(90);
  servo5.write(90);
  servo6.write(90);
  
  servo1.attach(2); 
  servo2.attach(3); 
  servo3.attach(4); 
  servo4.attach(5);
  servo5.attach(6); 
  servo6.attach(7);
}
void loop() 
{
  static unsigned long lastRelayTime = 0;

  if (millis() - lastRelayTime >= 2000)
  {
    digitalWrite(RELAY_PIN, LOW); // turn relay off
  }

  if (irrecv.decode(&results)) 
{
    Serial.println(results.value, HEX);
    
    digitalWrite(RELAY_PIN, HIGH); // turn relay on
    lastRelayTime = millis()

   else if(results.value == Value1) {
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
   }
   else if  (results.value == Value4){ // servo 1-180
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo1.write(0);
    }
    else if  (results.value == Value5){ // servo 1-110
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo1.write(30);
    }
    else if  (results.value == Value6){ // servo 1-90
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo1.write(60);
    } 
    else if  (results.value == Value7){ // servo 2-180
      servo1.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo2.write(0);
    }
    else if  (results.value == Value8){ // servo 2-110
      servo1.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo2.write(30);
    }
    else if  (results.value == Value9){ // servo 2-90
      servo1.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo2.write(60);
    } 
    else if  (results.value == Value10){ // servo 3-180
      servo1.write(90);
      servo2.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo3.write(0);
    }
    else if  (results.value == Value11){ // servo 3-110
      servo1.write(90);
      servo2.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo3.write(30);
    }
    else if  (results.value == Value12){ // servo 3-90
      servo1.write(90);
      servo2.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(90);
      servo3.write(60);
    }
    else if  (results.value == Value13){ // servo 4-180
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo5.write(90);
      servo6.write(90);
      servo4.write(0);
    }
    else if  (results.value == Value14){ // servo 4-110
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo5.write(90);
      servo6.write(90);
      servo4.write(30);
    }
    else if  (results.value == Value15){ // servo 4-90
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo5.write(90);
      servo6.write(90);
      servo4.write(60);
    }
    else if  (results.value == Value16){ // servo 5-180
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo6.write(90);
      servo5.write(0);
    }
    else if  (results.value == Value17){ // servo 5-110
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo6.write(90);
      servo5.write(30);
    }
    else if  (results.value == Value18){ // servo 5-90
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo6.write(90);
      servo5.write(60);
    }
    else if  (results.value == Value19){ // servo 6-180
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(0);
    }
    else if  (results.value == Value20){ // servo 6-110
      servo1.write(90);
      servo2.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo6.write(30);
    }
    else if  (results.value == Value21){ // servo 6-90
      servo1.write(90);
      servo3.write(90);
      servo4.write(90);
      servo5.write(90);
      servo5.write(90);
      servo6.write(60);
    }
    irrecv.resume(); // Receive the next value
  }
}