Nodemcu IR signal sending twice

Hey everybody, I’ve come a way in the learning experience with Blynk, utilizing my own server as well. However I am having an issue with my ir blasting.

The ir code is being sent twice apparently, any time I adjust my TV volume or try to open the inputs, it simulates two button presses. I’m using the button widget on the app and BLYNK_WRITE(V100) { irsend.send(NEC, 0x20DF10EF, 32); // LGTV off/on } an excerpt.

I’ve also tried for(int i=0;i<4;i++) in the code as well but it seems to send even more than just two. I tried to add a delay(2000) in the code as well but it only adds time between the two ir transmits. I noticed if I hold the button, it seems to only write once but upon releasing it sends a second write to it.

Does anybody know a little more about this with the IRsend.h lib? I’m excited it works to an extent and its fine for power functions but I’m wanting a little more accuracy.

Let’s see a bit of code at least. Looks like you have the wrong code in the BLYNK_WRITE() functions.

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Servo.h>
#include <Adafruit_Sensor.h>
#include <DHT_U.h>
#include <DHT.h>
#include <Wire.h>
#include <IRsend.h>

#define DHTTYPE DHT11

#define DHTPIN 14


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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "a";
char pass[] = "a";
BlynkTimer timer;
Servo servo;
DHT dht(DHTPIN, DHTTYPE);
IRsend irsend(4);  // An IR LED is controlled by GPIO pin 4 (D2)
BLYNK_WRITE(V3) {
  servo.write(param.asInt());
  timer.setTimeout(2000L, ServoNeutral);  // In two seconds, Run the void ServoNeutral() routine.
}



BLYNK_WRITE(V100)
{
  irsend.send(NEC, 0x20DF10EF, 32); // TV off/on
}

BLYNK_WRITE(V101)
{
  irsend.send(NEC, 0x20DF40BF, 32); // VolUp
}

BLYNK_WRITE(V102)
{
  irsend.send(NEC, 0x20DFC03F, 32); // Vol DWN
}

BLYNK_WRITE(V103)
{
  irsend.send(NEC, 0x20DF906F, 32); // MUTE
}

BLYNK_WRITE(V104)
{
  irsend.send(NEC, 0x20DF00FF, 32); // chup
}

BLYNK_WRITE(V105)
{
  irsend.send(NEC, 0x20DF807F, 32); // chdown
}

BLYNK_WRITE(V106)
{
  irsend.send(NEC, 0x20DFD02F, 32); // input
}

BLYNK_WRITE(V107)
{
  irsend.send(NEC, 0x20DF22DD, 32); // ok
}

BLYNK_WRITE(V108)
{
  irsend.send(NEC, 0x20DF55AA, 32); // exit
}


void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(true);

  if (isnan(h) || isnan(t)) {
    Serial.println("DHT FAILURE");
    return;
  }
  Blynk.virtualWrite(V20, h);
  Blynk.virtualWrite(V21, t);
}

void ServoNeutral() {
  servo.write(60);
}

void setup() {

  Blynk.begin(auth, ssid, pass, IPAddress(10, 0, 0, 2), 8442);
  dht.begin();
  timer.setInterval(1000L, sendSensor);
  servo.attach(15); // 15 means D8 pin of ESP8266
  irsend.begin();

}

void loop()
{
  timer.run();
  Blynk.run(); // You can inject your own code or combine it with other sketches.

}

@HeckHeckBork do you have the buttons in the (wrong) default mode of PUSH?

This will send HIGH and then LOW signal, ergo 2 sequences as per your poor code.

Not:

 BLYNK_WRITE(V100)
{
  irsend.send(NEC, 0x20DF10EF, 32); // TV off/on
}

but:

    BLYNK_WRITE(V100)
    {
      if(param.asInt()){      // when button goes HIGH
         irsend.send(NEC, 0x20DF10EF, 32); // TV off/on
      }
    else{       // when button goes LOW
       // do nothing
     }
   }

Button can then be in either PUSH or SWITCH mode etc.

1 Like