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

Virtual wall roomba

Hi, I’m trying to build a virtual wall for roomba vacuum cleaners.
I’ve whrite the code to simulate the virtual wall with wemos D1 and a infrared LED and it works well.
Now I want to swith on-off the virtual wall with Blynk with a simple Virtual Pin.

This is my sketch:

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>


const uint16_t kIrLed = 4; 
IRsend irsend(kIrLed);  

BLYNK_WRITE(V5)
{
  int pinValue = param.asInt();
  if (pinValue == 1) {
    digitalWrite (kIrLed, HIGH);
    delay (1000);
  }
  else {
    irsend.begin();
    delay(1000);
  }
}
void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
}

void loop()
{
  irsend.enableIROut(38);
  irsend.mark(1000);
  irsend.space(1000);
  Blynk.run();

}

The problem is that wen I press the button in Blynk App, the IR LED swithc off only for 1 second (delay 1000) and then restart to send the IR…

I think the problem is in the “void loop” but I can’t solve it.
Can anyone help me?

Thanks

@Marco_Francescato please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

Thanks Pete, I’ve edit my post.

You mentioned the problem. But what is your desired out come?

Hi, I want to switch on and switch off the IR signal by pressing the button in Blynk app. Now, when I press the the button, the IR Led start to send the correct code, but when I Press the button to switch off, the IR stop for 1 sec. (Delay 1000) and then restart to send the IR signal.

Try setting your button in the app to “switch”. In “push” mode it sends a “1” when you push it and a “0” when you let go.

Rule No 1 - Don’t use delays with Blynk

Rule No 2 - Keep your void loop clean

The solution to your issue is to use a virtual pin to turn the IR send on and off, not to turn it off for a short period then have your void loop turn it back on again.

Pete.

Thanks for your suggestions.
I’ve erase the “delays” and I tried to clean the “void loop” but, without this part of code in the loop, the output is incorrect.
So, the only solution I found, was to restart ESP when Virtual Pin is LOW :

const uint16_t kIrLed = 00;  // ESP8266 GPIO pin to use. Recommended: 0.

IRsend irsend(kIrLed);  // Set the GPIO to be used to sending the message.
WidgetLED LED1Blynk(V6);

BLYNK_WRITE(V5)
{
  int pinValue = param.asInt();
  if (pinValue == 1) {
    LED1Blynk.on();
    irsend.begin();

  }
  else {
    LED1Blynk.off();
    ESP.restart ();
  }
}

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);


}



void loop()
{
  Blynk.run();
  irsend.enableIROut(38);
  irsend.mark(1000);
  irsend.space(1000);

}

I think this isn’t the best/right solution, but it works.
Any suggestions?

Thanks

If this runs without Blynk disconnections then I’d put the IR commands in your loud loop into an if statement which checks if a global flag is true or false, and only executes these commands if true.

Then, use the BLYNK_WRITE(V5) callback to set the flag to true/false depending on the state of the widget switch.

Pete.