BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

[SOLVED] Blynk + IR SAMSUNG TV Remote Power ON/OFF

Library Used

Hi Blynkers, who knows a thing or 2 about Blynk + IR TV codes. My aim is to blynk the samsung code to switch tv on.
Because the same code is for on and off being the power button, i need to send just one pulse. The good news is
that the below code works and indeed powers on the TV with an IR Led connected via a NODEMCU V3 board.
Unfortuanately things go downhill from now on, i have zero control with the Blynk app but i learned that by pressing the RESET
button on the NODEMCU it pulsed again which powered the TV off, as you can gather this is hardly a workable solution.
In light of the below actually working, can someone please add and correct my code so i can Blynk the code on and off using
virtual pins in the blynk app, i have read almost everything on ir control with ESP8266 and could only find one snippet on blynk which did not work for me.

/*
 * IRremoteESP8266: IRsendGCDemo - demonstrates sending Global Cache-formatted IR codes with IRsend
 * An IR LED must be connected to ESP8266 pin 0.
 * Version 0.1 30 March, 2016
 * Based on Ken Shirriff's IrsendDemo Version 0.1 July, 2009, Copyright 2009 Ken Shirriff, http://arcfn.com
 */

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <IRremoteESP8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "********************************";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "**********";
char pass[] = "**********";
char server[] = "************";

// Codes are in Global Cache format less the emitter ID and request ID. These codes can be found in GC's Control Tower database.

unsigned int Samsung_power_toggle[71] = {38000,1,1,170,170,20,63,20,63,20,63,20,20,20,20,20,20,20,20,20,20,20,63,20,63,20,63,20,20,20,20,20,20,20,20,20,20,20,20,20,63,20,20,20,20,20,20,20,20,20,20,20,20,20,63,20,20,20,63,20,63,20,63,20,63,20,63,20,63,20,1798};

IRsend irsend(4); //an IR emitter led is connected to GPIO pin 4 (D2)
void setup()
{
  irsend.begin();
  irsend.sendGC(Samsung_power_toggle, 71);
  Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY);
  Blynk.begin(auth, ssid, pass, server);
  
}

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

Please remember to properly format your code. I’ve done it for you this time, go to edit mode to see how it has been done.

remove this line of code from setup().

Add a button to V1 and set the button to PUSH mode.
Then add this code, it can be anywhere but for clarity let’s say between setup() and loop():

BLYNK_WRITE(V1){
  int onoff = param.asInt();
  if(onoff == 1){
    irsend.sendGC(Samsung_power_toggle, 71);
 }
}

thanks costas, i revised as per your instructions, it failed compiling with the below error.

Build options changed, rebuilding all
Archiving built core (caching) in: C:\Users**********AppData\Local\Temp\arduino_cache_134441\core\core_esp8266_esp8266_nodemcuv2_CpuFrequency_80,UploadSpeed_115200,FlashSize_4M3M_c6b3beadbdb815653dd719e7ec783133.a
libraries\Blynk\utility\BlynkHandlers.cpp.o: In function `GetWriteHandler’:

C:\Program Files\Arduino\libraries\Blynk\src\utility/BlynkHandlers.cpp:23: multiple definition of `BlynkWidgetWrite’

sketch\BLYNKSAMSUNGTVcostos.ino.cpp.o:C:\Program Files\Arduino\libraries\Blynk\src/Blynk/BlynkParam.h:68: first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).

This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.

I missed the V1 from the BLYNK_WRITE() function, see revised sketch.

where is the revised sketch costas?

Should have said see revised code, not sketch. Look above for BLYNK_WRITE(V1).

the V1 was in your original code

am i missing the point sorry

No it wasn’t. If you look at the post you can see the different versions of my post. Original was just () without V1.

Post your latest sketch with my button code and I’ll tell you what you are doing wrong.

sorry yeah i see what you mean now, i didn’t realize that you had edited your original reply, i was looking for a new code entry, it just compiled, any thanks costas, will test in next hour, i will let you know if it works and then will share my whole project for others to try.

1 Like

yessssssssss it worked, thanks costas, i’m just starting to share the project to which i will accredit to you. Many thanks

@Costas Costas solved this issue and here is everything you need to create a blynk app to turn ON/OFF your SAMSUNG TV’

Download IRremoteESP8266master Library from Github:-
[IRremoteESP8266

Here is the finished working Code

/*
  • IR](https://github.com/markszabo/IRremoteESP8266)remoteESP8266: IRsendGCDemo - demonstrates sending Global Cache-formatted IR codes with IRsend

  • An IR LED must be connected to ESP8266 pin 0.

  • Version 0.1 30 March, 2016

  • Based on Ken Shirriff’s IrsendDemo Version 0.1 July, 2009, Copyright 2009 Ken Shirriff, http://arcfn.com
    */

    #include <ESP8266WiFi.h>
    #include <BlynkSimpleEsp8266.h>
    #include <IRremoteESP8266.h>

    // You should get Auth Token in the Blynk App.
    // Go to the Project Settings (nut icon).
    char auth[] = “********************************”;

    // Your WiFi credentials.
    // Set password to “” for open networks.
    char ssid[] = “";
    char pass[] = "
    ”;
    char server[] = “************”;

    // Codes are in Global Cache format less the emitter ID and request ID. These codes can be found in GC’s Control Tower database.

    unsigned int Samsung_power_toggle[71] = {38000,1,1,170,170,20,63,20,63,20,63,20,20,20,20,20,20,20,20,20,20,20,63,20,63,20,63,20,20,20,20,20,20,20,20,20,20,20,20,20,63,20,20,20,20,20,20,20,20,20,20,20,20,20,63,20,20,20,63,20,63,20,63,20,63,20,63,20,63,20,1798};

    IRsend irsend(4); //an IR emitter led is connected to GPIO pin 4 (D2)
    void setup()
    {
    irsend.begin();
    Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY);
    Blynk.begin(auth, ssid, pass, server);
    // You can also specify server:
    //Blynk.begin(auth, ssid, pass, “blynk-cloud.com”, 8442);
    //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
    }
    BLYNK_WRITE(V1){
    int onoff = param.asInt();
    if(onoff == 1){
    irsend.sendGC(Samsung_power_toggle, 71);
    }
    }
    void loop() {
    Blynk.run();

    }
    }

Here is the QR Code for the simple PUSH button, (must be set to PUSH and not SWITCH

Hardware side:- I used a NODEMCU IR led connected to D2

OBVIOUSLY the IR LED must be pointing at the TV to work.

1 Like

Sory… i get this…
“error: ‘IRsend’ does not name a type”
I have all libraries installed…and just copy/paste the code from jasperdogJun

add the following 2 lines at the start, i will amend the code to reflect it above ok.

#include <IRsend.h>  // Needed if you want to send IR commands.
#include <IRrecv.h>  // Needed if you want to receive IR commands.

here is the revised code due to the IR library being amended some time ago.

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>  // Needed if you want to send IR commands.
#include <IRrecv.h>  // Needed if you want to receive IR commands.



// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "********************************";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "**********";
char pass[] = "**********";
char server[] = "************";

// Codes are in Global Cache format less the emitter ID and request ID. These codes can be found in GC's Control Tower database.

unsigned int Samsung_power_toggle[71] = {38000,1,1,170,170,20,63,20,63,20,63,20,20,20,20,20,20,20,20,20,20,20,63,20,63,20,63,20,20,20,20,20,20,20,20,20,20,20,20,20,63,20,20,20,20,20,20,20,20,20,20,20,20,20,63,20,20,20,63,20,63,20,63,20,63,20,63,20,63,20,1798};

IRsend irsend(4); //an IR emitter led is connected to GPIO pin 4 (D2)
void setup()
{
  irsend.begin();
  Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY);
  Blynk.begin(auth, ssid, pass, server);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
}
BLYNK_WRITE(V1){
  int onoff = param.asInt();
  if(onoff == 1){
    irsend.sendGC(Samsung_power_toggle, 71);
 }
}
    void loop() {
     Blynk.run();
  
}

not working… sorry…

C:\Users\Juanjo\Documents\Arduino\sketch_jun30e\sketch_jun30e.ino: In function 'void BlynkWidgetWrite1(BlynkReq&, const BlynkParam&)':

sketch_jun30e:34: error: no matching function for call to 'IRsend::sendGC(unsigned int [71], int)'

     irsend.sendGC(Samsung_power_toggle, 71);

                                           ^

C:\Users\Juanjo\Documents\Arduino\sketch_jun30e\sketch_jun30e.ino:34:43: note: candidate is:

In file included from C:\Users\Juanjo\Documents\Arduino\sketch_jun30e\sketch_jun30e.ino:4:0:

C:\Users\Juanjo\Documents\Arduino\libraries\IRremoteESP8266\src/IRsend.h:181:8: note: void IRsend::sendGC(uint16_t*, uint16_t)

   void sendGC(uint16_t buf[], uint16_t len);

        ^

C:\Users\Juanjo\Documents\Arduino\libraries\IRremoteESP8266\src/IRsend.h:181:8: note:   no known conversion for argument 1 from 'unsigned int [71]' to 'uint16_t* {aka short unsigned int*}'

C:\Users\Juanjo\Documents\Arduino\sketch_jun30e\sketch_jun30e.ino: At global scope:

sketch_jun30e:41: error: expected declaration before '}' token

 }

 ^

exit status 1
no matching function for call to 'IRsend::sendGC(unsigned int [71], int)'

i don’t know, it works perfectly for me as per the code.

OK, thanks anyway…i will keep trying!

i remember using a different approach to this, i’ll try and find my sketch and post it for you to try.

1 Like