How to use the IR commands?

hbl2013

Senior Member
I am trying to work with the IR commands and have not much luck. Nothing seems to work. Can anybody shed some light into it? Here is some code I have been using. To try the IR Input, I used a standard Sony remote as the transmitter, because the IR diode does not seem to work. (No pulses on the scope) There is no output from the Terminal program at all. If I add a DEBUG statement to the code, nothing happens, and the Debug window states that it is "Waiting". Waiting for what and how do I get it to RUN? The scope tells me that I am receiving pulses on A.O. when I use the remote. Using the PULSIN statement does not indicate anything either.
Anybody has any suggestions how to get this working? I am looking to use the IR system for a simple obstacle avoidance Robot.

Code:
'using the 28X2
'IR diode connected to C.0 directly with a 330 ohm in series to ground.
'IR detector with 3K9 ohm to VCC, connected to A.0
'VCC = 3X AA batteries = 4.5V Nominal
main:
irout C.0,1,1
irin A.0,b4            'check for IR input
pulsin A.0,0,w1    'anything there?
sertxd ("B4 = ",#b4," ,W1 = ",#w1)
sertxd (CR,LF)
pause 800
goto main
 
Last edited:

hbl2013

Senior Member
eclectic - The IR Module Circuit is as per sample on page 125. The signal pin is connected to Pin #2 of the 28X2 (A.0), with a 3K9 Pullup resistor to VCC. (4.5V)

The part number of the Module is unknown, but was sold as a replacement part for a 38kHz system. It shows a de-modulated pulse-train on the scope when any remote is used, including the Sony I have.
 

hippy

Ex-Staff (retired)
The following program works for me on a 28X2. This uses a timeout on the IRIN command so you can tell it is working and not hung -

Code:
#Picaxe 28X2
#Terminal 9600
#No_Data
#No_Table

Main:
  IrIn [2000,TimedOut], A.0, b0
  SerTxd( "Received ", #b0, CR, LF )
  Goto Main
  
TimedOut:
  SerTxd( "Timed Out", CR, LF )
  Goto Main
Check that the remote is putting out Sony TV codes because that is all the IRIN command will recognise. There are variants of the Sony IR codes so perhaps try another remote.

You will not be able to use IROUT and then IRIN to read what was sent because what you send will have been sent before you come to read it.
 

papaof2

Senior Member
I am trying to work with the IR commands and have not much luck. Nothing seems to work.

main:
irout C.0,1,1
irin A.0,b4 'check for IR input

[/code]
I can guarantee that this code will NOT do what you want.

The IROUT completes its task before the IRIN starts, so there's nothing for the IRIN to see. The PICAXE is a single-thread device and can't speak IR and listen for IR at the same time. I can also guarantee that you're not the first person to make that assumption ;-)

You can have IR communications if you send the IROUT from one PICAXE and receive that signal with IRIN on another PICAXE.
 

hbl2013

Senior Member
Thanks fellows for the replies! I have to look further into the suggestions offered
Just quickly for now
You can have IR communications if you send the IROUT from one PICAXE and receive that signal with IRIN on another PICAXE.
- I can also guarantee that you're not the first person to make that assumption ;-)
Come to think about it, it's obvious that it does not work! Your second suggestion of using an other PICAXE to generate the pulse is a good one, but it does not explain why the diode does not work. I should see a pulse train on the scope, and I do not see one.

Also, the fact that the codes are not received from my Sony Remote, does it mean that the type of code is wrong? There is no way of changing it, it is fixed. I do not have another one, this one is for a HD TV.
And why does the PULSIN not see anything? That should not be dependent of any code, just the fact that there is a pulse or not.
 

eclectic

Moderator
"And why does the PULSIN not see anything? That should not be dependent of any code, just the fact that there is a pulse or not. "
IRIN is blocking, so the program never gets to that line.


Please try the simple code in post #6.

Press each of the remote keys in turn.

There might be a couple that work.

(I have a very old SONY HiFi remote, and only a few keys produce a response.)

Otherwise, off to the cheap-shops to buy a universal remote. :)

e
 
Last edited:

hippy

Ex-Staff (retired)
but it does not explain why the diode does not work. I should see a pulse train on the scope, and I do not see one.
There should be a modulated pulse train going to the IR LED. This test code flashes a normal visible LED+R connected to C.0 on a 28X2 -

Code:
Do
  IrOut C.0, 1, 1
  Pause 250
Loop
Could the hardware be wired wrongly ?

Try a simple HIGH / LOW loop on C.0 and check that can be seen on the scope.

Also, the fact that the codes are not received from my Sony Remote, does it mean that the type of code is wrong?
Possibly.

And why does the PULSIN not see anything? That should not be dependent of any code, just the fact that there is a pulse or not.
As it is in your code, if the IRIN doesn't receive data, the PULSIN will never activate. Even with the IRIN removed the incoming IR pulse has to arrive at a time when PULSIN is active.
 

hbl2013

Senior Member
As it is in your code, if the IRIN doesn't receive data, the PULSIN will never activate. Even with the IRIN removed the incoming IR pulse has to arrive at a time when PULSIN is active.
That is true as per my code. But there is nothing there either when I use the remote, while I can see the pulse train on A.0. And that was what I was refering to.

And yes, the pin goes High and Low, I checked that. The only thing is, should the Port be normally HIGH before I pulse it with the IR data or should it be normally LOW? As is it is, it is LOW, because I ground the IR DIODE trough a 330 ohm resistor. To make it HIGH I would tie it to VCC with a 330 ohm resistor.
 

eclectic

Moderator
IR diode?
Grounding?

I'm confused.
Have you got the exact circuit from the Manual?

As an aside, Pulsin works fine
using my exact same circuit as post #6.

e
 

Attachments

Last edited:

hbl2013

Senior Member
I had the chance to work on this project again and here are some updates. The Remote used turned out to be for a Sony DVD/VCR, and once I got a Universal Remote programmed for a Sony TV, things started to work.
The IR diode was connected to the wrong pin, and I got that working now.
Originally my goal was to use the IR features of the PICAXE to build a object avoidance little robot car. It seems that that is not possible with the standard IR statements available to the user. The question is, how DO you use an IR system to build one? Somehow the processor has to know when a IR pulse is sent before it can look for the echo and able to calculate the distance. Also, to use an IR detector, the pulse has to contain a 38kHz modulation, otherwise the detector will ignore it.
Any comments?
 

Rick100

Senior Member
These IR detectors are used for object detection but they provide no distance information . You send a carrier signal and watch the module for an output to see if the signal is reflected back . The pwm command can be used to turn an IR led off and on at 38kHz for the carrier . Here is a website about the testing of a Panasonic 4602M for this purpose . Apparently , some IR detector modules are better for this than others . If you want distance info use one of the sharp modules .
 

erco

Senior Member
@hbl: Yes, the only codes that work come from a Sony TV remote, or a universal remote set up to work like one.

BTW, I've used many different IR receiver modules and have never used a pullup resistor on the signal line. Never had a problem, always works fine. My favorite is the Vishay 4038, which is a fixed-gain, continuous signal compatible unit. It actually has a feature that can measure the relative strength of the reflected signal, which can be used to estimate distance.

From http://www.vishay.com/company/press/releases/2010/100628irsensors/ :

Many other applications require a reflective sensor that detects not only presence but also proximity by measuring the strength or weakness of the reflected signal. Instead of a fixed detection threshold, analog information from the sensor is needed. This is possible with the TSOP4038, TSOP58038, and TSOP58P38 IR proximity sensors. The length of the sensor’s output pulse in response to the emitter signal varies in proportion to the amount of light reflected from the object being detected. For near objects, the output pulse approaches 100 % of the emitted pulse, for far objects the output pulse becomes shorter.

 

Goeytex

Senior Member
An object avoidance detector that relies upon reflected Infrared light would be extremely difficult if not imposible to do with a Picaxe(s) and standard fare IR LEDs and receivers. Many objects would simply absorb the IR and reflect nothing back. Even if the object was IR reflective, the reflected signal would be so weak that range would be dismal. Consider the reflective angle of a sphere. Even it it were chrome plated , what percentage of the IR would be rflected back to the receiver? A large wide angle colimating lens would be needed on the receiver side to have any hope of receiving even the faintest signal.

It would be extremely difficult if not impossible for the receiver side to discriminate between a far away object that is IR reflective and a close up object that is not.

It would need 2 microcontrollers, one for the tranmsittier and one to receive the reflected signal. A single Picaxe could not do it because for all practical purposes the light would be reflected back at the same time it is being tranmsitted (About 300 million meters per second.)

Even if the reflected signal could be detected it extremely unlikely that a Sony IRC packet data could be sent and reflected back intact. All things considered, I think this is pretty much undoable at a hobbyist level for the purpose of object avoidance in a small robot. IR Proximity detection is certainly doable as Erco notes above, but it generally is used to detect the proximity of objects of a known size, shape & reflectivity. Detecting the proximity of a black box might be a challenge.

There are good reasons that "radar" and an "sonar" are generally used for this kind of stuff.
 

hippy

Ex-Staff (retired)
It would need 2 microcontrollers, one for the tranmsittier and one to receive the reflected signal. A single Picaxe could not do it because for all practical purposes the light would be reflected back at the same time it is being tranmsitted (About 300 million meters per second.)
It can be done with a single PICAXE by generating 38kHz PWMOUT to an IR LED+R and then reading the IR Receiver chip as a digital input; if low the IR is being reflected back, if high it is not.

The PWMOUT needs to be turned off after each check as continuous IR may stop the IR receiver working reliably.
 

hbl2013

Senior Member
I am glad that there was such a response to my question about the use of IR for Object Avoidance purposes. It is now much clearer as how it would work, and it seems that it is not the way to go. As a better alternative, I will look into a Sonar based system (such as PING) that many others seem to use

This might help
http://www.picaxeforum.co.uk/showthread.php?14691-Robot-with-infrarred-sensor

It's not really clear how you were expecting a remote control to help with object detection? IRIN isn't really much use for this, its intended for receiving commands from the remote.
Sorry, I was not too clear in my postings here. The questions about the remote use was more a result of my attempts to use the IR system as an object avoidance tool. From one thing came another, and as I was trying things out, the problems with the Remote popped up. It was never my intention to use the Remote for anything other than testing if the Detector was working correctly.
BTW I can now control my little car with the IR Remote Control, but that was not my goal!
 

erco

Senior Member
There are many small robots which use 38kHz IR receivers for proximity detection. They work fine for general collision avoidance, but accurate distance measurements are nearly impossible for a couple of reasons. First, it's a digital signal, either it's detected or it's not. Some minimum threshold of reflected signal is required for the receiver to detect it. More importantly, the color and reflectivity of the object affects the signal drastically. Many white, reflective objects are more easily seen at long range, dull black or cloth objects (like a sofa) are not seen until very close.

There is an interesting technique to estimate relative range by doing a series of off-center frequency measurements. For instance, a sensor with a 38 kHz center frequency will be less sensitive to a 37 kHz signal, so doing a frequency sweep from 37 to 38 kHz and noting where the signal is detected (how far from center frequency) gives an idea of relative signal intensity/distance.
 
Top