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

BLYNK_WRITE not working (in my code)

esp8266
#1

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);
}
0 Likes

#2

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.

0 Likes

#3

It doesnt work :confused:

0 Likes

#4

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.

0 Likes

#5

i’ve deleted delay and still doesn display value

0 Likes

#6

sorry, now i’ve reapir this

1 Like

#7

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.

0 Likes

#8

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

0 Likes

#9

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

Pete.

0 Likes

#10

Its slider:


0 Likes

#11

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.

0 Likes

#12

yes it is i’ve checked this twice.

0 Likes

#13

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

Pete.

0 Likes

#14

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

 servo.write(pinValue);
0 Likes

#15

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