BLYNK_WRITE not working (in my code)

Hi, i have an issue. When i use blynk_write function it doesnt work. i use slider to pass data and control servo somehow. and it doesnt work . have any1 has idea what can be wrong :slight_smile:

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Servo.h>

Servo servo;

int value;//vaule of rotation
char auth[] = "3e0c43c56c494b139abed9d05cd3a032";
char ssid[] = "21:37";
char pass[] = "elomelo12";

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  servo.attach(15);
} 

BLYNK_WRITE(V0)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  value = pinValue;
  servo.write(30);
  Serial.print("Rotation: ");
  Serial.println(pinValue);
} 
void loop()
{
  Blynk.run();
  Serial.println(value);
}

Remove the delay from void loop and try it again.

Edit: also you need to add 3 back ticks as per forum rules for your code otherwise it may be deleted.

It doesnt work :confused:

Yes it does!
Three backticks look like this:
```
If you copy and paste these characters at the top and bottom of your code the it will display correctly.

Pete.

i’ve deleted delay and still doesn display value

sorry, now i’ve reapir this

1 Like

You’re declaring pinValue as a local variable. This means that it’s only available within the BLYNK_WRITE(V0) function.

Try googling “variable scope in C++” to learn how to resolve this issue.

Pete.

Evnen if i use global variable it still doesnt work. it looks like function desnt iniciate (trigger).

What widget do you have attached to V0, and how is it configured?

Pete.

Its slider:


It looks like the project has multiple devices.
Is the Auth code you’re using in the sketch the same one that is attached to device “Pomiary”?

Pete.

yes it is i’ve checked this twice.

So when you put the app into ‘run’ mode and move the slider, zero is printed in the serial monitor?

Pete.

yes, 0 printed. and if i connect servo like in code. servo doesnt move.

 servo.write(pinValue);

Ok, i’ve reset ath token and it works. I dont know why. Thank you @PeteKnight Pete for your help, and time spend to help me. U re good man. :stuck_out_tongue:

2 Likes