Reading IR signal width and length

Hello there.

I have been reading this forum for a certain time, always finding answers to my questions... until now.

About IR, I have seen a lot of project using pretty complex signals, like IR remote, but this doesn't apply to my case:

I do have 6 objects (scalextric cars), whith each individual objects having its own ID (1 to 6), and each object may request one and only one action (request lane change).

These objects will pass in front of the IR receiver pretty quickly.

ID is provided through the IR emitter by the time between 2 pulse (called Length, I believe).
action requested is provided by the time the signal is actually up, so the time the pulse is high (called width, I believe).

I tried to read the signal using IRremote library and the code below, but I got an inconsistent reading: I never have the same result.

This leads me to believe that I need to write some code which can get length end width of the pulse, probably include some tolerance, and then take action.

here are a few datas I could get by using an oscilloscope connected at the emiter.

ID: 1 _ Pulse length: 186µs _ action requested Pulse width: 48µs
ID: 2 _ Pulse length: 236µs _ action requested Pulse width: 41µs
ID: 3 _ Pulse length: 283µs _ action requested Pulse width: 47µs
ID: 4 _ Pulse length: 330µs _ action requested Pulse width: 48µs
ID: 5 _ Pulse length: 374µs _ action requested Pulse width: 63µs
ID: 6 _ Pulse length: 426µs _ action requested Pulse width: 42µs

I am looking for recomandations about the way to collect pulse datas with an arduino, or any idea about a better way to achieve my goal: detecting ID and detecting if action is requested or not.

Oh, and I forgot to mention that I am using AX-1838HS which was in an elegoo kit.

/*
  IR Receiver Demonstration 1
  IR-Rcv-Demo1.ino
  Demonstrates IR codes with IR Receiver
  Displays results on Serial Monitor

  DroneBot Workshop 2017
  http://dronebotworkshop.com
*/

// Include IR Remote Library by Ken Shirriff
#include <IRremote.h>

// Define sensor pin
const int RECV_PIN = 4;

// Define IR Receiver and Results Objects
IRrecv irrecv(RECV_PIN);
decode_results results;


void setup() {
  // Serial Monitor @ 9600 baud
  Serial.begin(9600);
  // Enable the IR Receiver
  irrecv.enableIRIn();
}

void loop() {
  if (irrecv.decode(&results)) {
    // Print Code in HEX
    Serial.println(results.value, HEX);
    irrecv.resume();
  }
}
1 Like

I am only a beginner at this but wouldn't it be easier to use two receivers, more expensive but.., one just before as per your set up and one just after the change over.
That would take care of your problem as pulse width etc as not needed the second detector can return the crossover back to normal and of course if you set a max time from first detection to second using it detect desloting.
Just a thought from a newbbee.

How do you want to prevent these objects from sending at the same time?

Easy: there can be only one object physically in front of the receiver.

we are talking about objects that are around 13cmx7cm, IR LED in the center, and distance between emitter and receiver will be as close as 8mm when object in position.

Not sure about what you mean by "change over"?

I am not trying to detect desloting.

there are 3 precise position where I need to know what car is there, and if it is actually requesting an action.

How does an object know when to send?
If it sends always, how many pulses can be transmitted while passing the receiver?

The OP may consider using the ESP32's API

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/rmt.html

The RMT hardware defines data in its own pattern – the RMT symbol . Each symbol consists of two pairs of two values. The first value in a pair describes the signal duration in RMT ticks and is 15 bits long. The second provides the signal level (high or low) and is contained in a single bit, as shown below:

The OP may also consider using the Pulse Counter (PCNT) - ESP32 - — ESP-IDF Programming Guide latest documentation but I think the RMT will work.

The diagram didn't come through...
image
I guess the text refers to it, not yourself...

It is always emiting.

I expect 20 to 40 pulses to be visible by the receiver

I have never used ESP32 before, so I feel more comfortable with a mega or uno, but I will have a look.

anyway, I don't get why you recommend ESP32? is there something a Nano can not do?

I did not put any diagram, I just wrote the values I could get via the oscilloscope.

What is the length and width of a pulse? I always considered them one dimensional. At least, the digital ones. Did you read the Arduino documentation about the pulseIn() function?

I was using the term "lenght" to describe the duration between 2 pulses, which, in my situation, is basically the ID. I probably should have used "period".

No, I haven't seen, the pulseIn() function, seems to be what I need to read the width. But not sure I can use it for the period.

I'll anyway try this right now to check if I can have a static read, and if yes a dynamic read

Thanks for pointing this out.

You're still confusing me. What is the difference between the width and the period? If you are talking about time between pulses, you don't have a pulse, you have a waveform.

Sorry about that.

téléchargement

I believe this image will help?

Right, that image shows a pulse waveform. Your proposal sounds reasonable, however the protocol as you have explained it, is not very resistant to transmission errors. You could do a lot better with more complex encoding.

Also there are some aspects that you haven't touched on that will crop up when you actually implement it. For example, all the cars are transmitting? What happens when the receiver sees signals from multiple cars?

Yep, But I have to deal with the signal, I cannot modify it.

Why is that? I had the impression you were the designer... if not, what haven't you told us?

Actually, some crucial specifications are missing. I asked you for numbers on the pulse width and duration, still waiting.

You said the targets could not conflict because they are only in the detection zone for a short time. Does that not place restrictions on the pulse train, considering that the cars are in motion? For example, at least one full pulse train period must be contained in the detection interval, and there must be some allowance for error, such as averaging multiple pulses (just an example).

Signal is coming from scalextric cars. As written in the first message...

all cars transmitting at once, as written a few message upper.

receiver can phisically receive signal from only one car at a time, as written upper as well.

what kind of secret do you believe I am hiding???

Please read the forum guidelines on how to post a question. It is not up to us to sit and Google Scalextric or other non-obvious aspects of your project. You are supposed to gather and present the information in a form that is complete and accurate so that people can concentrate on solutions.