Arduino receiving infrared signal but nothing happening

I am trying to make this project from Arduino Project Hub.
It doesn't seem to be working for some reason, though. It might be the remote that I am using, but I can see that the Arduino is receiving the signal, because the TX light blinks every time I click a button, but nothing is happening on the display. Can somebody please help me with this?

Thanks.

Show us a good schematic of your circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.


In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.

Use the </> icon from the ‘reply menu’ to attach the copied sketch.

Hi,

What display?
If it is the IDE monitor, make sure you have the monitor baud rate set at the Serial.begin() baud rate.

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

I am talking about my LCD display.

Hi,

What Tx LED.
Have you got any information displaying in your LCD?
Can you please post your code in a new post?

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

Hi,
Better define "It doesn't seem to be working for some reason".
Are you using LCD in your project?
Does something appear on the LCD?

RV mineirin

What version of the IRremote library do you have installed? The new versions (3.0+) is not compatible with older code like the code in the project page.

Ok, I changed it to version 2.8, but now the TX light isn't blinking at all...

Hi,

Please post your code and a circuit diagram.

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

What remote control are you using, what IR receiver? I had some old TV remote laying around and tried it with standard 38KHz receiver, it appeared like it was recognised, but transmitted some gibberish so no codes could be deciphered. Best, get a cheap IR kit from ebay or ali to make sure you have working hardware.

Have you a spare Arduino and an IR LED which you could use to test the receiver part with ?

I uploaded the code from the linked site to my Uno with an I2C LCD attached. I too saw nothing at all printed to the LCD. I do not have nor do I have an inclination to try to find the LCD library that you are using. There are just too many (incompatible) libraries named LiquidCrystal_I2C. So I modified your code to use the hd44780 I2C LCD library (see below). The display now works.

For an I2C LCD display to work, the I2C address and the I2C backpack to LCD pin mapping must be correct. If the library default settings for either or both are not correct the LCD will not work. You can try to figure out the right pin mapping and use an I2C scanner to find the address, but if you install and use the hd44780 library that is done automatically by the library.

To install the hd44780 library. The hd44780 library is the best available for I2C LCDs. The library is available in the Library Manager. Go to Library Manager (in the IDE menus, Sketch, Include Libraries, Manage Libraries) and in the Topics dropdown choose Display and in the Filter your search box enter hd44780. Select and install the hd44780 library by Bill Perry.

The class that you want to use is the hd44780_I2Cexp class. There are examples to show how to use the library. The nice thing about the hd44780 library is that it will autodetect the I2C address and the I2C backpack to LCD pin mapping.

In the examples, there is a diagnostic sketch that will help us to help you if you still have trouble with the display. Run the diagnostic sketch and post the results.

Here is the code modified to use the hd44780 library. There are many compile warnings that you should resolve. Enable the display of compile warnings in the IDE Files, Preferences menu.

If you still do not see anything on the display, try adjusting the contrast pot on the I2C backpack.

/*
   Fast IR Game by mgbig V1.0
*/
#include <IRremote.h>
#include <Wire.h>
//#include <LiquidCrystal_I2C.h>
#include <hd44780.h>                       // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header

char up = 3;
char down = 1;
char ok = 2;

// Define 3 characters for the LCD Display
const byte up1[8] =
{
   B00100,
   B01110,
   B10101,
   B00100,
   B00100,
   B00100,
   B00100,
   B00100
};

const byte down1[8] =
{
   B00100,
   B00100,
   B00100,
   B00100,
   B00100,
   B10101,
   B01110,
   B00100
};

const byte ok1[8] =
{
   B01110,
   B01010,
   B01110,
   B10000,
   B10100,
   B11000,
   B10100,
   B10010
};

int RECV_PIN = 11;  // IR Sensor on Pin 11

const char* howtoplay[23] =
{
   "> FAST IR GAME <",
   "   Press key    ",
   "You have to",      // if you don't want this howToPlay you can delete from here ...
   "press the key,",
   "that you see on",
   "the screen, when",
   "it is beetween",
   "the fences (#).",
   "It ist getting",
   "faster and there",
   "will be symbols",
   "that you do not",
   "have to hit!",
   "Try to get to",
   "Level 10 and win",
   "the game. Before",
   "you start, you",
   "have to define",
   "the keys on your",
   "remote control",
   "to play the game", // ... until here. Leave the last lines for propper work!
   "  Have fun !!",
   ""
};

