Problems with using incoming values from pin V1 inside loop function

Hi Blynkers,

I need some help with my project. I’ve been trying to run the following program on my Arduino Uno with a HM-10 bluetooth module. The problem is that: “Serial.println(Slider)” stays zero in serial monitor when i move the slider on the app side. The programs runs perfect when i use ethernet connection instead of bluetooth. Can anybody tell me please how to solve this without placing the “Serial.println(Slider)” outside the void loop function? Thank you!

#define BLYNK_PRINT Serial

#include <SoftwareSerial.h>
SoftwareSerial SwSerial(12, 13); // RX, TX
   
#include <BlynkSimpleSerialBLE.h>
#include <SoftwareSerial.h>
int Slider;

char auth[] = "secret";

SoftwareSerial SerialBLE(12, 13); // RX, TX

// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin 1
BLYNK_WRITE(V1)
{
 int Slider = param.asInt(); // assigning incoming value from pin V1 to a variable 
}

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

 SerialBLE.begin(9600);
 Blynk.begin(SerialBLE, auth);
 Serial.println("Waiting for connections...");
}

void loop()
{
 Serial.println(Slider);
 Blynk.run(); 
}

Honestly… I think BT/BLE has some comparatively recent issues that are still being worked on. Others have commented recently about similar problems but nothing official, that I can recall, is being said about any issue acknowledgement or fixes.

You already declared this variable Slider as global, so remove the int from within the function

Besides… what are you intending to do with the variable Slider after getting it?? I don’t see any other usages in your code (aside from the nasty inclusion in the void loop())

You have also doubled up your SoftwareSerial designation :stuck_out_tongue:

I removed the int from within the function. It finally works! Thanks a lot!!

1 Like