Help Replacing Buttons with IR Remote Control

Greetings everyone

I have an arduino project "Digital_Clock_MAX7219_DS1307RTC_3button" which, as the name implies, is a Clock with a LED Matrix Module (4 in 1) using 3 buttons to set the time.

However, I would like to replace these 3 buttons with a simpler IR Remote Control, found on ebay, with 17 keys, manufactured by KEYES.

But, I don't have enough knowledge to do this, so I ask everyone's help.

I will be attaching the sketch to the intended changes and also attached an image of the Remote Control mentioned with its decodes.

In the sketch header the links from author page and youtube page.

Thank you in advance for your help.

Digital_Clock_MAX7219_DS1307RTC_3button.ino (12 KB)

OK. I see it following on from Need help completing sketck for Clock - #24 by Dancopy - Jobs and Paid Consultancy - Arduino Forum

Have I understood the situation correctly: You have build the clock according to the project described in the link: ARDUINO DIGITAL CLOCK USING DS1307 RTC AND MAX7219 8x8 LED MATRIX DISPLAY. - YouTube and the only issue is now to replace the 3 physical control buttons (shown on the breadboard) with an IR based control ?

If that is the case, it is a relatively simple project.

That's right; my control is as I attached to the "Keyes Infrared Remote.jpg" picture and it is working correctly.

You say it is relatively simple, but for me it is not, because I have little knowledge in Arduino.

So if you can help me with the code, I really appreciate it!

This is a separate test sketch just to checkout the IR parts.
Connect the output of the IR receiver to arduino pin A3 and test all the buttons work.

If that works, I will integrate into your clock sketch. The integration is quite simple but let's hope you have no problem with the size of it (memory usage).

It will behave as follows:

Button 1 on the IR will have the same effect as pressing button A on the clock.
Button 2 on the IR will have the same effect as pressing button B on the clock.
Button 3 on the IR will have the same effect as pressing button C on the clock.
The original clock buttons will continue to function as before.

What pin do you want to use for the IR receiver ?

I wont be able to test the integrated sketch because I don't have the hardware or libraries installed.

IR-Receiver-Test_V0_01.ino (2.55 KB)

Hi 6v6gt
First, I want to thank you very much for your kindness in helping me.

Regarding the sketch you sent me, I don't know if you did it by the way, but the "cases" were all with different Hexadecimal codes, so it presented all commands in the Serial Monitor as "Bad Results detected".

So I changed all Hex in the sketch as per my Control, then tested it on Serial Monitor and now show all "Valid Results detected".

For example, button 1 looks like this:

1
Valid Results detected
irResults.value: 0xFF6897; irKeyValue: 1

The irReceiver pin A3, I changed it to 9.

Thank you and I'm waiting,

Daniel Fernandes

IR-Receiver-Test_V0_02.ino (2.53 KB)

I see from the picture of the your IR device that it is nearly identical to mine, only they have turned it up side down and relabeled the buttons. Hence you had to correct the assignment between the codes and the buttons.

Try the attached code. I've not disturbed the main structure of the sketch too much. All lines which I've changed are marked // IR

I can't test it. If there is a problem with the total size, post the compiler/linker size message. Some optimisation is possible. If you make any changes to the code and need help, then post the entire new version of the sketch.

Digital_Clock_MAX7219_DS1307RTC_3button_V0_02.ino (14.8 KB)

Hi 6v6gt
Thanks for your effort!

Really, the sketch got big; as follows:

Global variables use 1104 bytes (53%) of dynamic memory, leaving 944 bytes for local variables. The maximum is 2048 bytes.
Sketch too large; See http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on how to reduce it.
Error Compiling for Arduino / Genuino Uno Card

OK. There is enough RAM so it must be the flash memory of which there is 32kB.

Look in the diagnostic output after doing a "verify" operation for the phrase "Linking everything together..." and post ALL the output that appears below it. This will include the flash memory usage (program storage space). Do this with both your original sketch and the new one.

I have a smaller IR library but, as it is currently configured, it can use only pin 2 or pin 3.

If it is really a border line case, you can free up flash memory by commenting out some of the debug print statements. However, be careful because there are some multi-statement lines which include print , e.g.

case 0xFD8877: rv = -10 ; Serial.println(F(" UP ARROW")); break;

You have to comment it out like this:

case 0xFD8877: rv = -10 ; /*Serial.println(F(" UP ARROW")); */  break;

Also, don't start removing comments unless you are only say 80 bytes short because trouble shooting will be much harder.

I wouldn't want to be bothering you, but even exaggerated what you instructed me to do, and left the sketch as in the attached image, considering I would be using only cases 1, 2, and 3;

Even so, the sketch remains large:

Global variables use 1104 bytes (53%) of dynamic memory, leaving 944 bytes for local variables. The maximum is 2048 bytes.

My suggestion: What do you think about excluding the functions of the 3 buttons?

You have to do this:

=======
Look in the diagnostic output after doing a "verify" operation for the phrase "Linking everything together..." and post ALL the output that appears below it. This will include the flash memory usage (program storage space). Do this with both your original sketch and the new one.

