<Question> First Project With IR

Discussion in 'General Discussion' started by Kolonka, Feb 27, 2015.

  1. Kolonka

    Kolonka New Member

    Joined:
    Jun 20, 2014
    Messages:
    5
    Likes Received:
    0
    Hello,
    I've got an UDOO Quad since 2 years so I finally want to start my first project (like often before, but I don't want to kill it).
    The first part is: i push a button on a remote and a led should turn on.
    So I need an IR-Receiver and an LED (I have many of them in different colors and they are nice and...).

    The 2nd part is, to read the codes of the remote and save them to let the led run later.
    Then the LED should be replaced by an IR-LED.
    At the end a little app for android on udoo should run the different codes when pushing a button.

    So before I put anything into the ports on my UDOO, I need some instructions how to do that.
    I found this: http://www.zovirl.com/2008/11/12/buildi ... n-arduino/
    I don't have an oscilloscope so i wanted to do it with the IR-Reveiver (or maybe with the soundcard trick on an old PC to start with the 2nd part directly)

    I will need an resistor for the LED. U=R*I, R=U/I
    UDOO can handle 30mA (right?) so R = U / 0,03A
    on 5V: R=167o
    on 3,3V: R=110o
    I don't think that this is really right, because i think thats too low...
    Maybe it also depends on the LED
    The reciever maybe also need some resistor (=same?).

    The code:
    I'm a java dev but I worked with arduino a year ago. theres one line in the code in the link above i don't understand:
    Code:
    #define BIT_IS_SET(i, bits)  (1 << i & bits)
    if (BIT_IS_SET(i, bits)) {
    is it the same like:?
    Code:
    if (1 << i & bits) {
    what does this mean? i read that << is something like if i = 6 then the 1 will get from
    0000 0001 to 0100 0000 what is 64. "bits" is just an integer. so what does he do with f.e. 64 & 4? in java theres no if(int) so i don't know. internet says: 64 != 0 && 4 != 0, but that makes no sence..

    Back to hardware:
    the whole project shouldn't be more expencive than 10€, cause i will get a touchscreen for the android part of the project and then I'm poor. which IR-led do i need? which receiver do I need (IR-Receiver, something else with soundcard or anything else)? and which resistors do I need? How do I need to calculate, if i try other hardware like engines or... What does the code say? ( :p ).

    Thanks for help!
     
  2. fetcher

    fetcher Member

    Joined:
    Mar 9, 2014
    Messages:
    166
    Likes Received:
    20
    30mA is high for an indicator LED. I'd try for 10mA to start, or 20 at most. Different colors of LED have varying voltage drops and best resistor values, but if you don't try to push current to the max the exact value isn't critical. 330ohm or 470 ohm should be well within the safe region, driving from a 3.3V pin.

    You really don't want to use a raw phototransistor or photodiode to receive encoded IR. Infrared remotes cycle their sendng LED on/off at relatively high frequencies, usually around 38kHz (a few as high as 56kHz), sending bursts/pulses of this carrier in various patterns to identify the particular button pressed. This helps separate out the signal from sunlight, fluoresecent lamp strobing and other IR noise. Absolute intensity will vary greatly with distance, direct vs. reflected paths, etc. and can be quite weak, so the receiver uses an analog filter, detector and amplifier circuit to extract clean, data-rate TTL data pulses from the raw IR, after removing the 38kHz carrier.

    These 3-pin "IR receiver modules" are far easier to interface to digital logic than a raw phototransistor, and fairly cheap, available for just few dollars or euro. If you have any obsolete or broken A/V equipment on hand (old VCRs, etc.) you can even obtain one for free by desoldering it from the front-panel board. Here's what one common type looks like: http://www.radioshack.com/38khz-infrare ... 60640.html (from an overpriced but convenient US electronics store that just declared bankruptcy).

    These usually want +5V power and yield a 5V signal, so you need to drop that down to safely connect to a 3.3V input. Since Udoo pins have a weak pullup resistor, a simple diode will do, letting the module pull the pin down when low, but blocking the +5V when high (the pin will then float to 3.3V from its internal pulup). Connect the cathode (striped end) of the diode to the IR module's output, anode to an Udoo input pin. Small-signal diodes are best, but at these low bit rates just about anything will work-- 1N4001 rectifier diode, etc.

    Here is an Arduino IR library that works on the Due (hence Udoo also) for both sending and receiving:

    https://github.com/enternoescape/Arduino-IRremote-Due

    Receiving (from one of the modules mentioned above) can be done on any pin, but only a few specific pins are supported for sending out IR codes (emulating a remote for controlling A/V equpiment via Udoo), and you have to patch the library code to use a non-default one.

    In the second post of this thread I included a sample sketch which, amongst other things, receives IR codes and prints them to the serial console. This might be helpful as a starting point:

    reducing-sam3x-power-consumption-wait-sleep-mode-t2176.html#p12130

    For receiving, I've found that Sony remotes work well, as do some using the NEC protocol. Certain others don't play well with my sleep-until-first-pulse power saving method (SAM3X takes a short time to wake from BACKUP mode, and so can miss critical parts of certain IR codes), but if you don't care about 200mW of extra power use you could just have it busy-waiting in Loop(), as would normally be done with this library and probably have more flexibility in the choice of remote.
     
  3. Kolonka

    Kolonka New Member

    Joined:
    Jun 20, 2014
    Messages:
    5
    Likes Received:
    0
    ok thanks for the long answer!! i didn't understand everythink but at first here are some receivers a led. i'm sorry that these links are german.
    led:
    http://www.amazon.de/St%C3%BCck-200mW-I ... frarot+led
    the leds are in a 20pcs pack for cheap 5€. wavelength is 850nm. 1,5-1,6 voltage. 20mA current

    receiver
    http://www.amazon.de/Bheema-Infrarot-IR ... rot+sensor
    no description, but is for arduino
    http://www.amazon.de/Adafruit-157-Senso ... rot+sensor
    runs at 3-5 voltage. for 38kHz freq. no decoding

    and at the end here is a pack of led and receiver:
    http://www.amazon.de/pairs-Infrared-Dio ... cp_light_2
    Feature:
    Voltage:2.7~5.5V
    Frenqence:38KHz
    Receiver Angle:±45°
    Operate Distance:18~20m
    Total Length approx. 30mm
    --> and cheapest!

    what do you think about that links?
    what do you mean with:
    ?
    i think they just send on/off fastly which can be decoded easyly like in http://www.zovirl.com/2008/11/12/buildi ... n-arduino/ using graphing or isn't it possible to get this nice graph with a simple ir-receiver, a soundcard and some ubuntu tools or audiacity? or the other way around: what would decoding ir-receivers send back? i don't have old devices to get free hardware.
    how would you get the input data of the ir-receiver into integers to save?
     
  4. fetcher

    fetcher Member

    Joined:
    Mar 9, 2014
    Messages:
    166
    Likes Received:
    20
    The IR receiver modules you link to look good. I'd go for the one that can be powered directly from 3.3V (3.3V - 5.5V range), to avoid any need for level-shifting. Assume one not mentioning voltage wants 5V only.

    Note that all the LEDs you link to are IR only -- good for transmitting remote signals, but not as visible indicators since they'll be invisible to the eye. Your original post mentioned wanting to light an LED as a signal. Of course, those are easy enough to come by...

    Receiving signals using just a phototransistor is doable, it's just more work. Your might need to use a rapidly-sampled SAM3X analog input rather than a digital one, since the signal voltage coming from the phototransistor (difference beween IR present and not-present states) may be small in comparison to the constant DC bias, and both will change as a function of range, ambient light, etc. Your code would need to separate out that desired signal from the DC and any other noise-- looking for edges meeting a minimum dV/dt rise/fall time threshold might be the best way-- then check recorded time deltas for the detected edges to remove/ignore the 38khZ carrier. The module does all this for you, so you get a clean digital signal with nearly the full 0-3.3V or 0-5V swing.

    An advantage of the software-only method is that you could use remotes that send at a different IR carrier frequency, such as 56kHz, although there aren't many of those around. Some are 40kHz, which is close enough to 38k to satisfy the integrated modules, at slightly reduced range.
     
  5. Kolonka

    Kolonka New Member

    Joined:
    Jun 20, 2014
    Messages:
    5
    Likes Received:
    0
    ok thanks, now i understand what you meant. the ir receiver can filter the right frequency so its easyier to use.

    so you think this is the right one, too: http://www.amazon.de/pairs-Infrared-Dio ... cp_light_2
    it runs with 2,7-5 volts and has a freq of 38 (why does normal remotes use this frequency? why it is not simply 40 KHz..)
    I have some color leds at home but in an official tutorial i saw, that the leds are connected directly from gnd to pin 13. why they do not need to put a resistor between that?
    for now i will try to make a led blinking but do i need a resistor? and what about resistors for the ir reciever?
     
  6. fetcher

    fetcher Member

    Joined:
    Mar 9, 2014
    Messages:
    166
    Likes Received:
    20
    The IR LEDs and receivers from your amazon.de link look fine.

    I don' t know the history of why 38kHz became a common IR frequency, and would be curious to find out-- maybe an early TV manufacturer got a good deal on crystals that happened to divide down to this frequency, then others followed suit? Some types do use 40kHz, which is close enough to 38 that the detectors work for those also, though at reduced range (the rare 56k is too far away).

    I think that some Arduinos, such as the "Uno" model, may have a built-in resistor on pin 13, due to a (visible) LED already being present on the board as well for that pin, meant to allow for quick testing & demos without having to wire anything up. This isn't the case for an Udoo or Arduino Due, though, so be sure to add your own.

    Some people try to skip the resistor and rely on short pulse times alone to limit heat buildup, but that can risk damage to both the LED and the pin driving it -- especially with the more delicate, 3.3V processors in a Due or Udoo having more limited current drive capability compared to an 8-bit AVR. It's bad practice to do this, and unnecessary since resistors are easy to come by and quite cheap.
     

Share This Page