I want to blink a physical led

I want to blink a physical led , but this code is only for blinking virtual led on the app.what changes should I make in order blink physical led.:blush:

I am using Arduino nano with Bluetooth module HC06,
Blynk app Ver 2.27.5 on android os



#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11); // RX, TX
    
#include <BlynkSimpleSerialBLE.h>
#include <SoftwareSerial.h>

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

SoftwareSerial SerialBLE(10, 11); // RX, TX

WidgetLED led1(V1);

BlynkTimer timer;

// V1 LED Widget is blinking
void blinkLedWidget()
{
  if (led1.getValue()) {
    led1.off();
    Serial.println("LED on V1: off");
  } else {
    led1.on();
    Serial.println("LED on V1: on");
  }
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  SerialBLE.begin(9600);
  Blynk.begin(SerialBLE, auth);

  Serial.println("Waiting for connections...");

  timer.setInterval(1000L, blinkLedWidget);
}

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

When you created this topic you were presented with some guidance about the type of information to include, and also shown how to post your code between triple backticks so that it displays correctly.

Please edit your post (using the pencil icon at the bottom of the post). I’d success that you shorten your title to something more appropriate, include a description of what your’re trying to achieve and what problems you’re having, tell us what flavour of mobile OS (Android or iOS) and the version of the app that you have installed, what hardware you’re using etc. etc.

Then add triple backticks at the beginning and end of your code.
Triple backticks look like this:
```

Pete.

2 Likes

check out the Stroboscope example on the sketch builder.

2 Likes

thanks bro

Sir,
I have edited the post, Please provide me a solution.:blush:

You need to decide which physical pin you want to use to connect your LED, then declare that pin as an OUTPUT using a pinMode statement in your void setup.

You then need to use a digitalWrite command to set that pin HIGH when you want it on and LOW when you want to turn it off (assuming that the other side of the LED is connected to GND).

Don’t forget to include a suitable resistor.

Pete.

2 Likes

Sir,
It’s a request can you please edit the above code please . I would be grateful to you sir .

If you put the terms that @PeteKnight has said in his post into a search engine, you will find an endless amount of examples.

I highly doubt anyone will do the work for you. At least try and make an effort and then post your results and then we could help further.

1 Like

Ok Sir

1 Like


#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11); // RX, TX
    
#include <BlynkSimpleSerialBLE.h>
#include <SoftwareSerial.h>

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

SoftwareSerial SerialBLE(10, 11); // RX, TX

WidgetLED led1(V1);

BlynkTimer timer;

// V1 LED Widget is blinking
void blinkLedWidget()
{
  if (led1.getValue()) {
    led1.off();
    Serial.println("LED on V1: off");
  } else {
    led1.on();
    Serial.println("LED on V1: on");
  }
}

void setup()
{
  pinMode(3, OUTPUT);
  // Debug console
  Serial.begin(9600);

  SerialBLE.begin(9600);
  Blynk.begin(SerialBLE, auth);

  Serial.println("Waiting for connections...");

  timer.setInterval(1000L, blinkLedWidget);
}
void loop() {
  digitalWrite(3, HIGH); // sets the digital pin 13 on
  delay(1000);            // waits for a second
  digitalWrite(3, LOW);  // sets the digital pin 13 off
  delay(1000);            // waits for a second 
  Blynk.run();
  timer.run();
}```

Sir,
I wrote this code, but the led keeps on blinking .
If i switch on or off the button on app then also
the led is blink.

It is doing what you tell it to. In C++ the void loop runs constantly as fast as it can. Try the code builder to get a working sketch. Also search “clean void loop” of you want blynk to work.

As @daveblynk mentioned, the loop will run continuously, and with BLYNK you dont want to add code there as it can cause disconnection issues. Look HERE for more information on that. You also don’t want to use delay();, as this can interfer with the connection as well.

Also, the timer.setInterval(1000L, blinkLedWidget); will continuous run the blinkLedWidget every 1 second. There is nothing to stop it. Read up on SimpleTimer, as this is what the BlynkTimer is based on.

You do not have any code to check what the button in the app is doing. Read up on Virtual Pins, and how to determine their state. See HERE and HERE. I would read all of the DOCS on virtual pins. They have quite a few useful functions that can make coding easier.

As I mentioned before, take a look at the STROBOSCOPE example in the Sketch Builder. This code does what you are trying to accomplish, plus adds one more feature (controlling flashing interval with a slider widget).