String keyNames[] = {"up", "down", "right", "left", "ok", "+", "-", "#", "*"};
String keySymb[] = {"", "", "", "", "", "", "", "", ""};
long keys[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int keycount = 7;

int lev;
int xpos = 1;
int xadd = 1;
int xleft;
int xright;
int xstart = 0;
int xend = 15;

int actSym = 0;
int score;   // All together score
int scorePerLev; // Symbols in actual level
int scoreNextLev = 50;  // Symbols until next level

int gameState = -1;

bool pressed = false;

IRrecv irrecv(RECV_PIN);
decode_results results;

//LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
hd44780_I2Cexp lcd; // declare lcd object: auto locate & auto config expander chip


void setup()
{
   Serial.begin(9600);
   //lcd.init();  // initialize the lcd
   lcd.begin(16,2);
   lcd.backlight();
   lcd.createChar(up, up1);
   lcd.createChar(down, down1);
   lcd.createChar(ok, ok1);
   keySymb[0] = "\3";
   keySymb[1] = "\1";
   keySymb[2] = "\176";
   keySymb[3] = "\177";
   keySymb[4] = "\2";
   keySymb[5] = "+";
   keySymb[6] = "-";
   keySymb[7] = "#";
   keySymb[8] = "*";

   irrecv.enableIRIn(); // Start the receiver

   info(); //howtoplay show once at the start, can be removed when you know how to play
   randomSeed(analogRead(1));
}


void loop()
{

   // define keys only once
   // gameState= -1
   // ################################
   if (gameState == -1)
   {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print(F("Define Keys to"));
      lcd.setCursor(0, 1);
      lcd.print(F("play the game..."));
      delay(3000);
      pressed = false;
      for (int i = 0; i < keycount; i++)   // 0 und 5
      {
         pressed = false;
         lcd.clear();
         lcd.setCursor(0, 0);
         lcd.print(F("Key for:"));
         lcd.print(keyNames[i]);
         while (pressed != true)
         {
            if (irrecv.decode(&results))
            {
               keys[i] = results.value;
               lcd.setCursor(0, 1);
               lcd.print(F(" ok!"));
               Serial.println(keys[i]);
               delay(500);
               irrecv.resume(); // Receive the next value
               pressed = true;
            }
         }
         pressed = false;
         lcd.clear();
         lcd.setCursor(0, 0);
         lcd.print(F("Repaet key!"));
         lcd.print(keyNames[i]);
         irrecv.resume();
         while (pressed != true)
         {
            if (irrecv.decode(&results))
            {
               if (keys[i] == results.value)
               {
                  lcd.setCursor(0, 1);
                  lcd.print(F("is the same!"));
                  delay(500);
                  pressed = true;
               }
               else
               {
                  lcd.setCursor(0, 1);
                  lcd.print(F("wrong!"));
                  delay(500);
                  lcd.setCursor(0, 1);
                  lcd.print("       ");
               }
               irrecv.resume();
            }
         }
      }
      gameState = 0;  // ok to select level
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print(F("Keys done!"));
      delay(2000);
   }

   // Select Level
   // gameState=0
   //###########################
   if (gameState == 0)
   {
      lev = 1;
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print(F("Select Level+ok"));
      lcd.setCursor(0, 1);
      lcd.print(F("Level: "));
      lcd.print(lev);
      irrecv.resume();
      pressed = false;
      Serial.println("Level");
      Serial.println(pressed);
      while (pressed != true)
      {
         if (irrecv.decode(&results))
         {
            Serial.println(results.value);
            if (results.value == keys[0]) lev++;
            if (results.value == keys[1]) lev--;
            if (results.value == keys[4]) pressed = true;
            if (lev < 1) lev = 1;
            if (lev > 10) lev = 10;
            lcd.setCursor(7, 1);
            lcd.print(lev);
            lcd.print(" ");
            irrecv.resume();
         }
         delay(250);
      }
      lcd.setCursor(0, 0);
      lcd.print(F("Ok! Play in    "));
      delay(2000);
      lcd.clear();
      gameState = 1; // Main gameplay
      score = 0;
      scorePerLev = 0;
      keycount = 7;
      xleft = 4;
      xright = 11;
      drawField("");
      irrecv.resume();
      Serial.println(F("Level Set"));
   }

   // Main Game
   // gameState=1
   //###############################
   if (gameState == 1)
   {
      xpos = 0;
      xadd = 1;
      int k = 0;
      bool rightkey = false;
      pressed = false;
      actSym = floor(random(0, keycount));
      while (pressed != true)
      {
         Serial.println(xpos);
         if (irrecv.decode(&results))
         {
            for (int i = 0; i < keycount; i++)
            {
               if (results.value == keys[i])
               {
                  rightkey = true;
                  k = i;
               }
            }
            if (rightkey == true)
            {
               scorePerLev++;
               if (xpos <= xleft || xpos >= xright)
               {
                  score = score - (4 + lev);
                  // negativ sound
               }
               if (actSym == k)
               {
                  lcd.setCursor(xpos, 1);
                  lcd.print(" ");
                  score++;
                  drawField("");
                  changeDirection();
               }
               else
               {
                  score = score - (2 + lev);
                  drawField(" :(   ");
                  // negativ sound
               }
               actSym = floor(random(0, keycount));
               rightkey = false;
            }
            delay(10);
            irrecv.resume();
            if (scorePerLev == scoreNextLev)
            {
               scorePerLev = 0;
               lev++;
               drawField("");
               if (lev < 11)
               {
                  lcd.setCursor(0, 1);
                  lcd.print(F("Next level!"));
                  waitForOK();
                  // Check for score and display message here later
                  lcd.setCursor(0, 1);
                  lcd.print("           ");
               }
               else
               {
                  gameState = 5;
                  pressed = true;
               }
            }
         }
         lcd.setCursor(xpos, 1);
         lcd.print(" ");
         xpos = xpos + xadd;
         if (xpos == xend + 1 || xpos == xstart - 1)
         {
            if (actSym < 7)
            {
               score = score - (2 * (lev + 5));
               drawField(" :(   ");
            }
            else
            {
               drawField("");
            }
            changeDirection();
            actSym = floor(random(0, keycount));
            // negativ sound
         }
         lcd.setCursor(xpos, 1);
         lcd.print(keySymb[actSym]);
         delay(200 - (lev * 10));
         if (score < 0)
         {
            gameState = 9;
            pressed = true;
         }
      } // Main Game loop End

   }

   // Win
   // ##################
   if (gameState == 5)
   {
      // positiv sound
      lcd.setCursor(0, 1);
      lcd.print(F("You win the Game"));
      lcd.setCursor(0, 0);
      lcd.print("Bravo! ");
      waitForOK();
      gameState = 0;
   }

   // Game Over
   // ##################
   if (gameState == 9)
   {
      // negativ sound
      for (int i = 0; i < 5; i++)
      {
         lcd.setCursor(0, 1);
         lcd.print("                ");
         delay(200);
         lcd.setCursor(0, 1);
         lcd.print(F("   Game over!   "));
         delay(300);
      }
      waitForOK();
      gameState = 0;
   }

}

void info ()
{
   int i = 0;
   while (howtoplay[i] != "")
   {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print(howtoplay[i]);
      lcd.setCursor(0, 1);
      lcd.print(howtoplay[i + 1]);
      delay(300);
      waitForKey();
      i++;
   }
   irrecv.resume();
}

void drawField(String empty)
{
   Serial.println(F("drawField"));
   int SCur;
   if (empty == "") empty = "      ";
   lcd.setCursor(0, 0);
   lcd.print("################");
   if (lev > 3)
   {
      xleft = floor(random(4, 7));
      xright = xleft + 7;
      if (lev > 6) xright = xleft + 6;
      if (lev > 9) xright = xleft + 5;
   }
   if (lev > 4) keycount = 8;
   if (lev > 6) keycount = 9;
   lcd.setCursor(xleft + 1, 0);
   lcd.print(empty.substring(0, xright - xleft - 1));
   lcd.setCursor(0, 0);
   lcd.print("L");
   lcd.print(lev);
   if (score < 1000) SCur = 13;
   if (score < 100) SCur = 14;
   if (score < 10) SCur = 15;
   if (score < 0) SCur = 14;
   lcd.setCursor(SCur, 0);
   lcd.print(score);
}

void changeDirection()
{
   xpos = xstart;
   xadd = 1;
   if (lev > 3)
   {
      int dir = floor(random(0, 2));
      if (dir == 1)
      {
         xpos = xend;
         xadd = -1;
      }
   }
}

void waitForKey ()
{
   bool press = false;
   irrecv.resume();
   while (press == false)
   {
      if (irrecv.decode(&results))
      {
         if (results.value != 0) press = true;
         irrecv.resume();
         delay(200);
      }
   }
}

void waitForOK()
{
   delay(1000);
   bool press = false;
   irrecv.resume();
   while (press == false)
   {
      if (irrecv.decode(&results))
      {
         if (results.value == keys[4]) press = true;
         irrecv.resume();
         delay(200);
      }
   }
}

The IR remote decoder also seems to work with the IRremote 2.80 version. I did no more than get the LCD to work and see if the decoder will function so the rest is up to you. We will gladly help if you get stuck.

I got a low memory warning when compiling for an Uno. Using the F macro on all string literal print statements saved 10% of SRAM and the warning no longer shows.

1 Like

I fixed the warnings. The warnings about making a comparison between signed and unsigned values is because results.value is a uint32_t data type so is unsigned and your keys array is the long data type (int32_t), a signed data type.
unsigned long keys[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
makes keys unsigned and fixes the warnings.

The last warning has to do with " comparison with string literals results in unspecified behaviour". That warning is because you cannot use != or == to compare strings. Use the strcmp() function instead.
while (strcmp(howtoplay[i], "") != 0)

With those fixes the code will compile without compiler or low memory warnings.

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.