ir library not working on stand alone mode

While in board am recving ir signal. And intensity of my load led is changing bt when I make it to work in standalone mode its not working,pls help me out

I means board means arduino board*

Since we are not telepathic, you need to give a lot more information about your problem, including what it is intended to do, what you have actually achieved so far in working up to your present project, and the code you are using - posted in code tags ([ # ] button above the "post" window).

i want to comtroll my led lamp intensity and switching,in arduino board its working perfectly bt wen i make it stand alone its not working,i ve tried blink program with stand alone ckt its working pretty fine bt wen i ude ir library its not working.and my code is
#include <IRremote.h>

int IRpin = 11;
IRrecv irrecv(IRpin);
decode_results results;
int led=9;

const long int uparrow = 2153764903;
const long int downarrow = 2153773063;
const long int rightarrow = 2153732263;
const long int leftarrow = 2153740423;
const long int okbutton = 2153765413;

void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
pinmode(led,output);
}

void loop()
{
if (irrecv.decode(&results))
{
irrecv.resume();
}

switch(results.value)
{

case uparrow: // up arrow
analogwright(led,255);
break;

case downarrow: // down arrow
analogwright(led,0);
break;

case rightarrow: // right arrow
analogwright(led,100);
break;

case leftarrow: // left arrow
analogwright(led,150);
break;

case okbutton: // ok button
analogwright(led,200);
break;

}}

that 2153764903; and etc all are my remote decoded signal which i have got from serial monitor this code is working good in arduino board bt not in stand alone mode i have used tsop to recive IR

I'm also having same problem as mentioned above, I'm working on a simple project where 4 LED's are connected to arduino I want to control them using TV remote . I decoded decimal values of TV remote using serial monitor and programmed the microcontroller with those values . A TSOP 1738 is connected to receive commands. I have programmed arduino such that when particular key is pressed in TV remote accordingly LED's light up. This is working very fine.

But the problem is when I take this to standalone PCB , where I put programmed microcontroller and crystal and capacitor. TSOP receives the commands from remote. I have used switch statement for decoding but it always goes into default statement instead of case statement.

For example , In TV remote value of key 1 - 49284 . In switch statement , case 49284 : is not executing when I press key 1. Instead it executes default statement.

Please help me regarding this .

Thank you, -Krishna Patil

I’m putting the code for convenience

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;
int l1=A0;
int l2=A1;
int l3=A2;
int l4=A3;


void setup()
{
  
  irrecv.enableIRIn();
  pinMode (l1,OUTPUT);
  pinMode (l2,OUTPUT);
  pinMode (l3,OUTPUT);
  pinMode (l4,OUTPUT);
}

void loop() {
   digitalWrite(l1,HIGH);  // LED's are wired up using active low logic , so a high is required is keep them off.
    digitalWrite(l2,HIGH);
    digitalWrite(l3,HIGH);
    digitalWrite(l4,HIGH);
  if (irrecv.decode(&results)) 
  {    
    switch (results.value) 
  {
  case 49284:      
  digitalWrite(l1,LOW);
  delay(5000);
    break;
  case 49220:   
    digitalWrite(l2,LOW);
    delay(5000);
    break;
  case 49348:  
    digitalWrite(l3,LOW);
    delay(5000);
    break;
  case 49188:  
    digitalWrite(l4,LOW);
    delay(5000);
    break;
    case 49384:
    digitalWrite(l1,LOW);
    digitalWrite(l2,LOW);
    digitalWrite(l3,LOW);
    digitalWrite(l4,LOW);
    delay(5000);  
    
   default: digitalWrite(l2,LOW); // this is written only to confirm that neither of cases is executing. It is not a part of actual code. Always this is executing when I run on standalone mode
    delay(1000);
    digitalWrite(l2,HIGH);
    delay(1000);
    digitalWrite(l2,LOW);
    delay(1000);
  }   
         
    irrecv.resume(); // Receive the next value
  }

 }
  • In standalone , microcontroller pins 23,24,25,26( A0,A1,A2,A3 in arduino) are connected to LED’s which are pulled up by resistors. Pin 17(11 in arduino) is connected to TSOP signal pin.

and to make it considerably easier to read and decipher your code, you should go back and select "modify" on your previous posting, highlight the actual code in it and click on the "Insert Code" [ # ] icon above the text window and save it.

Ok done. Thank you for making me aware of that :)

krishnapatil: Ok done. Thank you for making me aware of that :)

That did not work out too well at all!

How can I make it work out ? I highlighted the part of code, only where program flow goes .

In simple words, all I can tell is like this

Scenario 1 :- I connect my arduino uno , connect TSOP and put the above code . Everything works fine.

Scenario 2:- I take out Atmega 328 from UNO and put it with crystal, capacitor and wire it up with a TSOP 1738. Everything else works fine except Switch statement.

Please see the Switch cases , for example

1) case 49284: some statements; break; // here if I recieve " 49284" from decoded results of IR , it would execute statements. 2) case 49220.. ... etc.,

Instead of all these cases it is executing default in switch , which means microcontroller is not decoding the IR signals properly