The problem is not global variables (RAM) , it program storage space (flash memory). I need this information to decide how to progress.

OK!

Original sketch:

Linking everything together...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711/Digital_Clock_MAX7219_DS1307RTC_3button.ino.elf" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711\sketch\Digital_Clock_MAX7219_DS1307RTC_3button.ino.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711\libraries\MD_Parola\MD_PZone.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711\libraries\MD_Parola\MD_Parola.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711\libraries\MD_Parola\MD_Parola_Blinds.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711\libraries\MD_Parola\MD_Parola_Close.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711\libraries\MD_Parola\MD_Parola_Diag.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711\libraries\MD_Parola\MD_Parola_Dissolve.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711\libraries\MD_Parola\MD_Parola_Fade.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711\libraries\MD_Parola\MD_Parola_Grow.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711\libraries\MD_Parola\MD_Parola_HScroll.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711\libraries\MD_Parola\MD_Parola_Mesh.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711\libraries\MD_Parola\MD_Parola_Open.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711\libraries\MD_Parola\MD_Parola_Print.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711\libraries\MD_Parola\MD_Parola_Random.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711\libraries\MD_Parola\MD_Parola_Scan.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711\libraries\MD_Parola\MD_Parola_Slice.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711\libraries\MD_Parola\MD_Parola_Sprite.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711\libraries\MD_Parola\MD_Parola_VScroll.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711\libraries\MD_Parola\MD_Parola_Wipe.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711\libraries\MD_MAX72XX\MD_MAX72xx.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711\libraries\MD_MAX72XX\MD_MAX72xx_buf.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711\libraries\MD_MAX72XX\MD_MAX72xx_font.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711\libraries\MD_MAX72XX\MD_MAX72xx_pix.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711\libraries\SPI\SPI.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711\libraries\Wire\Wire.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711\libraries\Wire\utility\twi.c.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711\libraries\MD_DS1307\MD_DS1307.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711/core\core.a" "-LC:\Users\Daniel\AppData\Local\Temp\arduino_build_997711" -lm
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-objcopy" -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711/Digital_Clock_MAX7219_DS1307RTC_3button.ino.elf" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711/Digital_Clock_MAX7219_DS1307RTC_3button.ino.eep"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-objcopy" -O ihex -R .eeprom "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711/Digital_Clock_MAX7219_DS1307RTC_3button.ino.elf" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711/Digital_Clock_MAX7219_DS1307RTC_3button.ino.hex"
Usando a biblioteca MD_Parola na versão 3.0.2 na pasta: C:\Users\Daniel\Documents\Arduino\libraries\MD_Parola
Usando a biblioteca MD_MAX72XX na versão 3.2.1 na pasta: C:\Users\Daniel\Documents\Arduino\libraries\MD_MAX72XX
Usando a biblioteca SPI na versão 1.0 na pasta: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI
Usando a biblioteca Wire na versão 1.0 na pasta: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire
Usando a biblioteca MD_DS1307 na versão 1.3.5 na pasta: C:\Users\Daniel\Documents\Arduino\libraries\MD_DS1307
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-size" -A "C:\Users\Daniel\AppData\Local\Temp\arduino_build_997711/Digital_Clock_MAX7219_DS1307RTC_3button.ino.elf"

The sketch uses 28990 bytes (89%) of program storage space. The maximum is 32256 bytes.

Global variables use 696 bytes (33%) of dynamic memory, leaving 1352 bytes for local variables. The maximum is 2048 bytes.

New sketch:

