Ir remotes

do you think Its possible to use the ir remote numbers as a servo selector?? Then use up/down arrows to servo.write

ie button 1 = servo 1 than up/down arrows to servo.write

button 2 = servo 2 then also use up/down arrows to servo.write

Cheers
Thanks

arduinoinfluence:
do you think Its possible to use the ir remote numbers as a servo selector?? Then use up/down arrows to servo.write

ie button 1 = servo 1 than up/down arrows to servo.write

button 2 = servo 2 then also use up/down arrows to servo.write

Yes.
As long as you can receive IR codes correctly you can assign any function you like to a received IR code.

Yes. The buttons all produce different codes. You can read the codes and then decide what to do with them.

There will be many different ways to program things once you have decided EXACTLY what you mean e.g. does each press of UP increase the value in servo.write(value)? How much by? It's going to be really boring if you have to press it 180 times to get from one end of the movement to the other. Or do you mean to keep increasing the value while UP is pressed because that needs different coding.

Steve

Not increments I'd like up-0/down-180 but the part I'm having a problem with would be coding this number button servo selector I think I'll need an if statement but I'm its like I'd need a if statment inside an if statment.. i havent programed much since 11th grade and that was 13 years ago I need a little guidance on the coding

#include <IRremote.h>
#include <Servo.h>
int IRpin = 11; // ir sensor
IRrecv irrecv(IRpin);
decode_results results;
Servo servo1;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
servo1.attach(9); // servo1
int servoselect
}
void loop()
{
if (irrecv.decode(&results))
{
irrecv.resume();
}
if (results.value == 16718055) //number button 1
{
int servoselect = 1

if int servoslect = 1

if (results.value == 33441975) //up button
{
servo1.write(0);
delay(15);
}
if (results.value == 33446055) // down button
{
servo1.write(180);
delay(15);

Here is your code after using the autoformat tool of the IDE (ctrl-t ot Tools, Auto Format) to indent the code. You can see that you are missing curly brackets to define the if blocks and some semicolons to end some statements. Also you declare the servoselect variable in setup(). That variable goes out of scope when setup() ends. Then you declare a new servoselect variable twice more in loop().

#include <IRremote.h>
#include <Servo.h>
int IRpin = 11;  // ir sensor
IRrecv irrecv(IRpin);
decode_results results;
Servo servo1;

void setup()
{
   Serial.begin(9600);
   irrecv.enableIRIn(); // Start the receiver
   servo1.attach(9);  // servo1
   int servoselect
}
void loop()
{
   if (irrecv.decode(&results))
   {
      irrecv.resume();
   }
   if (results.value == 16718055)  //number button 1
   {
      int servoselect = 1

                        if int servoslect = 1

                                            if (results.value == 33441975)  //up button
         {
            servo1.write(0);
            delay(15);
         }
      if (results.value == 33446055)  // down button
      {
         servo1.write(180);
         delay(15);

Here is the code modified to make more sense (not tested)

#include <IRremote.h>
#include <Servo.h>
int IRpin = 11;  // ir sensor
IRrecv irrecv(IRpin);
decode_results results;
Servo servo1;
int servoselect; // make servoselect glaobal so that it is visible to all functions

void setup()
{
   Serial.begin(9600);
   irrecv.enableIRIn(); // Start the receiver
   servo1.attach(9);  // servo1
   //int servoselect  // serves no purpose
}
void loop()
{
   if (irrecv.decode(&results))
   {
      if (results.value == 16718055)  //number button 1
      {
         servoselect = 1;
      }
      else if (results.value == 33441975)  //up button
      {
         servo1.write(0);
         delay(15);
      }
      else if (results.value == 33446055)  // down button
      {
         servo1.write(180);
         delay(15);
      }
      irrecv.resume();
   }
}

:

Oh global yeah, thanks I'm going to plug away at it thanks for your help groundfungus

Here is an example of using an array of servos to do what (I think) that you want. Be sure to power the servos from an external supply capable of supplying the current required. A 4 AA alkaline cell battery pack is one such supply. insufficient power is the root of many servo problems.

The IR codes are set up for my remote. You will probably have to change them to suit. And note the pins to which the servo are connected. Code is tested on my Uno and 3 mini servos.

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

const byte RECV_PIN = 11;
Servo servo[3];  // Array of servos
IRrecv irrecv(RECV_PIN);
decode_results results;

const byte servoPins[] = {7, 8, 9};

byte servoselect = 0;


void setup()
{
   Serial.begin(115200);
   Serial.println("select servo number and position");
   irrecv.enableIRIn(); // Start the receiver
   for (byte n = 0; n < sizeof(servoPins); n++)
   {
      servo[n].write(90);
      servo[n].attach(servoPins[n]);
   }
}

void loop()
{
   static unsigned long timer = 0;
   unsigned long interval = 100;
   if (millis() - timer >= interval)
   {
      timer = millis();
      if (irrecv.decode(&results))
      {
         unsigned long thisresult = results.value;
         if (thisresult == 0xffffffff) // ignore repeat code
         {
            irrecv.resume();
            return;
         }
         Serial.println(thisresult, HEX);

         if (thisresult == 0x4eb3c837)
         {
            servoselect = 0;
         }
          if (thisresult == 0x4eb308f7)
         {
            servoselect = 1;
         }
          if (thisresult == 0x4eb38877)
         {
            servoselect = 2;
         }

          if (thisresult == 0x4eb322dd)
         {
            servo[servoselect].write(0);
         }
          if (thisresult == 0x4eb3b847)
         {
            servo[servoselect].write(180);
         }
         irrecv.resume();
      }
   }
}

I think you're right that's what I needed. I like the ignore repeat code that's very nice addition aswell. thanks again ill add this code into my notes :slight_smile: