Emulate an Arduino remote control & send WiFi signals to an IR transceiver

Hey Blynkers! My project is to have a Blynk ESP8266 WiFi Project remote control on my iPhone with 17 widgets (for 0-9, “*”, “#”, Left, Right, Up, Down and OK) to emulate a NEC InfaRed Remote Control used with an Arduino. When you depress any widget key on the App, it would send a canned IR control string in ASCII (like 0xffeff, 0xfbcde, etc.) via WiFi to an Arduino UNO running with an ESP8266 as a WiFi to IR translator, which I already have working beforehand for BlueTooth. When any of the widget keys are pressed, Blynk will send the pre-recorded IR control string to the transceiver, which will convert it into IR signals to be sent out via an IR transmitter to the receiving device. I see lots of Blynk widgets for buttons, sliders, temp display, and more, but none that can be configured to send out ASCII IR control strings to a receiving device. BlueTooth has limited distance, so I want to switch to WiFi. Any ideas which of the Blynk widgets can be configured to send IR hex control strings?
Thanks for looking.

This is the NEC Arduino Remote Control I want to emulate as a Blynk App:

You’re approaching this from the wrong angle.
The way to do it is to use Button widgets, set to Push mode and each connected to a different virtual pin.
The button will send a “1” when pressed and a “0” when released by default, and there’s no need to change this default behaviour.

The code running on the MCU will include a BLYNK_WRITE(Vpin) callback for each button widget. You will only want to take action when the button is pressed (not released) so you’ll start by only proceeding if the received value is a “1”.
At that point you can take whatever action you want, such as calling a function with a parameter which sends the specified IR code.

There are quite a few projects around where this has already been done. Here is one:

I’ve not studied the code in this example, and as it was written by a newcomer it may well have some serious flaws, but doing more searches will probably deliver something you can work with.

Pete.

1 Like

Thanks, Pete, I’ll take a look. I already have everything working on BlueTooth using the iPhone Tatco “Arduino IR Kit” App from them, but I want to try a new App like Blynk for the WiFi phase.
Cheers,
Mike

Here is the Blynk layout for my virtual remote control - all the keys on the original one plus some test push-buttons. For a full-sized layout like this you can’t take a full-sized screen snapshot off an iPhone without getting the top button row chopped.

Update: Project completed, @Pavel. How can I get a full-screen App snapshot of my Blynk RC layout without the Project status bar at the top of the screen chopping off the first row of keys?

Adafruit also has a great writeup on sending and receiving IR codes;
it has project details and complete code sketches.

So I built these two WiFi-to-IR prototypes, one based on the ESP-01 chip and the other on a NodeMCU. I wrote a sketch, uploaded it into both of them, and also uploaded the Blynk “Push Data” sketch. Like Alice who stumbled into the rabbit hole, I quickly realized I was in for an adventurous ride. I could only enable one key on my Blynk virtual remote control (see above post). As soon as I enabled more, I encountered the dreaded “Cmd error” message after putting the 8266 into verbose debugging mode to read all the messaging from the UNO to the 8266. The Blynk Cloud WiFi connection was broken !

09:35:31.746 -> BlynkIR V1.0 1/12/20
09:35:31.781 -> [10] 
09:35:31.781 ->     ___  __          __
09:35:31.814 ->    / _ )/ /_ _____  / /__
09:35:31.848 ->   / _  / / // / _ \/  '_/
09:35:31.848 ->  /____/_/\_, /_//_/_/\_\
09:35:31.883 ->         /___/ v0.6.1 on Arduino Uno
09:35:31.918 -> 
09:35:32.359 -> [612] Connecting to MyHomeRouter
09:35:35.585 -> [3826] AT version:1.3.0.0(Jul 14 2016 18:54:01)
09:35:35.619 -> SDK version:2.0.0(5a875ba)
09:35:35.653 -> Farylink Technology Co., Ltd. v1.0.0.2
09:35:35.687 -> May 11 2017 22:23:58
09:35:35.721 -> OK
09:35:40.883 -> [9139] +CIFSR:STAIP,"192.168.1.67"
09:35:40.916 -> +CIFSR:STAMAC,"84:f3:eb:dd"
09:35:40.950 -> [9146] Connected to WiFi
09:35:51.160 -> [19417] <[1D|00|01|00] _tN
09:35:51.397 -> [19657] >[00|00|01|00|C8]
09:35:51.432 -> [19657] Ready (ping: 54ms).
09:35:51.465 -> [19658] Free RAM: 566
09:35:51.499 -> [19682] >[14|00|01|00|16]
09:35:51.499 -> [19700] >pm[00]14[00]out[00]15[00]out[00]4[00]out
09:35:51.566 -> [19762] <[11|00|02|00]fver[00]0.6.1[00]h-beat[00]10[00]buff-in[00]256[00]dev
09:36:01.669 -> [29922] Cmd error **<<<<<<<<=======  <<<<<=====  <<<<<=====**

It seems to happen right after the keep-alive “heartbeat” to keep the WiFi connection up. Back off to just one RC key defined in the sketch, and there is no performance error. Mind you, I’m running this as a sketch inside the UNO. Others ahead of me have to compiled the code to run in native mode inside the 8266 WiFi chip. I hope that is not my only choice. Heading the advice of others, I downloaded the latest libraries, the latest IDE, kept my VOID loop to only two statements: Blynk.run() and timer.run().
I am using these three libraries:
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h> and
#include <IRremote.h>
I know the IDE will indicate low memory when the RAM memory is below 500; I’m at 566. My sketch uses only 19,568 bytes, which is 60% of the available. I will continue testing and the discovery process.
Those plastic sleds the Arduinos are shipped in make great breadboard bases, right?

The NodeMCU on its own, without the Uno, is by far the better solution. The NodeMCU is far more powerful than the Uno and using it as an AT Wi-Fi modem for the Uno is a bit like using a cart horse to tow a Ferrari.
Read this for more info:

I use a Wemos D1Mini with a couple of IR LEDs connected to control my aircon and fans. I don’t even bother with the resistors, so have just 3 wires plus the power connection.

You could probably do the same with the ESP-01, but I prefer the convenience of a dev board with an onboard debut port.

The issues you are facing with your current setup may be caused by the communication speed with the ESPs via SoftwareSerial, or poor coding, but without seeing your code it’s difficult to say.

Using breadboards for long-term projects isn’t the way to go. They are notoriously bad at maintaining good connections over time and tracking down the fault is a case of wiggling wires to figure-out where the dodgy contact is - not good for your sanity!
As I said earlier, you only really need two wires to drive your LED, plus an in-line resistor if that’s the way you want to go (the resistor value will be lower when using the ESP’s GPIO pins, as they operate on 3.3v logic levels rather than the 5v used by the Arduino).

Pete.

These WiFi breadboards are just temporary test stations. All my finished units get PCB’s I design using Autodesk Eagle and uploaded to JLCPCB, and a crystal project case.
Serial baud-rate anomalies? Yes, like many others, I had problems running at 115,200 baud on both units (garbled characters in the serial monitor), so I re-flashed them to 9600 baud.
Problem not solved, just eliminated.
Finally, NodeMCU vs. UNO - Your point taken, I will recompile and move my code into the Node out of the UNO and go from there. I was able to run my BlueTooth Remote Control inside the UNO without any problems, but it does look like in order to use Blynk I will have to move it. I’m way past the “Hello World” (watch the LED flash) milestone a year ago.


Ah! A clue! More breadcrumbs down the rabbit hole to digest …
I’m getting the same heartbeat block message followed by the “Cmd error”.
Thanks, @Jamin.


Finally reached the end of the tunnel. All is working as I envisioned. My RC sketch is running inside the Arduino Uno, all 20 virtual Blynk keys on my iPhone App are being processed, and I got rid of the “cmd error” timeout problem. Threading thru all the Blynk postings and seeing what others who approached the problem did, I made the following very simple changes:

  1. Added these three statements to my Sketch:
    #define BLYNK_DEBUG
    #define BLYNK_HEARTBEAT 30
    #define BLYNK_NO_FLOAT
    (Verbose) Debug mode allowed me to see all the messaging to and from the Blynk Cloud Server. “Heartbeat 30” changes the timeout from 10 seconds to 30 seconds. The “No Float” statement saves code-space internally; I have no way to accurately measure.
  2. The final fix that made it totally work was to remove all Serial.println calls inside each Blynk.Write() subroutine, and remove all Delay() statements that were unnecessary. This allowed me to jump from enabling just 4 Blynk RC keys to enabling all of them without the “cmd error” timeout. My goal was to get this working (part-time) by the end of the month; I did it in 15 days. I still intend to recompile the sketch so it will run in native mode inside the NodeMCU. This picture shows a working WiFi-to-IR breadboard on the left and a pseudo IR remote control receiver on the right. Each time it receives a new valid NEC code, the plastic sled base glows a new color.

If you’re still struggling with available memory (you can tell this when you compile the code, it tells you at the end) then you can use the so-called “F Macro” with your serial print statements.
Serial.println(“Hello World”);
Would become:
Serial.println(F(“Hello World”));

This only works with string literals, not variables, and it saves a small amount of memory each time - although will stop being an issue when you swap to the NodeMCU.

Pete.

Hey, thanks, Pete. Every byte helps ……

OK, Pete, this looks to be a good article on flashing the ESP-01, now that I have a working sketch that runs in the Arduino UNO. Do you have a better starting point?

https://www.diyhobi.com/flash-program-esp-01-using-usb-serial-adapter/

To be honest, I’d start with using a NodeMCU as your replacement for the Arduino/ESP-01 combination.
The reason being that the NodeMCU has a built-in TTL to Serial adaptor, which is easy to access via the onboard USB connector, and it has lots of useable GPIO pins. It’s also much easier to flash, as you don’t have to mess around manually putting it onto flash mode by pulling GPIO0 low.

The ESP-01 on the other hand is trickier to use as it has no TTL to serial adaptor, limited GPIOs and is more difficult to flash. The adaptors shown in the article you linked solve some of these issues, but not the limited GPIOs.
If you work with the NodeMCU first then getting it working will be much easier, and you’ll have good access to the serial debug data. If you then want to do the same thing with the ESP-01 the what you’ve learned with the NodeMCU will be helpful and make your life easier.

You should also read this:

Pete.

2 Likes

2020-01-19_15-56-07%20IRsend%20type%20error

Next brain-teaser: I tried compiling the Ellis “All remotes from your Smartphone” example mentioned above just to see what it would say on my IDE. Looks like I have some library conflicts between the Uno & ESP8266 module libraries resulting in this error: “IRsend does not name a type”. The Internet has hundreds of opinions and comments about this error. I’m going to have to fix the library conflict. Compiling for the UNO, this was not a problem when <IRremote.h> was used, but for the 8266 environment, <IRremoteESP8266.h> there seems to be something missing. Some people say going to go back to a previous IDE 1.0.6, others say it’s a conflict between C++ and C coded routines, and a few say to delete misbehaving “RobotIRRemote” files.

That is a VERY old version of the IDE and may have been an appropriate fix at the time, but certainly isn’t the solution now.

The first thing is to post your full code, so we can see if you’re doing anything wrong elsewhere.

Secondly, post a link to the exact IRremoteESP8266 library that you installed, as there are multiple flavours that have been hacked/modified by people along the way. It’s always good practice to add a URL to the exact library in your code, along with a note about the version that you successfully used.

What version of the ESP core are you using?

Pete.

This is the Ellis “All your Remotes to Smartphone” sketch you referenced; this is the one as well as my code that gets the IRsend() error when compiling.
Compile it on your IDE and see if you get the same error —

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
// IR remote
#include <IRremoteESP8266.h>

char auth[]   = "yourauthcode";
char ssid[]   = "your wifi network";
char pass[]   = "your wifi password";
char server[] = "blynk-cloud.com";

SimpleTimer testingTimer;

IRsend irsend(0); ///an IR led is connected to GPIO 0 --> D4

// ======= SKETCH IR

int pinValueV1;
int pinValueV4;
int pinValueV5;
unsigned int ScreenUp[63] = {1400, 400, 1400, 400, 1400, 400, 1400, 400, 500, 1200, 500, 1200, 500, 1200, 500, 1200, 500, 1200, 500, 1200, 500, 1200, 1350, 400, 500, 1200, 500, 1200, 500, 1200, 1400, 400, 1400, 400, 1400, 400, 500, 1200, 1350, 400, 1350, 400, 1350, 400, 500, 1200, 1400, 400, 1400, 400, 1400, 400, 500, 1200, 1400, 400, 1400, 400, 1350, 400, 1350, 400, 500};
unsigned int ScreenDown[63] = {1400, 400, 1350, 400, 1400, 400, 1400, 400, 500, 1200, 500, 1200, 500, 1200, 500, 1200, 500, 1200, 1350, 400, 500, 1200, 500, 1200, 500, 1200, 500, 1200, 500, 1200, 1400, 400, 1400, 400, 1400, 400, 1400, 400, 550, 1200, 1350, 400, 1350, 400, 1400, 400, 550, 1200, 500, 1200, 500, 1200, 500, 1200, 1400, 400, 1400, 400, 1400, 400, 1400, 400, 1400};

// ====== DEVICE SELECTOR

void mySetPropertyFunction1notneeded(){
  Blynk.setProperty(V2, "color", "#23C48E"); //GREEN
  Blynk.setProperty(V4, "color", "#23C48E"); //GREEN
  Blynk.setProperty(V5, "color", "#23C48E"); //GREEN
  Blynk.setProperty(V6, "color", "#23C48E"); //GREEN
}
void mySetPropertyFunction1(){
  Blynk.setProperty(V7, "color", "#23C48E"); //GREEN
  Blynk.setProperty(V13, "color", "#23C48E"); //GREEN
  Blynk.setProperty(V14, "color", "#23C48E"); //GREEN
  Blynk.setProperty(V15, "color", "#23C48E"); //GREEN
}

void mySetPropertyFunction2notneeded(){
   Blynk.setProperty(V2, "color", "#D3435C"); //RED POWER
   Blynk.setProperty(V3, "color", "#D3435C"); //RED SOURCE
   Blynk.setProperty(V3, "label", "HOME");
   Blynk.setProperty(V4, "color", "#D3435C"); //RED SOURCE
}
void mySetPropertyFunction2(){
   Blynk.setProperty(V4, "label", "LEFT/RIGHT");
   Blynk.setProperty(V5, "color", "#D3435C"); //RED SOURCE
   Blynk.setProperty(V13, "color", "#D3435C"); //RED SOURCE
   Blynk.setProperty(V15, "color", "#D3435C"); //RED SOURCE
}
 

BLYNK_WRITE(V1) {
  switch (param.asInt())
  {
    case 1:               // Item 1 - TV LIVING
      pinValueV1 = 1;
      Blynk.setProperty(V2, "color", "#23C48E"); //GREEN
      Blynk.setProperty(V4, "color", "#23C48E"); //GREEN
      Blynk.setProperty(V5, "color", "#23C48E"); //GREEN
      Blynk.setProperty(V6, "color", "#23C48E"); //GREEN
       testingTimer.setTimeout(300,mySetPropertyFunction1); // perform the second function 400ms later
      break;

    case 2:               // Item 2 - DVD
      pinValueV1 = 2;
      Blynk.setProperty(V2, "color", "#D3435C"); //RED POWER
      Blynk.setProperty(V3, "color", "#D3435C"); //RED SOURCE
      Blynk.setProperty(V3, "label", "HOME");
      Blynk.setProperty(V4, "color", "#D3435C"); //RED SOURCE
      testingTimer.setTimeout(300,mySetPropertyFunction2); // perform the second function 400ms later 
      break;

    case 3:               // Item 3 - AUX
      pinValueV1 = 3;
      Blynk.setProperty(V2, "color", "#04C0F8"); //BLU
      Blynk.setProperty(V4, "color", "#04C0F8"); //BLU
      delay(1000);
      break;

    case 4:
      pinValueV1 = 4;
      
      break;

    case 5:             // Item 5 - Projector Screen
      pinValueV1 = 5;
      Blynk.setProperty(V15, "color", "#ED9D00"); //YELLOW
      
      break;

  }
}

// ========== END DEVICE SELECTOR