Linking everything together...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224/Digital_Clock_MAX7219_DS1307RTC_3button_V0_02.ino.elf" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\sketch\Digital_Clock_MAX7219_DS1307RTC_3button_V0_02.ino.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\MD_Parola\MD_PZone.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\MD_Parola\MD_Parola.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\MD_Parola\MD_Parola_Blinds.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\MD_Parola\MD_Parola_Close.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\MD_Parola\MD_Parola_Diag.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\MD_Parola\MD_Parola_Dissolve.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\MD_Parola\MD_Parola_Fade.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\MD_Parola\MD_Parola_Grow.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\MD_Parola\MD_Parola_HScroll.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\MD_Parola\MD_Parola_Mesh.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\MD_Parola\MD_Parola_Open.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\MD_Parola\MD_Parola_Print.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\MD_Parola\MD_Parola_Random.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\MD_Parola\MD_Parola_Scan.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\MD_Parola\MD_Parola_Slice.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\MD_Parola\MD_Parola_Sprite.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\MD_Parola\MD_Parola_VScroll.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\MD_Parola\MD_Parola_Wipe.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\MD_MAX72XX\MD_MAX72xx.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\MD_MAX72XX\MD_MAX72xx_buf.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\MD_MAX72XX\MD_MAX72xx_font.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\MD_MAX72XX\MD_MAX72xx_pix.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\SPI\SPI.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\Wire\Wire.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\Wire\utility\twi.c.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\MD_DS1307\MD_DS1307.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\IRremote\IRremote.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\IRremote\esp32.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\IRremote\irPronto.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\IRremote\irRecv.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\IRremote\irSend.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\IRremote\ir_Aiwa.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\IRremote\ir_Denon.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\IRremote\ir_Dish.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\IRremote\ir_JVC.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\IRremote\ir_LG.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\IRremote\ir_Lego_PF.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\IRremote\ir_Mitsubishi.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\IRremote\ir_NEC.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\IRremote\ir_Panasonic.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\IRremote\ir_RC5_RC6.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\IRremote\ir_Samsung.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\IRremote\ir_Sanyo.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\IRremote\ir_Sharp.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\IRremote\ir_Sony.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\IRremote\ir_Template.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\IRremote\ir_Whynter.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224\libraries\IRremote\sam.cpp.o" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224/core\core.a" "-LC:\Users\Daniel\AppData\Local\Temp\arduino_build_69224" -lm
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-objcopy" -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224/Digital_Clock_MAX7219_DS1307RTC_3button_V0_02.ino.elf" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224/Digital_Clock_MAX7219_DS1307RTC_3button_V0_02.ino.eep"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-objcopy" -O ihex -R .eeprom "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224/Digital_Clock_MAX7219_DS1307RTC_3button_V0_02.ino.elf" "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224/Digital_Clock_MAX7219_DS1307RTC_3button_V0_02.ino.hex"
Usando a biblioteca MD_Parola na versão 3.0.2 na pasta: C:\Users\Daniel\Documents\Arduino\libraries\MD_Parola
Usando a biblioteca MD_MAX72XX na versão 3.2.1 na pasta: C:\Users\Daniel\Documents\Arduino\libraries\MD_MAX72XX
Usando a biblioteca SPI na versão 1.0 na pasta: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI
Usando a biblioteca Wire na versão 1.0 na pasta: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire
Usando a biblioteca MD_DS1307 na versão 1.3.5 na pasta: C:\Users\Daniel\Documents\Arduino\libraries\MD_DS1307
Usando a biblioteca IRremote na versão 2.2.3 na pasta: C:\Users\Daniel\Documents\Arduino\libraries\IRremote
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-size" -A "C:\Users\Daniel\AppData\Local\Temp\arduino_build_69224/Digital_Clock_MAX7219_DS1307RTC_3button_V0_02.ino.elf"

The sketch uses 36178 bytes (112%) of program storage space. The maximum is 32256 bytes.

Global variables use 1104 bytes (53%) of dynamic memory, leaving 944 bytes for local variables. The maximum is 2048 bytes.

Sketch too large; See http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on how to reduce it.

  • I had to send in two parts because it exceeded the limit.

Try disabling all unnecessary protocols in IRremote.h and recompile.

@ arduarn - Greetings

I disabled all protocols, as you said, leaving only the NEC protocol;

It worked, but only with the Uno card; on arduino Nano 328 still shows that the sketch is very large; I found this strange because the processor on both boards is ATmega328p.

I would like to use it on the Nano board because, besides being much smaller (taking up less space), it is cheaper too.

Thank you very much for the valuable and excellent tip!

@ 6v6gt

You friend, who did the great job of adding the Remote Control function to the sketch, was a gift you gave me in advance (my birthday on 28 Jan 2020); my thank you very much.

I will try more often to see if you record on Arduino Nano; If not, can I talk to you again?

Hugs to you friends!

PS. Sorry for the spelling mistakes, because English is not my native language (I'm from Brazil).

Ok. So it all works perfectly on the uno and you can use the IR to control the clock exactly as with the buttons on the clock? If so, that is good news.

The problem with Nano is likely to be that it has an old bootloader on it which uses a large amount of flash memory. The uno (and some newer Nanos ) use optiboot which is 500 bytes. The older one uses 2kB.

You can use your uno to burn the uno (optiboot) bootloader on to the Nano. Google for a tutorial.

Incidentally, it was this line in your listing which shows the flash memory usage:
The sketch uses 36178 bytes (112%) of program storage space. The maximum is 32256 bytes.

Do you mean Bootloader?

Because I recorded Uno's Bootloader on Nano but still says that the sketch is too big.

If not, can you give me a link on how to do it?

Thank you

MiniCore
ArduinoISP

Thank you arduarn

I did the procedure but keep saying that the sketch is too big (with Uno bootloader on Nano);

I probably have to use the Uno board, although it is much larger and makes it difficult to accommodate the components.

Dancopy:
I did the procedure but keep saying that the sketch is too big (with Uno bootloader on Nano);

Not sure what you mean by Uno bootloader on the Nano. Did you install the MiniCore package in the boards manager as described in the MiniCore readme? Did you follow the other instructions?
Also, you need to be specific when describing what you are doing and what the results are. Instead of just posting that the sketch is still too big you need to post the actual build output of the statistics, as requested in previous posts.

And once you have installed the uno bootloader (optiboot) on the Nano, what board type did you select before attempting to load a sketch onto the “Nano” ? The Nano is now effectively a uno.

@arduarn: what was the reason for asking the OP in addition to migrate to the mincore ?