IR transmitter / receiver with MERJ25 Adapter (multiple IR sensors)


#1

Hi,

While the ME IR Receiver works well, it does take up a whole port.

I want to use a ME-RJ25 adapter to connect 2x IR LED receivers to double the amount of sensors.

I’m stuck how to modify the following project to work with the ME RJ-25 adapter…

#include <IRremote.h>

const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup(){
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true);
}

void loop(){
if (irrecv.decode(&results)){
Serial.println(results.value, HEX);
irrecv.resume();
}
}

regards
Michael


#2

Are you using some kind of multiplexer for the IR LED receivers or a third-party component? Would be helpful to see exactly what you have set up. :slight_smile:

Also, adding @tech_support in on these questions gets their attention. :smiley:


#3

SOLVED:

I used the IR library here -> https://github.com/Neco777/IRemoteModified/tree/master/IRremote

I connect a pair of these -> https://www.jaycar.com.au/arduino-compatible-infrared-receiver-module/p/XC4427

to connect to slot 1 and 2 of a ME RJ25 Adapter

and I use a pair of ME RJ25 Adapter, which gives me in total 4 IR sensors.

I address each sensor by the specific Arduino pin its connected to via the ME RJ25 adapter, I couldn’t work out how to use the MakeBlock library (if someone can show me how I would appreciate it)

This is the code I use to test 4x IR sensors. I didn’t need to know what the code was, just that a valid code was received. So my “battletank” can report when my front, rear, left and right sensor was hit.

#include "IRremote.h"
#include "CppList.h"

bool _initialized = false;

int rcv_count;
IRrecv **all_rcv;

void setup() {
  if (_initialized) return;
  
  Serial.begin(9600);
  
  rcv_count = 4;
  all_rcv = (IRrecv **)malloc(rcv_count*sizeof(int));
  all_rcv[0] = new IRrecv(11);
  all_rcv[1] = new IRrecv(12);
  all_rcv[2] = new IRrecv(9);
  all_rcv[3] = new IRrecv(10);
   for (int i=0; i<rcv_count; ++i){
	all_rcv[i]->enableIRIn();
  }
  
  _initialized = true;
}

void loop() {
  for (int i=0; i<rcv_count; ++i){
	decode_results results;
	if (all_rcv[i]->decode(&results)) {
	  switch (i) {
		case 0:
		  Serial.println("pin11 - port 1 - slot 1");
		  break;
		case 1:
		  Serial.println("pin12 - port 1 - slot 2");
		  break;
		case 2:
		  Serial.println("pin9 - port 2 - slot 1");
		  break;
		case 3:
		  Serial.println("pin10 - port 2 - slot 2");
		  break;
	  }      
	  all_rcv[i]->resume();
	}
  }
}

Here’s the original code doing and displaying the code that was received…

#include "IRremote.h"
#include "CppList.h"

bool _initialized = false;

int rcv_count;
IRrecv **all_rcv;

void setup() {
  if (_initialized) return;
  
  Serial.begin(9600);
  
  rcv_count = 4;
  all_rcv = (IRrecv **)malloc(rcv_count*sizeof(int));
  all_rcv[0] = new IRrecv(11);
  all_rcv[1] = new IRrecv(12);
  all_rcv[2] = new IRrecv(9);
  all_rcv[3] = new IRrecv(10);
   for (int i=0; i<rcv_count; ++i){
	all_rcv[i]->enableIRIn();
  }
  
  _initialized = true;
}

void loop() {
  for (int i=0; i<rcv_count; ++i){
	decode_results results;
	if (all_rcv[i]->decode(&results)) {
	  int btn = DecodeButton(results.value);
	  Serial.print("Rcv_");
	  Serial.print(i);
	  Serial.print(":");
	  Serial.println(btn);
	  all_rcv[i]->resume();
	}
  }
}

const int BTN_EMPTY = 0;
const int BTN_POWER = 99;
const int BTN_0 = 10;
const int BTN_1 = 1;
const int BTN_2 = 2;
const int BTN_3 = 3;
const int BTN_4 = 4;
const int BTN_5 = 5;
const int BTN_STOP = 6;
const int BTN_DOWN = 7;
const int BTN_UP = 8;
const int BTN_BACK = 9;
const int BTN_FWD = 11;
const int BTN_EQ = 12;
const int BTN_REPEAT = 100;
const int BTN_UNKNOWN = 101;
const int BTN_ERROR = 102;

int DecodeButton(int param){
	int rez = BTN_UNKNOWN;
	switch (param){
	case 0x0: {
						rez = BTN_ERROR;
						break;
			  }
	case 0x00FD00FF:
	case 0x00FF728D:
	case 0x20DF4EB1: {
						rez = BTN_POWER;
						break;
					 }
	case 0x00FD30CF:{
						rez = BTN_0;
						break;
					}
	case 0x00FD08F7:{
						rez = BTN_1;
						break;
					}
	case 0x00FD8877:{
						rez = BTN_2;
						break;
					}
	case 0x00FD48B7:{
						rez = BTN_3;
						break;
					}
	case 0x00FD28D7:{
						rez = BTN_4;
						break;
					}
	case 0x00FDA857:{
						rez = BTN_5;
						break;
					}
	case 0x00FD40BF:{
						rez = BTN_STOP;
						break;
					}
	case 0x00FD10EF:{
						rez = BTN_DOWN;
						break;
					}
	case 0x00FD50AF:{
						rez = BTN_UP;
						break;
					}
	case 0x00FD20DF:{
						rez = BTN_BACK;
						break;
					}
	case 0x00FD609F:{
						rez = BTN_FWD;
						break;
					}
	case 0x00FDB04F:{
						rez = BTN_EQ;
						break;
					}
	case 0xFFFFFFFF:{
						rez = BTN_REPEAT;
						break;
					}
	}
	return rez;
}

#4

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