IR receiver/remote control problem

IDE: Arduino 1.8.4-V6.0
Board: Microduino/mCookie-device (VID: 10C4 PID: EA60)
Processor: Microduino/mCookie-core (328p)
Port: COM6

I've built "Light house" example from "Itty Bitty City" microduino kit.
Here is the code which initialises an IR receiver and decodes signals of remote control:

void setup() {
  Serial.begin(9600);
  irrecv.enableIRIn();//Initialize the Infrared Receiver and begin receiving data.
  Serial.println("**************START************");
}

void loop() {
  if (irrecv.decode(&results)) 
  {
    Serial.print("Recv Code:");
    Serial.println(results.value);
    recvParse(results.value);
    //irrecv.enableIRIn();
    irrecv.resume(); //Receive next value.
  }

The problem is that no matter which button I pressed on remote control, the decoded value is always "0"
Why is this happening?

@asocial

Your topic was Moved to it's current location / section as it is more suitable.

Could you also take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

The code that you posted will not compile. It is incomplete. Always post the entire program.

The recvParse(results.value) function is missing from your code as well as the #include for the library and the constructors and is missing a } to close the loop() function.

#include <IRremote.h>

const byte IR_RECEIVE_PIN = 4;  // ******* note the recv pin

IRrecv irrecv(IR_RECEIVE_PIN);
decode_results results;


void setup()
{
   Serial.begin(9600);
   irrecv.enableIRIn();//Initialize the Infrared Receiver and begin receiving data.
   Serial.println("**************START************");
}

void loop()
{
   if (irrecv.decode(&results))
   {
      Serial.print("Recv Code:");
      Serial.println(results.value);
      //recvParse(results.value);
      //irrecv.enableIRIn();
      irrecv.resume(); //Receive next value.
   }
}

This code works for my remote.

Have you made sure that your remote is in fact transmitting? Most cell phone cameras are sensitive to IR light. You should see a blue glow in the camera when the IR LED transmits.

Are you sure of the decoder wiring?

Have you tried any of the examples that come with the IRremote library?

Hello!
I initially compiled and uploaded this sketch without any modifications: Examples -> mCookie_IBC -> _02_Lighthouse. Here is the source code:

Lighthouse.ino

#include "IRControl.h"
#include "colorLed.h"
#include "userDef.h"


void setup() {
  Serial.begin(9600);
  strip.begin();
  strip.setBrightness(BRIGHT_MAX);
  irrecv.enableIRIn();//Initialize the Infrared Receiver and begin receiving data.
#if DEBUG
  Serial.println("**************START************");
#endif
  //Shine 10 colors for 0.5 seconds each.
  for (int i = 0; i < 10; i++)
  {
    setAllLed(i);
    delay(500);//每个颜色持续时间
  }
}

void loop() {
  if (irrecv.decode(&results)) //If there is an available Infrared signal, then:
  {
#if DEBUG
    Serial.print("Recv Code:");
    Serial.println(results.value, HEX);
#endif
    recvParse(results.value);
    //irrecv.enableIRIn();
    irrecv.resume(); //Receive next value.
  }

  switch (mode)
  {
    case MODE_OFF:
      setAllLed(LOW);
      break;
    case MODE_A:
      ledRainbow(20);       //Rainbow effect, 20 ms for every color.
      break;
    case MODE_B:
      ledBreath(COLOR_WARM, 10);
      break;
    case MODE_C:
      ledBreath(COLOR_COLD, 10);
      break;
    case MODE_D:
      setAllLed(colorNum);
      break;
    case MODE_E:
      ledBreath(Color[colorNum], 10);
      break;
    default:
      break;
  }
  delay(20);
}

IRControl.h

#include <IRremote.h>//Import the library for the Infrared Receiver.
#include "userDef.h"

#define  BUTTON_POWER   0x1FE48B7
#define  BUTTON_A       0x1FE807F
#define  BUTTON_B       0x1FE40BF
#define  BUTTON_C       0x1FEC03F
#define  BUTTON_D       0x1FE20DF
#define  BUTTON_E       0x1FE609F
#define  BUTTON_LEFT    0x1FEE01F
#define  BUTTON_RIGHT   0x1FE906F
#define  BUTTON_UP      0x1FEA05F
#define  BUTTON_DOWN    0x1FED827
#define  BUTTON_OK      0x1FE10EF
#define  BUTTON_BACK    0x1FE50AF
#define  BUTTON_VOLUP   0x1FEF807
#define  BUTTON_VOLDOWN 0x1FE708F
#define  BUTTON_MUTE    0x1FEB04F
#define  BUTTON_PLAY    0x1FE30CF



#define  MODE_OFF     0
#define  MODE_A       1
#define  MODE_B       2
#define  MODE_C       3
#define  MODE_D       4
#define  MODE_E       5

IRrecv irrecv(PIN_RECV);
decode_results results;

uint8_t mode = MODE_OFF;
uint8_t colorNum = 1;


//------------Receiving Infrared Signals from Remote Control-------------//
void recvParse(uint32_t recvCode)
{
  switch (recvCode)
  {
    case BUTTON_A:
      mode = MODE_A;
      break;
    case BUTTON_B:
      mode = MODE_B;
      break;
    case BUTTON_C:
      mode = MODE_C;
      break;
    case BUTTON_D:
      mode = MODE_D;
      colorNum = 3;
      break;
    case BUTTON_E:
      mode = MODE_E;
      colorNum = 3;
      break;
    case BUTTON_LEFT:
      colorNum--;
      if (colorNum < 3)
        colorNum = 9;
      break;
    case BUTTON_RIGHT:
      colorNum++;
      if (colorNum > 9)
        colorNum = 3;
      break;
    case BUTTON_POWER:
      mode = MODE_OFF;
      break;
    default:
      break;
  }
}

userDef.h

#define DEBUG       1      //Serial monitor debugging ON/OFF.
#define PIN_RECV    4      //Infrared Receiver pin.
#define PIN_LED     12     //ColorLED pin.
#define LED_NUM     2       

//=================================DO IT YOURSELF: CHANGE THE CODE BELOW!========================================//
//Example: Change "#define BRIGHT_MAX 128" to "#define BRIGHT_MAX 180".                                          //
//         That means the LED will now shine brighter than before.                                               //
//                                                                                                               //
//IMPORTANT: Remember to upload the code into the mBattery again after changing the values!                      //
//===============================================================================================================//
#define BRIGHT_MAX  64         //Max LED brightness. Max brightness is 255. Minimum brightness is 0.

Have you made sure that your remote is in fact transmitting?

Yes, I'm sure. I run it under debug and it printed "0" in console whatever button I pressed on remote control. Also the LED blinked every time I pressed a button on remote control. I've tried wiring on different pins, but it didn't help

Have you tried any of the examples that come with the IRremote library?

SmartCar (Examples -> mCookie_IBC -> _08_SmartCar) has the same problem, it can not be controlled with remote.
BTW, it turned out that one of the weels isn't flat enough, so the car can't move straight :frowning: