Widget Led by physical pin

Hi, why in app in LED widget, I can select ONLY virtual pin?
It is not big difference with value reading at Value Display, where I can select any pin.
In my project there is lack of free space. So, I could not use Widget led class or virtualWrite.

I guess it’s because the LED widget does some PWM simulation in the background, so it requires a value of 255 to turn it on whereas a regular physical LED simply requires a HIGH or LOW (1 or 0) to turn it on/off - depending on how you’ve wired the physical LED.

I assume that you’re using an Uno?
There are techniques for reducing memory usage when coding, such as taking care which variable types you use, which libraries you include, and use of the ‘F’ macro when doing serial prints.

However, you’re probably better-off using more appropriate hardware for your project…


HI, Peter. Thank you for your suggestions.

I run Arduino Nano and binded to it due to this nice shield Шилд Arduino Nano + GSM SIM800 + 2реле купить в Украине
It is silly but Blynk reboots Nano, when it could not get connection. Continue code if Register in network failed - #9 by Gunner
I had to use additional code to control Blynk connection to let sketch run without Blynk.
Nano’s memory 98% full and when I use Widget Led class, Blynk connection becomes unstable.
But i found short code solution to use LED on app:

Blynk.virtualWrite(V23, (digitalRead(pinACsensor)*255));

But of course, it could be better if Blynk could arrange direct read of the physical pin for that. Led is most useful in simple indication. Why we need extra code for that?

From my experience, when you start to get above about 80% useage things can start to behave strangely sometimes, certainly when using an Uno.
If you post your code then I’d be happy to take a look and see if there are any other shortcuts that might help reduce memory usage.


1 Like

Thank you very much, Peter.
I will make comments to the code and put code on Github as well. Because i did not found solution at the web how to kill Blynk before it crash Nano.)
So, may be it could be useful for others.

Hi, Pete
My code worked for a week, but now lost control over Nano/SIM800))
I put it on Github https://github.com/CHE77/Power-monitoring-management-with-and-w-o-Blynk.-Arduino-Nano-SIM800l-
May be you could have a look. Pls, PM to me if any question arise.

Deleting #define BLYNK_PRINT Serial should help save memory.
Also, as you aren’t using your serial port for debugging you could use it for your connecting your SIM800, so allowing you to remove the SoftwareSerial library, also saving memory.
If you aren’t planning to regularly change the values that you’ve parameterised in your settings.h file then it may be better to hard code them as this will save on memory.


1 Like

Thank you for advises.
That do you mean “hard code values”? - to make static? via define?
Or just to put all code in one file?

You’re defining variables like this:
```int averageFactor = 10``
And the value of average factor doesn’t change throughout the code so this:

* (averageFactor - 1) +

could be replaced with this:

* 9 +

and you’ve saved yourself a variable and the storage space that goes with it.

This declaration:

  #define PIN_Relay7 7 // Build-in relay - PIN 7 NANO

is unnecessary if you replace:

  pinMode(PIN_Relay7, OUTPUT);


  pinMode(7, OUTPUT);

In addition you have variables that aren’t used (the code that uses them is commented-out)…

//#define VPIN_LabelValu V0
#define VPIN_TimeInput V1
#define VPIN_Button_Manual_Auto V2
#define VPIN_Button_On_Off_Relay5 V5
#define VPIN_Button_On_Off_Relay6 V6


1 Like