How can this be done, ir send & receive at same time?

First of all, so sorry if this is in the wrong place, I just joined and have tried for several days to complete a little project, but to no avail ;-(..

I have Arduino UNO, IDE- 1.6.7, an IR receive led, and an IR send led, also a servo and a standard NEC protocol Arduino kit remote.

Many hours of searching gave me a sketch that works with the ir receive and moves the servo either left or right while holding the button down, also stops when released.
Using "irlib"

I have another sketch which uses "Nikonirlib", which when uploaded sends a signal to my Nikon camera every 1 second.

I have tried and tried to put these two sketches together and it compiles with no errors but the ir send led does nothing.

My end result would be to have the IR send to the nikon only when either of the remote buttons are being held down.

I have attached both codes, these are not mine and I give credit to the initial writers of these sketches.

The servo.ino has my attempt :

#include #include #include

// You will have to set these values depending on the protocol
// and remote codes that you are using. These are For the Adafruit
// Mini Remote
#define MY_PROTOCOL NEC
#define RIGHT_ARROW 0x538DC23D //Move several clockwise
#define LEFT_ARROW 0x538DF807 //Move servo counterclockwise
#define SELECT_BUTTON 0xfd906f //Center the servo
#define UP_ARROW 0xfda05f //Increased number of degrees servo moves
#define DOWN_ARROW 0xfdb04f //Decrease number of degrees servo moves
#define BUTTON_0 0xfd30cf //Pushing buttons 0-9 moves to fixed positions
#define BUTTON_1 0xfd08f7 // each 20 degrees greater
#define BUTTON_2 0xfd8877
#define BUTTON_3 0xfd48b7
#define BUTTON_4 0xfd28d7
#define BUTTON_5 0xfda857
#define BUTTON_6 0xfd6897
#define BUTTON_7 0xfd18e7
#define BUTTON_8 0xfd9867
#define BUTTON_9 0xfd58a7

IRrecv My_Receiver(11);//Receive on pin 11
IRdecode My_Decoder;
Servo My_Servo; // create servo object to control a servo
int pos; // variable to store the servo position
int Speed; // Number of degrees to move each time a left/right button is pressed
long Previous; // Stores previous code to handle NEC repeat codes
int CameraIrPin = 13;
void setup()
{
pinMode(CameraIrPin, OUTPUT);
My_Servo.attach(9); // attaches the servo on pin 9 to the servo object
pos = 90; // start at midpoint 90 degrees
Speed = 3; // servo moves 3 degrees each time left/right is pushed
My_Servo.write(pos); // Set initial position
My_Receiver.enableIRIn(); // Start the receiver
}

void loop()
{
if (My_Receiver.GetResults(&My_Decoder)) {
My_Decoder.decode();
if(My_Decoder.decode_type==MY_PROTOCOL) {
if(My_Decoder.value==0xFFFFFFFF)
My_Decoder.value=Previous;
switch(My_Decoder.value) {
case LEFT_ARROW: pos=min(180,pos+Speed); break;
case RIGHT_ARROW: pos=max(0,pos-Speed); break;
case SELECT_BUTTON: pos=90; break;
case UP_ARROW: Speed=min(10, Speed+1); break;
case DOWN_ARROW: Speed=max(1, Speed-1); break;
case BUTTON_0: pos=020; break;
case BUTTON_1: pos=1
20; break;
case BUTTON_2: pos=220; break;
case BUTTON_3: pos=3
20; break;
case BUTTON_4: pos=420; break;
case BUTTON_5: pos=5
20; break;
case BUTTON_6: pos=620; break;
case BUTTON_7: pos=7
20; break;
case BUTTON_8: pos=820; break;
case BUTTON_9: pos=9
20; break;
cameraSnap(CameraIrPin);
delay(1000);
}
My_Servo.write(pos); // tell servo to go to position in variable 'pos'
Previous=My_Decoder.value;
}
My_Receiver.resume();
}
}

This_moves_servo.ino (2.83 KB)

This_takes_a_photo.ino (1.01 KB)

I have tried and tried to put these two sketches together and it compiles with no errors but the ir send led does nothing.

Can you post this attempt? I don't see how we can fix your problem if we can't see it.

I have pasted my effort into the main window, hope to have help soon .
Thanks.

You realize, you cannot have two IR transmit signals in the same room at the exactly the same time. They will conflict and nothing will be received.

Nope honestly I have no idea, could the Arduino take a single signal from the remote and then send signal to the camera,then delay or pause,then remote sends again,and then send from arduino to cam etc..while the servo moves a few degrees,then repeat the process?, i would not know how to do such a sketch but it was a thought.

//Nope honestly I have no idea, could the Arduino take a single signal from the remote and then send signal to the camera,
//then delay or pause,then remote sends again,and then send from arduino to cam etc..while the servo moves a few degrees,
//then repeat the process?, i would not know how to do
//such a sketch but it was a thought.

Does this outline follows your verbal description / project specification ?
Basically - are the tasks in correct functional sequence?
Is there another task and where in the sequence?

// initialize
// start process loop
// remote sends
// receive signal
// send to camera
// move servo
// pause
// loop back to remote send

yes, exactly! as I would like to have the servo move only 2 degrees when the button is pressed, during the movement,the send ir could send,after which I press the button again and the servo moves again..

anthonyjames678:
yes, exactly! as I would like to have the servo move only 2 degrees when the button is pressed, during the movement,the send ir could send,after which I press the button again and the servo moves again..

anthonyjames678:
yes, exactly! as I would like to have the servo move only 2 degrees when the button is pressed, during the movement,the send ir could send,after which I press the button again and the servo moves again..

Next - find an example / sample code ( IDE examples , Google etc ) which approximates some of your tasks.
Or just use examples basic bareminimum as convenient "template", I did.
Cut and paste your task into "BareMinimum " - in some reasonable order of execution.
Than build an empty function for each of your task.

Your code should look like this:

//Nope honestly I have no idea, could the Arduino take a single signal from the remote and then send signal to the camera,
//then delay or pause,then remote sends again,and then send from arduino to cam etc..while the servo moves a few degrees,
//then repeat the process?, i would not know how to do
//such a sketch but it was a thought.


//Does this outline follows your verbal description / project specification ?
//Basically - are the tasks in correct functional sequence?
//Is there another task and where in the sequence?

// initialize
// start process loop
// remote sends
// receive signal
// send to camera
// move servo
// pause
// loop back to remote send



// initialize



void setup() {
  // put your setup code here, to run once:
  // initialize Serial 
  Serial.begin(115200);
  // identify current *.ino file 
  Serial.println(__FILE__);   
}

void loop() {
  // put your main code here, to run repeatedly:
  // start process loop
  // remote sends
  SendIR(); 
  // receive signal
  ReceiveIR(); 
  // send to camera
  // move servo
  // pause
  // loop back to remote send
}
/* SendIR
 *  sends IR signal 
 *  returns 0 on success 
 */
int SendIR(void)
{
  int iState = 0;
  Serial.println(__func__);

  return iState;   // function executed correctly  
}
/* ReceiveIR
 *  receive IR signal 
 *  returns 0 on success 
 */
int ReceiveIR(void)
{
  int iState = 0;
  Serial.println(__func__);

  return iState;   // function executed correctly  
}

It will compile and run.
Now add the rest of the tasks as functions and pick ONE you feel most comfortable with and work on it until it does what you want.
Than do next task / function.
Go overboard with comments and use Serial to trace your code.
Add delay to slow things down (Serial prints) - you are after WORKING functions, execution speed is not your priority.

After ALL functions work, start on overall logic / code flow to accomplish your main task(s) in correct sequence. Since you will be dealing with building blocks / functions this gets easier to move things around.

Than you can "tweak your code" , for example replace some repetitious code with functions, use arrays when appropriate etc.

Last advise - use plenty of comments , and do not erase code you do not need or have replaced. The IDE text will look messy , but you will have a "fall back" code ready if needed, will have paper trail of how things went from start etc.
And compiler DOES NOT care about code which is commented out!
And by all means - save your new code often , and / or as new version "BareMinimum_IR_1" !
Good luck.