Can't get this example code to work

It may be out of date?
can anyone correct it to work?
(taken from [ https://dronebotworkshop.com/using-ir-remote-controls-with-arduino/]( https://dronebotworkshop.com/using-ir-remote-controls-with-arduino/)

I get...
The function decode(&results)) is deprecated and may not work as expected! Just use decode() without a parameter and IrReceiver.decodedIRData. .

I'm just starting with Arduino,

> [code]
> #include <IRremote.hpp>
> 
> /*
>   IR Receiver Demonstration 1
>   IR-Rcv-Demo1.ino
>   Demonstrates IR codes with IR Receiver
>   Displays results on Serial Monitor
> 
>   DroneBot Workshop 2017
>   http://dronebotworkshop.com
> */
> 
> // Include IR Remote Library by Ken Shirriff
> #include <IRremote.h>
> 
> // Define sensor pin
> const int RECV_PIN = 4;
> 
> // Define IR Receiver and Results Objects
> IRrecv irrecv(RECV_PIN);
> decode_results results;
> 
> 
> void setup(){
>   // Serial Monitor @ 9600 baud
>   Serial.begin(9600);
>   // Enable the IR Receiver
>   irrecv.enableIRIn();
> }
> 
> void loop(){
>   if (irrecv.decode(&results)){
>     // Print Code in HEX
>         Serial.println(results.value, HEX);
>         irrecv.resume();
>   }
> }
> 
> [/code]

What does it do now that you call not working?

a7

I get ...

The function decode(&results)) is deprecated and may not work as expected! Just use decode() without a parameter and IrReceiver.decodedIRData. .

from the serial monitor.
I was hoping for some hex codes.

See: Converting your 2.x program to the 3.x version

That warning is telling you that you are using old code with the new version of the IRremote library. The IRremote GitHub page tells you how to modify older code to work with the new library.

Use the examples from the new library to learn how the new version works.

1 Like

I will have to look at that.
But so many questions. i.e. .h / .hpp

As I am very new (week) to all of this I was hoping someone would take pity on me and rewrite the code correctly.
Converting the code looks daunting to me at the moment.

The context is.. I'm hoping to reprogram an old remote control to make a kind of "busy box", (grandson) as he seems fixated with remotes at the minute.
So this code was to extract the codes from the remote.

I always heard "people lose interest when things fail". I think that can be true.
Oh, and I am 73, so not as sharp as once was :unamused:

Example code:

#include <IRremote.h>

const byte IR_RECEIVE_PIN = 4;

void setup()
{
   Serial.begin(115200);

   Serial.println("IR receive test");
   IrReceiver.begin(IR_RECEIVE_PIN);
}

void loop()
{
   if (IrReceiver.decode())
   {
      //ignore repeats
      if ((IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT))
      {
         IrReceiver.resume();
         return;
      }      
      unsigned long keycode = IrReceiver.decodedIRData.command;      
      Serial.print("command = ");
      Serial.println(keycode);
      Serial.print("address = ");
      Serial.println(IrReceiver.decodedIRData.address);
      Serial.print("raw data = ");
      Serial.println(IrReceiver.decodedIRData.decodedRawData);
      Serial.println();
      
      IrReceiver.resume();
   }
}
1 Like

I am 72 and find that to be true as well.

What do you want the "busy box" to do?

I am willing to give you a hand if you can describe what you want to do.

Please post photos of the remote and your wiring.

1 Like

Made a button box (busy box) a while back, this was the front panel.

Kids love it.

1 Like

I bet. I want one.

Does it deliver an electric shock non-lethal of course for errors on the slides wire thing?

a7

Never thought of that, will include in version 2 :cloud_with_lightning: .

Thanks to everyone who has contributed so far.
I will reply to unanswered posts tomorrow.
:zzz::zzz::zzz:

groundFungus, Thank you for that code.
Unfortunately, it's not working correctly here.

When I press a button on the remote, I get…
4⸮R⸮e, or this for multiple presses on the same button...
⸮5⸮⸮q尥P⸮⸮R⸮eҚ⸮⸮u⸮R⸮⸮R⸮⸮C⸮

The only thing I could think of to do, was to change the baud rate to 9600.
This gave me a different output…
IR receive test
command = 0
address = 0
raw data = 0

command = 0
address = 0
raw data = 0

command = 0
address = 0
raw data = 0

I obviously don't know what to do next.

Please post photos of the remote and your wiring.
No wiring yet, I am just at this stage of attempting to extract the button codes from the remote.

(I have tried two totally different types of remote controls)
(and I will take you up on the offer of help regarding the box, a little further down the line)

Absolutely brilliant.
So do I.

Are The full construction details available anywhere?

This looks like at least version 3 of what I have got in mind.
The one I am hoping to make currently (V1) will just have grandson using the remote control to get reactions from the box. (No point in putting the steady hand item for example, in at this stage, he would just drag it around the room :grinning: :hammer:)

So you changed the Serial baud rate in the code to match serial monitor?

What are the remotes for (TV, DVD, AC, ... )?

It is really difficult to troubleshoot when I do not know what you have or how it is connected.

How have you wired this up?

Operation: point remote at card, press a button.

image|374x500
This is my setup ATM.

arduino IDE (computer) to Uno to little IR Card
2 remotes also shown

Hope this helps.

Can you please confirm that this is an IR remote and not an RF remote? Many small ones that look like this actually work on RF.

It looks to me like you have an IR emitter/sensor pair to use for object detection. Post some more photos of the IR sensor and we can be sure. That sensor will not work to receive and decode IR remote signals](IR Remote Signals | IR Sensor | Adafruit Learning System).

You will need to acquire an IR receiver.. The receiver will recognize only the signal modulated at a certain carrier frequency (38KHz - 40KHz popular) and strip the data from the carrier.

I have gotten this, hope it's correct,
image

It's producing this...(3 keypresses - same key)

command = 0
address = 0
raw data = 1792785869

command = 0
address = 0
raw data = 3289110549

command = 0
address = 0
raw data = 1236334118

command = 0
address = 0
raw data = 1776008254

command = 0
address = 0
raw data = 1253111733

command = 0
address = 0
raw data = 3268227023

A couple of observations, different results and double output.

Are we winning? :confused: