D1 mini control TV

I am using a Wemos D1 mini to control an LG tv via RS232. Code 1 works however code 2 doesn’t work. So, in code 2, i am trying to send the rs232 command when V0 is high but it doesn’t seem to work. Does anyone have a solution?

Code 1:

#include <SoftwareSerial.h>

SoftwareSerial TV_Serial(3, 1); // Arduino RX, Arduino TX

void setup() {
  TV_Serial.begin(9600);  // software serial port

void loop() {
  String cmd = ("ka 01 01");
  TV_Serial.println (cmd);


Code 2:

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SoftwareSerial.h>
SoftwareSerial TV_Serial(3, 1);
BlynkTimer timer;

char auth[] = x

char ssid[] = "IoT";
char pass[] = "x";

void setup()
  // Debug console
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, lg);

void lg(){
  if (V0 == HIGH){
    String cmd = ("ka 01 01");
    TV_Serial.println (cmd);

void loop()

These are a few issues with what you’ve written here, from my point of view at least…

The Blynk library provides a method for automatically triggering a callback function whenever the value of a widget connected to a virtual pin changes. This is the BLYNK_WRITE function.

Within this function, the value that comes from the widget can be captured and assigned to a variable for later use. This is done with the param.asInt, param.asFloat or param.asString command. In the case of a button widget you’d use the param.asInt function.
If you only want to do something when the value received from the widget is 1 then you use a regular if statement for this, with an else tagged on the end if you want to do something different when a 0 is received.
See this recent post for a slight more in-depth explanation…

Also, you’re using the SoftwareSerial library with an ESP based device. This has known issues with all of the recent versions of the ESP core and should be avoided.
There are alternative libraries, called things like ESPSoftwareSerial, but that may not be necessary.
The Wemos D1 Mini has one and a half hardware serial ports onboard. The half a port is transmit only, and if the communication with your TV doesn’t require bi-directional communication then you could use this second Tx only port, which is available on pin D4 and is referenced as Serial1.


Thanks, I got the code to work now.