BLYNK_WRITE(V2) // ON/OFF
{
  if ( param.asInt() && pinValueV1 == 1 )  // ON/OFF TV
  { irsend.sendNEC(0xFB38C7, 32);
  } else if ( param.asInt()   && pinValueV1 == 2 ) // ON/OFF DVD
  { irsend.sendSAMSUNG(0xB4B40CF3, 32);
  } else if ( param.asInt()   && pinValueV1 == 3 ) // ON/OFF AUX
  { irsend.sendNEC(0x7E8154AB, 32);
  }
}


BLYNK_WRITE(V3) // SOURCE
{
  if ( param.asInt() && pinValueV1 == 1 )
  { irsend.sendNEC(0xFBE817, 32); //
  } else if ( param.asInt()   && pinValueV1 == 2 ) // SAMSUNG
  { irsend.sendSAMSUNG(0xB4B4E619, 32);
  }
}


BLYNK_WRITE(V4) // AUDIO + / -
{
  pinValueV4 = V4  ;
  if ( param.asInt()  == 4 && pinValueV1 == 1 )
  { irsend.sendNEC(0xFBD22D, 32); // + AUDIO
  } else if ( param.asInt()  == 3 && pinValueV1 == 1 )
  { irsend.sendNEC(0xFBF20D, 32); // - AUDIO
  } else if ( param.asInt()  == 3 && pinValueV1 == 3 )  // AUDIO AUX -
  { irsend.sendNEC(0x5EA1D827, 32); // - AUDIO
  } else if ( param.asInt()  == 3 && pinValueV1 == 3 )  // AUDIO AUX +
  { irsend.sendNEC(0x5EA158A7, 32); // - AUDIO
  } else if ( param.asInt()  == 3 && pinValueV1 == 2 )  // DVD Left
  { irsend.sendSAMSUNG(0xB4B49A65, 32); // - AUDIO
  } else if ( param.asInt()  == 3 && pinValueV1 == 2 )  // DVD Right
  { irsend.sendSAMSUNG(0xB4B45AA5, 32); // - AUDIO
  }
}


BLYNK_WRITE(V5) // CHANNELS + / -
{
  pinValueV5 = V5  ;
  if ( param.asInt()  == 4 && pinValueV1 == 1 )
  { irsend.sendNEC(0xFB906F, 32); // + CH
  } else if ( param.asInt()  == 3 && pinValueV1 == 1 )
  { irsend.sendNEC(0xFBA05F, 32); // - CH
  } else if ( param.asInt()  == 3 && pinValueV1 == 2 )  // DVD CH -
  { irsend.sendSAMSUNG(0xB4B41EE1, 32); // - CH
  } else if ( param.asInt()  == 4 && pinValueV1 == 2 )    // DVD CH +
  { irsend.sendSAMSUNG(0xB4B4EE11, 32); // - CH
  }

}

BLYNK_WRITE(V6) // TXT
{
  if ( param.asInt() && pinValueV1 == 1 )
  { irsend.sendNEC(0xFB807F, 32); //
  } else {
    //LOW - OFF
  }
}

BLYNK_WRITE(V7) // INFO
{
  if ( param.asInt() && pinValueV1 == 2 )
  { irsend.sendNEC(0xFB1AE5, 32); //
  } else {
    //LOW - OFF
  }
}

BLYNK_WRITE(V8) // Rewind
{
  if ( param.asInt() && pinValueV1 == 2 )
  { irsend.sendSAMSUNG(0xB4B44CB3, 32); //
  } else {
    //LOW - OFF
  }
}

BLYNK_WRITE(V9) // Play
{
  if ( param.asInt() && pinValueV1 == 2 )
  { irsend.sendSAMSUNG(0xB4B48C73, 32); //
  } else {
    //LOW - OFF
  }
}

BLYNK_WRITE(V10) // Stop
{
  if ( param.asInt() && pinValueV1 == 2 )
  { irsend.sendSAMSUNG(0xB4B49C63, 32); //
  } else {
    //LOW - OFF
  }
}