I somehow managed to find a link where someone posted similar to what I have been doing.

check this http://majsterkowo.pl/how-to-control-any-home-appliance-using-a-tv-remote-and-an-arduino/

My only problem is that , all this works when microcontroller is in arduino board . If I make it as standalone project and remap pins accordingly. IR decoding doesn't work.

krishnapatil: How can I make it work out ? I highlighted the part of code, only where program flow goes .

Which has just garbled it.

The purpose of marking code as such, is to make it readily legible as it would appear in the IDE, particularly to preserve the formatting (indenting) and to prevent certain substitutions including "smileys" (such as 8) where "8" is typed adjacent to the right bracket) which the forum software performs. This has nothing whatever to do with "program flow".

So you need to go back, remove all the "[ code ]" tags incorrectly placed, highlight your code in its entirety and mark it up. Then it may be comfortable to examine it in detail. :D

Ok I got it. Thanks! Now comfortably examine the code and please tell the solution. I'm here for solution !!

Hi

Have you tried adding serial debugging to your code to see if it is still interpreting the iR signals (but the LEDs are not firing) or if it's not seeing the iR signals entirely? Are you seeing the default LED display from your switch/case every time?

If you add an LED between the output and VCC pins on your TSOP receiver does it flash when the iR signal is received (to eliminate the possibility your sensor has failed)? This Adafruit article shows how.

krishnapatil: Ok I got it. Thanks! Now comfortably examine the code and please tell the solution. I'm here for solution !!

If it worked on the Uno, the problem is less likely to be in your code. Have you tried a simple test sketch to flash the LEDs to ensure they all function and that your standalone is actually working (and working at the correct clock speed)? Setup a flash at 1sec intervals to ensure that what you see is running correctly. If they're flashing slower, the chip may still be running on its internal clock rather than the external crystal - indicating you need to set the internal fuses still.

Lots of options here. Lets' remove the obvious ones and let us know how you go.

Cheers ! Geoff

Edit: added adafruit link

Have you tried adding serial debugging to your code to see if it is still interpreting the iR signals (but the LEDs are not firing) or if it's not seeing the iR signals entirely? Are you seeing the default LED display from your switch/case every time?

Thank you for reply, If I get a signal from microcontroller, LED's are correctly firing . I checked it . But due to improper detection of IR signals it won't go into case statements in the program . Since as I mentioned defualt is working that means IR is active . It is seeing the signals, and it is responding. But not responding properly. Yes! I'm seeing default LED display everytime.

If you add an LED between the output and VCC pins on your TSOP receiver does it flash when the iR signal is received (to eliminate the possibility your sensor has failed)?

Sensor is properly working. I have checked it by taking inputs from microcontroller inside arduino board. If I take out microcontroller outside , then it won't work . Of course it is seeing IR signals, but decoding is not proper.

If it worked on the Uno, the problem is less likely to be in your code. Have you tried a simple test sketch to flash the LEDs to ensure they all function and that your standalone is actually working (and working at the correct clock speed)? Setup a flash at 1sec intervals to ensure that what you see is running correctly. If they're flashing slower, the chip may still be running on its internal clock rather than the external crystal - indicating you need to set the internal fuses still.

Yes, it is working perfectly when I take TSOP output and connect to microcontroller inside arduino board. Rest all circuit remain same. Only if I make standalone it is not working.

As you said crystal might be a problem . I measured timing by making them flash for 5 sec interval . They take 7 sec !! There is a mismatch. I was using 11.0592 MHz crystal on standalone board with two capacitors. I tried all other programs like just simply flashing LED's etc., they all working fine at crystal of 11.0592 MHz.

In arduino board, there is 16MHz crystal , so I tried 16 Mhz crystal . It won't work . Even other programs like flashing LED's won't work. Same result for 12MHz crystal also.

Note : 16Mhz crystal was a four pin crystal( I couldn't find 2 pin in local store) . I used two pins other side of notch. Leaving notch side pins unconnected. 12Mhz crystal was 2 pin.

What might be other possibilities of error ?

krishnapatil: What might be other possibilities of error ?

It seems like you found the source of the issue. Just get the timing issue sorted with a functional 16MHz crystal or resonator and it should be perfect.

Of course you need to remember to set the fuses internal to the ATmega to get it to expect and use the correct clock signal source. This is done by choosing the "load bootloader" option in the IDE and having a target board selected that uses that clock source - in your case Uno. If you have loaded the bootloader for Uno (say) and you're using a different clock source (other than 16MHz) your timing will be out. Timing is everything in this application.

Cheers ! Geoff

Edit: added note on fuses

My personal preference is to get IR to work all-the-time and then to just replicate and reuse. So, Sony IR is aavailable on every universal remotes, even the $1 from the dollar store!

The output of the IR module is simply serial which makes use into any Arduino project simply a couple of lines of code: http://forum.arduino.cc/index.php?topic=139907.0

Larger pix here: http://www.hackster.io/rayburne/infrared-dedicated-decoder

Ray

Thanks Geoff !! It worked ! 16 Mhz crystal cleared the problem.

Thanks Ray for your suggestion.

Great to to see. All the best with your project! Geoff