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

Slider, I need help with using slider widget in blynk app


#1

I am using nodemcu esp8266
And blynk app
Yesterday I tried to connect blynk and blub using nodemcu…
It’s worked
today I am trying to use slider.
But I’m not getting how write the code. I am a complete begginer.
I searched a lot… But still have lots of confusion Can please help me.


#2

To do what?

The slider can directly adjust the PWM value of a GPIO. Say you have a LED on GPIO 14 and GND (or D5 as silkscreened on the NodeMCU - best to always use the GPIO number)

You set the Slider like this and then it will dim or brighten the LED as you move the slider.

Or, using Virtual Pins, lets use V4, it can send a range value to the device using the BLYNK_WRITE() Function.

For example to control that same LED on GPIO14 set your widget like this…

And add this to your basic Blynk Blink sketch…

In void setup()

pinMode(14, OUTPUT);

And then add this Blynk function to your sketch. Anywhere before or after your void loop()

BLYNK_WRITE(V4){  // This function gets called each time something changes on the widget
  int value = param.asInt();  // This gets the 'value' of the Widget as an integer
  analogWrite(14, value);  // this send a PWM signal based on 'value' to the GPIO pin
}

That’s basically it.

Lots of examples and more documentation in the links at the top of this page…scroll up to see them.


#3

Thanks a lot.

I am trying to use slider to dim the blub .

I will try this code and let u know.
Thanks a lot :blush:


#4

Can I use this code to control The fan speed?


#5

1550468165712-1003644373
I will connect nodemcu( pin d5 )to relay and than The fan?
Will it work?
I am a beginner… I just need help.
Thanks in advance.


#6

Analogwrite does not work with digital pin you have to use digitalwrite

Try tip testing with your board und relays

in the community there is a lot to do with fan switch relays and so on


#7

When I use analog write…
ND connect to Bulit In led it works. …but when I use digitalwrite it’s not


#8

@SANJANA, It’s much better if you copy and past your code (using backticks so that it displays properly) rather than posting photos of your computer monitor.

It’s also much better if you explain in words, diagrams, pictures etc what it is that you’re trying to achieve with your project. Your other thread (which @Gunner has now merged for you) asks about dimming an LED, and here you’re trying to control some sort of fan via a relay using an unknown type of widget in your app. Reading between the lines I’m guessing that the widget is a slider ad that you’re hoping top control the fan speed with the app. This clearly wont work if it’s a mains voltage fan and you’re controlling it with a relay, as the relay is a simple on/off device.

The point is that if you ask one line questions and give vague one line answers when others provide suggestions then you wont get the right information from people and they’ll very soon tire of trying to help you.

@markop, it is possible to use analogueWrite to a digital pin, it’s a technique I use all the time when dimming my LEDs. On the NodeMCU, all the digital pins can be used in PWM mode using analogueWrite. The NodeMCU uses PWM values of 0-1023 and if this is used to drive a single LED directly, or a strip of LEDs via a MOSFET then the LEDs can be dimmed from zero to maximum brightness.

Pete


#10

@SANJANA @manju1 Please don’t create new user accounts for the forum to discuss the same issue. I’ve suspended your @manju1 account on the forum (note that this is not connected in any way to the accounts you’ve created in the Blynk app, they are totally independent). I’ve merged your new post back in to this thread.

I’ve also edited your post to put backticks at the top and bottom of your code so that it displays correctly. In future please do this your self, like this:

Blynk%20-%20FTFC

As I said earlier, a comprehensive description of what it is you are trying to achieve is the best place to start.

Pete.


#11

iam new to nodemcu and blynk.
i created a new account in blynk used the button widget .
set it to D1
.
wrote a code as follows in arduino ide

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include "BlynkSimpleEsp8266.h"
char auth[] = "";
char ssid[] = "";
char pass[] ="";
void setup()
{
Serial.begin(115200);
pinMode(D1,OUTPUT);
digitalWrite(D1,HIGH);
Blynk.begin(auth, ssid, pass);
}
void loop()
{
Blynk.run();
}

i connected properly from nodemcu to relay to bulb .
its working fine.

now, i used a slider widget   for diming of a built in led  in node mcu using this code

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>

#include "BlynkSimpleEsp8266.h"

char auth[] = ""

char ssid[] = "";

char pass[] = ""
void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
pinMode(D4,OUTPUT);
}
BLYNK_WRITE(V4) //this function gets called each time changes in widget
{
int value = param.asInt(); // this get the 'value' of widget as an integer
analogWrite(D4,value); // this send a signal based on 'value' to pin . 
}
void loop()
{
Blynk.run();
}

it worked fine.

so i wrote code something like show in below.

 can it be used to control the speed of the fan using slider widget in blynk app.

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>

#include "BlynkSimpleEsp8266.h"

char auth[] = ;

char ssid[] = ;

char pass[] = &quot;madmadmad &quot;;
void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
pinMode(D5,OUTPUT);
}
BLYNK_WRITE(V4) //this function gets called each time changes in widget
{
int value = param.asInt(); // this get the 'value' of widget as an integer
analogWrite(D5,value); // this send a signal based on 'value' to pin .
}
void loop()
{
 Blynk.run();
}

iam confused ?
how shd i connect node mcu to a fan?
blub was connected through relay , shd we use a relay for the fan too?
how shd i make the connection?
is the code right?
please help,!


#12

it depends on the fan you use: voltage, intensity.


#13

better use Mosfet driver


#15

iam using nodemcu and arduino ide
its a project given to us.
please do help !


#16

its not the SAME persons account @PeteKnight .
we r working in group as this group project .
one of my friend post all the code in detail
im new to the blynk community,iam sure how to use it.
can please help with the code…


#17

Then please work with one account.


#18

ok , can u help with the code and connections ? plz


#19

We help you learn about Blynk… how to find the Documentation, learn about the commands, assist with some tidbits and advice, as we have already tried to do.

But we are NOT here to teach you programming or how to do your projects.


#20

ok thanks @Gunner