BLYNK_WRITE(V11) // Forward
{
  if ( param.asInt() && pinValueV1 == 2 )
  { irsend.sendSAMSUNG(0xB4B44CB3, 32); //
  } else {
    //LOW - OFF
  }
}


BLYNK_WRITE(V12) // Eject
{
  if ( param.asInt() && pinValueV1 == 2 )
  { irsend.sendSAMSUNG(0xB4B46C93, 32); //
  } else {
    //LOW - OFF
  }
}


BLYNK_WRITE(V13) // OK
{
  if ( param.asInt() && pinValueV1 == 1 )
  { irsend.sendNEC(0xFB609F, 32); //
  } else if ( param.asInt()   && pinValueV1 == 2 ) // SAMSUNG
  { irsend.sendSAMSUNG(0xB4B41AE5, 32);
  }
}

BLYNK_WRITE(V14) // KO
{
  if ( param.asInt() && pinValueV1 == 1 )
  { irsend.sendNEC(0xFB50AF, 32); //
  } else {
    // LOW - OFF
  }
}

BLYNK_WRITE(V15) // UP/DOWN-
{
  pinValueV5 = V15  ;
  if ( param.asInt()  == 4 && pinValueV1 == 1 ) //+ CH
  { irsend.sendNEC(0xFB58A7, 32); //
  } else if ( param.asInt()  == 3 && pinValueV1 == 1 ) // - CH
  { irsend.sendNEC(0xFB12ED, 32); //
  } else if ( param.asInt()  == 3 && pinValueV1 == 2 )  // DVD UP
  { irsend.sendSAMSUNG(0xB4B4E21D, 32); //
  } else if ( param.asInt()  == 4 && pinValueV1 == 2 )    // DVD DOWN
  { irsend.sendSAMSUNG(0xB4B412ED, 32); //
  } else if ( param.asInt()  == 3 && pinValueV1 == 5 )    // SCREEN UP
  { irsend.sendRaw(ScreenUp, 63, 32);
  } else if ( param.asInt()  == 4 && pinValueV1 == 5 )    // SCREEN DOWN
  { irsend.sendRaw(ScreenDown, 63, 32);
  }
}

// ========LOOP
void setup()
{
  Serial.begin(115200);
  Serial.println();
  Serial.println(F("Started"));
  irsend.begin();
   Blynk.begin(auth, ssid, pass, server); 
  Blynk.syncAll();
  
}

void loop()
{
  Blynk.run();
  testingTimer.run();
}

Yeah, going back to the old IDE is not an option. And I’m not using any RobotIRRemote files mentioned either. I tried compiling for the Wemos D1 R1 and the generic ESP8266 module; same result. I’m using latest IDE 1.8.10.

What IRremoteESP8266 library do you have installed? Where did you get it from and what version is it?
Did you install it directly from the IDE library manager, or as a .zip file from a GitHub or similar site?

What version of the ESP Core do you have installed?

Pete.

Here is a problem discovered with the bad IR remote files and the fix.
One of the libraries has to be manually replaced:

  1. Some of the headers I have used were installed from folders at GitHub rather than via Library Manager in order to get another project working. I may have to back them out.

  2. Here are my libraries:

Multiple libraries were found for "ESP8266WiFi.h"
 Used: C:\Users\mstod\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266WiFi
Multiple libraries were found for "BlynkSimpleEsp8266.h"
 Used: C:\Users\mstod\Documents\Arduino\libraries\Blynk
Multiple libraries were found for "SimpleTimer.h"
 Used: C:\Users\mstod\Documents\Arduino\libraries\SimpleTimer
Multiple libraries were found for "IRremoteESP8266.h"
 Used: C:\Users\mstod\Documents\Arduino\libraries\IRremoteESP8266
Using library ESP8266WiFi at version 1.0 in folder: C:\Users\mstod\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266WiFi 
Using library Blynk at version 0.6.1 in folder: C:\Users\mstod\Documents\Arduino\libraries\Blynk 
Using library SimpleTimer in folder: C:\Users\mstod\Documents\Arduino\libraries\SimpleTimer (legacy)
Using library IRremoteESP8266 at version 2.7.2 in folder: C:\Users\mstod\Documents\Arduino\libraries\IRremoteESP8266 

Thanks,
Mike