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

Problems with the hc-05 together with the SW-420

hello friends, here the speaker is the direct friend of Brazil.
I need a help I got it with the help of you to configure the hc-05 together with the SW-420, now I would like it to show the SW data on the LCD reader, I will make my code available to see if there are errors and if I am on the right path , I thank you and apologize for my English

#define BLYNK_PRINT Serial

#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11); // RX, TX

#include <BlynkSimpleSerialBLE.h>


char auth[] = "..........";
SoftwareSerial SerialBLE(10, 11);



//==============================Token de autorizacao

BlynkTimer timer;



int vs =9; //  sensor de vibração / vibration sensor
int aviso;

void enviaraviso()
{
  vs = digitalRead (9);
  Blynk.virtualWrite(V0, vs);
  
}


void setup(){
  pinMode(vs, INPUT); 
  Serial.begin(9600);
  SerialBLE.begin(9600);
  Blynk.begin(SerialBLE, auth);

  Serial.println("Waiting for connections...");

  timer.setInterval(1000L, enviaraviso); 

}

void loop(){
  long measurement = vibration();
  delay(50);
  Serial.println(measurement);
  if (measurement > 12000){
   Blynk.virtualWrite(V1, aviso); 
  }
  Blynk.run();
  timer.run(); 
}

long vibration(){
  long measurement=pulseIn (vs, HIGH); 
  return measurement;
}

this will trigger sending the “aviso” several times, which is not recommended: Limitations and Recommendations

You have two virtual serial ports using the same pins, one called SerialBLE and the other called SwSerial.
Only SerialBLE is used in your code, you should delete the other one.

Is this a physical LCD, or an LCD widget?
What data do you want to show on this display?

Pete.

I appreciate the tip but you can tell me if it is possible to create a variable (if) where every time the sensor detects that the value is above 10,000, send a warning to the blynk’s LCD?

Hello, PeteKnight, again I apologize for the English, it’s the LCD widget that has on the blynk, I want to send the data from the SW-420 which is the vibration sensor

but I also tried to use an (if) to send a “danger” warning every time the sensor detects that the sensor value was greater than 10000

As this will keep sending your alert every loop count as long as the value is over your threshold, then I recommend you use an additional latching variable to force only one initial alert, then resetting either manually, automatically if value goes below threshold, or after a set time (as shown below).

I did something similar (latch and timer) for this timed button example… so you could try like this (untested for syntax or function… that is up to you to do :slight_smile: )

int latchFlag = 0;  // in pre-setup
if (measurement > 12000 && latchFlag == 0){  // Only send alert once, if latchFlag is not engaged, if already engaged then ignore further alert operation.
 latchFlag = 1;
 Blynk.virtualWrite(V1, "Aviso"); // Print to LCD Widget?
 timer.setTimeout(10000L, []() {  // Timed Lambda Function - latchFlag reset after 10 seconds
   latchFlag = 0;  // resets to allow next interaction
   Blynk.virtualWrite(V1, ""); // Clear LCD Widget?
 });  // END Timer Function
}

Personally, I’d use a Labelled Value widget rather than the LCD widget.
But, it sounds like you need to learn more about C++ programming before you can go much further.
I’d suggest searching the internet for C++ programming tutorials in your own language, and in a format that suits your learning style.

Pete.

I wanted to but unfortunately I have a few days to finish, it’s a school project, could you help me with the Labeled Value widget

@Gunner has provided you with enough code to get you going. The code would work equally well with either an LCD or Labelled Value widget on V1.

Pete.

:flushed: maybe you should have started sooner?

2 Likes

Hello, I put a virtual button on the blynk app and I wanted every time it was pressed to clear the message from the display (V1), but I have no idea how to do it.

//============================Configuracoes biblioteca Blynk
#define BLYNK_PRINT Serial

#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11); // RX, TX

#include <BlynkSimpleSerialBLE.h>
SoftwareSerial SerialBLE(10, 11);



//==============================Token de autorizacao
char auth[] = "1234";
BlynkTimer timer;



int vs = 9; //  sensor de vibração / vibration sensor
int aviso;
int latchFlag = 0;  // in pre-setup



void setup(){
  pinMode(vs, INPUT); 
  Serial.begin(9600);
  SerialBLE.begin(9600);
  Blynk.begin(SerialBLE, auth);

}

void loop(){
  long measurment = vibration();
  delay(50);
  Serial.println(measurment);
  if (measurment > 26000  && latchFlag == 0){  
 Blynk.virtualWrite(V1, "alerta!!!!");
 timer.setTimeout(10000L, []() {  
   latchFlag = 0;  
   Blynk.virtualWrite(V1, ""); 
 });  
}
Blynk.virtualWrite(V0, measurment);
  Blynk.run();
  timer.run(); 
}

long vibration(){
  long measurement=pulseIn (vs, HIGH); 
  return measurement;
}

@CaioVieira you’ve now started three different topics about the same project. I’ve closed one of them, and merged the other two together.
Please stop creating new topics in this way.

You should read the documentation here:

The BLYNK_WRITE(V1) function will be called whenever the V1 widget value changes.

Pete.